Skip to content

Commit

Permalink
Panel output/regex fixes (#1883)
Browse files Browse the repository at this point in the history
* Fixed panel result_file_regex:
  - one non-space character anchored to line start (captured)
  - followed by zero or more arbitrary characters (still captured)
  - followed by a colon anchored to line end (not captured)
  This is tight enough to skip all other lines. The old regex is too
  premissive and matches for example:
    "                  Perhaps you meant one of these:"
  which you see a lot with Haskell.

* Fixed line number formatting so that there is at least one space at
  line start guaranteed for the result_line_regex to match line
  numbers > 9999

* Adjusted file and line regex in syntaxes accordingly

* Fixed multi-line diagnostic indentation (just one more)

* Changed match defs to preferred style.
  • Loading branch information
htmue authored Oct 27, 2021
1 parent ac56c4a commit b7114c4
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 15 deletions.
6 changes: 3 additions & 3 deletions Syntaxes/Diagnostics.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ contexts:
- include: line

file:
- match: ^(?!\s*\d+:\d+)(.*)(:)$
- match: ^(\S.*)(:)$
scope: meta.diagnostic.preamble.lsp
captures:
0: meta.diagnostic.preamble.lsp
1: entity.name.filename.lsp
2: punctuation.separator.lsp

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

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

contexts:
main:
- include: references-preamble
- include: references-body

references-preamble:
- match: '{{filename_and_colon}}'
- match: ^(\S.*)(:)$
scope: meta.reference.preamble.lsp
captures:
0: meta.reference.preamble.lsp
1: entity.name.filename.lsp
2: punctuation.separator.lsp

references-body:
- match: '{{start_of_reference_body}}'
- match: ^\s+(?=\d+)
push:
- ensure-reference-meta-scope
- code
Expand Down
2 changes: 1 addition & 1 deletion plugin/core/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
TCP_CONNECT_TIMEOUT = 5 # seconds
FEATURES_TIMEOUT = 300 # milliseconds

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

FileWatcherConfig = TypedDict("FileWatcherConfig", {
Expand Down
4 changes: 2 additions & 2 deletions plugin/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,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 = "{:>5}:{:<4}{:<8}{} \u200B{}".format(
result = " {:>4}:{:<4}{:<8}{} \u200B{}".format(
diagnostic["range"]["start"]["line"] + 1,
diagnostic["range"]["start"]["character"] + 1,
format_severity(diagnostic_severity(diagnostic)),
Expand All @@ -671,7 +671,7 @@ def format_diagnostic_for_panel(diagnostic: Diagnostic) -> Tuple[str, Optional[i
if href:
offset = len(result)
for line in itertools.islice(lines, 1, None):
result += "\n" + 17 * " " + line
result += "\n" + 18 * " " + line
return result, offset, code, href


Expand Down
2 changes: 1 addition & 1 deletion plugin/references.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def _show_references_in_output_panel(self, word: str, session: Session, location
for reference in references:
references_count += 1
point, line = reference
to_render.append('{:>5}:{:<4} {}'.format(point.row + 1, point.col + 1, line))
to_render.append(" {:>4}:{:<4} {}".format(point.row + 1, point.col + 1, line))
to_render.append("") # add spacing between filenames
characters = "\n".join(to_render)
panel.settings().set("result_base_dir", base_dir)
Expand Down
2 changes: 1 addition & 1 deletion plugin/rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def _render_rename_panel(
for edit in file_changes:
start = edit[0]
line_content = get_line(window, file, start[0])
to_render.append('{:>5}:{:<4} {}'.format(start[0] + 1, start[1] + 1, line_content))
to_render.append(" {:>4}:{:<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 "")
Expand Down

0 comments on commit b7114c4

Please sign in to comment.