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 6 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
4 changes: 2 additions & 2 deletions Syntaxes/Diagnostics.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ contexts:
- include: line

file:
- match: ^(?!\s*\d+:\d+)(.*)(:)$
- match: ^(?!\s+\d+:\d+)(.*)(:)$
captures:
0: meta.diagnostic.preamble.lsp
1: string.unquoted.lsp
2: punctuation.separator.lsp

line:
- match: ^\s*(?=\d)
- match: ^\s+(?=\d)
push:
- ensure-diag-meta-scope
- expect-source-and-code
Expand Down
7 changes: 3 additions & 4 deletions Syntaxes/References.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ scope: output.lsp.references

variables:
start_of_reference_body: ^\s+(?=\d)
filename_and_colon: ^\s*(\S)\s+(.*)(:)$
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
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 = "\t{:>4}:{:<4}{:<8}{} \u200B{}\n".format(
predragnikolic marked this conversation as resolved.
Show resolved Hide resolved
diagnostic.range.start.row + 1,
diagnostic.range.start.col + 1,
format_severity(diagnostic.severity),
Expand Down
11 changes: 6 additions & 5 deletions plugin/core/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ def handle_show_message(self, session: Session, params: Any) -> None:
sublime.status_message("{}: {}".format(session.config.name, extract_message(params)))

def update_diagnostics_panel_async(self) -> None:
to_render = [] # type: List[str]
to_render = "" # type: str
predragnikolic marked this conversation as resolved.
Show resolved Hide resolved
base_dir = None
self.total_error_count = 0
self.total_warning_count = 0
Expand All @@ -427,16 +427,17 @@ def update_diagnostics_panel_async(self) -> None:
file_path = listener.view.file_name() or ""
base_dir = self.get_project_path(file_path) # What about different base dirs for multiple folders?
file_path = os.path.relpath(file_path, base_dir) if base_dir else file_path
to_render.append("{}:".format(file_path))
to_render += "{}:\n".format(file_path)
row += 1
for content, offset, code, href in contribution:
to_render.append(content)
to_render += content
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
# append a new line after each file name
to_render += '\n'
for listener in listeners:
set_diagnostics_count(listener.view, self.total_error_count, self.total_warning_count)
characters = "\n".join(to_render)

def update() -> None:
panel = ensure_diagnostics_panel(self._window)
Expand All @@ -446,7 +447,7 @@ def update() -> None:
panel.settings().set("result_base_dir", base_dir)
else:
panel.settings().erase("result_base_dir")
panel.run_command("lsp_update_panel", {"characters": characters})
panel.run_command("lsp_update_panel", {"characters": to_render})
if self._panel_code_phantoms is None:
self._panel_code_phantoms = sublime.PhantomSet(panel, "hrefs")
phantoms = [] # type: List[sublime.Phantom]
Expand Down
7 changes: 4 additions & 3 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 @@ -123,11 +124,11 @@ def show_references_panel(self, references_by_file: Dict[str, List[Tuple[Point,
text = ''
references_count = 0
for file, references in references_by_file.items():
text += '{}:\n'.format(self.get_relative_path(file))
text += '{}:\n'.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)
text += '\t{:>4}:{:<4} {}\n'.format(point.row + 1, point.col + 1, line)
# append a new line after each file name
text += '\n'

Expand Down
16 changes: 9 additions & 7 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 @@ -162,17 +163,18 @@ def _render_rename_panel(self, changes: Dict[str, List[TextEdit]], total_changes
return
text = ''
for file, file_changes in changes.items():
text += '{}:\n'.format(self._get_relative_path(file))
text += '{}:\n'.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)
line_content = get_line(self.view.window(), file, start[0])
text += '\t{:>4}:{:<4} {}\n'.format(start[0] + 1, start[1] + 1, line_content)
# append a new line after each file name
text += '\n'
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),
'force': True,
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"
)