Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make panels consistent #1524

Merged
merged 16 commits into from
Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions Syntaxes/References.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ hidden: true
scope: output.lsp.references

variables:
start_of_reference_body: ^\s+(?=\d)
filename_and_colon: ^\s*(\S)\s+(.*)(:)$
start_of_reference_body: ^\s*(?=\s*\d+:\d+)
filename_and_colon: ^(?!\s*\d+:\d+)(.*)(:)$

contexts:
main:
Expand All @@ -18,9 +18,8 @@ contexts:
- match: '{{filename_and_colon}}'
captures:
0: meta.reference.preamble.lsp
1: punctuation.section.references.preample.lsp
2: string.unquoted.lsp entity.name.file.references.lsp
3: punctuation.separator.lsp
1: string.unquoted.lsp entity.name.file.references.lsp
2: punctuation.separator.lsp

references-body:
- match: '{{start_of_reference_body}}'
Expand Down
31 changes: 0 additions & 31 deletions Syntaxes/Rename.sublime-syntax

This file was deleted.

3 changes: 2 additions & 1 deletion plugin/core/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
from .protocol import Diagnostic
from .protocol import Point
from .sessions import SessionBufferProtocol
from .types import PANEL_FILE_REGEX, PANEL_LINE_REGEX
from .typing import List, Tuple, Callable, Optional, Iterable
import sublime


def ensure_diagnostics_panel(window: sublime.Window) -> Optional[sublime.View]:
return ensure_panel(window, "diagnostics", r"^(.*):$", r"^\s*(\d+):(\d+)",
return ensure_panel(window, "diagnostics", PANEL_FILE_REGEX, PANEL_LINE_REGEX,
"Packages/LSP/Syntaxes/Diagnostics.sublime-syntax")


Expand Down
3 changes: 3 additions & 0 deletions plugin/core/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
TCP_CONNECT_TIMEOUT = 5 # seconds
FEATURES_TIMEOUT = 300 # milliseconds

PANEL_FILE_REGEX = r"^(?!\s+\d+:\d+)(.*)(:)$"
PANEL_LINE_REGEX = r"^\s+(\d+):(\d+)"


def basescope2languageid(base_scope: str) -> str:
# This the connection between Language IDs and ST selectors.
Expand Down
2 changes: 1 addition & 1 deletion plugin/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ def format_diagnostic_for_panel(diagnostic: Diagnostic) -> Tuple[str, Optional[i
formatted.append(code)
lines = diagnostic.message.splitlines() or [""]
# \u200B is the zero-width space
result = "{:>4}:{:<4}{:<8}{} \u200B{}".format(
result = "{:>5}:{:<4}{:<8}{} \u200B{}".format(
diagnostic.range.start.row + 1,
diagnostic.range.start.col + 1,
format_severity(diagnostic.severity),
Expand Down
1 change: 1 addition & 0 deletions plugin/core/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ def update_diagnostics_panel_async(self) -> None:
if offset is not None and code is not None and href is not None:
prephantoms.append((row, offset, code, href))
row += content.count("\n") + 1
to_render.append("") # add spacing between filenames
rwols marked this conversation as resolved.
Show resolved Hide resolved
for listener in listeners:
set_diagnostics_count(listener.view, self.total_error_count, self.total_warning_count)
characters = "\n".join(to_render)
Expand Down
16 changes: 8 additions & 8 deletions plugin/references.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .core.registry import windows
from .core.settings import PLUGIN_NAME
from .core.settings import userprefs
from .core.types import PANEL_FILE_REGEX, PANEL_LINE_REGEX
from .core.typing import List, Dict, Optional, Tuple, TypedDict
from .core.url import uri_to_filename
from .core.views import get_line, text_document_position_params
Expand All @@ -17,7 +18,7 @@


def ensure_references_panel(window: sublime.Window) -> 'Optional[sublime.View]':
return ensure_panel(window, "references", r"^\s*\S\s+(\S.*):$", r"^\s+([0-9]+):?([0-9]+).*$",
return ensure_panel(window, "references", PANEL_FILE_REGEX, PANEL_LINE_REGEX,
"Packages/" + PLUGIN_NAME + "/Syntaxes/References.sublime-syntax")


Expand Down Expand Up @@ -120,24 +121,23 @@ def show_references_panel(self, references_by_file: Dict[str, List[Tuple[Point,
if not panel:
return

text = ''
to_render = [] # type: List[str]
references_count = 0
for file, references in references_by_file.items():
text += '◌ {}:\n'.format(self.get_relative_path(file))
to_render.append('{}:'.format(self.get_relative_path(file)))
for reference in references:
references_count += 1
point, line = reference
text += '\t{:>8}:{:<4} {}\n'.format(point.row + 1, point.col + 1, line)
# append a new line after each file name
text += '\n'

to_render.append('{:>5}:{:<4} {}'.format(point.row + 1, point.col + 1, line))
to_render.append("") # add spacing between filenames
characters = "\n".join(to_render)
base_dir = windows.lookup(window).get_project_path(self.view.file_name() or "")
panel.settings().set("result_base_dir", base_dir)

panel.run_command("lsp_clear_panel")
window.run_command("show_panel", {"panel": "output.references"})
panel.run_command('append', {
'characters': "{} references for '{}'\n\n{}".format(references_count, self.word, text),
'characters': "{} references for '{}'\n\n{}".format(references_count, self.word, characters),
'force': True,
'scroll_to_end': False
})
Expand Down
24 changes: 13 additions & 11 deletions plugin/rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
from .core.registry import get_position
from .core.registry import LspTextCommand
from .core.registry import windows
from .core.types import PANEL_FILE_REGEX, PANEL_LINE_REGEX
from .core.typing import Any, Optional, Dict, List
from .core.views import range_to_region
from .core.views import range_to_region, get_line
from .core.views import text_document_position_params
import os
import sublime
Expand Down Expand Up @@ -160,21 +161,22 @@ def _render_rename_panel(self, changes: Dict[str, List[TextEdit]], total_changes
panel = ensure_rename_panel(window)
if not panel:
return
text = ''
to_render = [] # type: List[str]
for file, file_changes in changes.items():
text += '◌ {}:\n'.format(self._get_relative_path(file))
to_render.append('{}:'.format(self._get_relative_path(file)))
for edit in file_changes:
start = edit[0]
text += '\t{:>8}:{}\n'.format(start[0] + 1, start[1] + 1)
# append a new line after each file name
text += '\n'
line_content = get_line(self.view.window(), file, start[0])
to_render.append('{:>5}:{:<4} {}'.format(start[0] + 1, start[1] + 1, line_content))
to_render.append("") # this adds a spacing between filenames
characters = "\n".join(to_render)
base_dir = windows.lookup(window).get_project_path(self.view.file_name() or "")
panel.settings().set("result_base_dir", base_dir)
panel.run_command("lsp_clear_panel")
window.run_command("show_panel", {"panel": "output.rename"})
fmt = "{} changes across {} files. Double-click on a row:col number to jump to that location.\n\n{}"
fmt = "{} changes across {} files.\n\n{}"
panel.run_command('append', {
'characters': fmt.format(total_changes, file_count, text),
'characters': fmt.format(total_changes, file_count, characters),
'force': True,
'scroll_to_end': False
})
Expand All @@ -184,7 +186,7 @@ def ensure_rename_panel(window: sublime.Window) -> Optional[sublime.View]:
return ensure_panel(
window=window,
name=PanelName.Rename,
result_file_regex=r"^\s*\S\s+(\S.*):$",
result_line_regex=r"^\s*([0-9]+):([0-9]+)\s*$",
syntax="Packages/LSP/Syntaxes/Rename.sublime-syntax"
result_file_regex=PANEL_FILE_REGEX,
result_line_regex=PANEL_LINE_REGEX,
syntax="Packages/LSP/Syntaxes/References.sublime-syntax"
)