Skip to content

Commit

Permalink
Ignore syntax errors on help commands (#5561)
Browse files Browse the repository at this point in the history
Addresses #5483.
  • Loading branch information
seeM authored Dec 5, 2024
1 parent 45ec5c2 commit 44ed531
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
_LINE_MAGIC_PREFIX = r"%"
_CELL_MAGIC_PREFIX = r"%%"
_SHELL_PREFIX = "!"
_HELP_PREFIX_OR_SUFFIX = "?"
_HELP_TOPIC = "positron/textDocument/helpTopic"


Expand Down Expand Up @@ -669,7 +670,7 @@ def positron_did_close_diagnostics(


@jedi_utils.debounce(1, keyed_by="uri") # type: ignore - pyright bug
def _publish_diagnostics_debounced(server: JediLanguageServer, uri: str) -> None:
def _publish_diagnostics_debounced(server: PositronJediLanguageServer, uri: str) -> None:
# Catch and log any exceptions. Exceptions should be handled by pygls, but the debounce
# decorator causes the function to run in a separate thread thus a separate stack from pygls'
# exception handler.
Expand All @@ -680,7 +681,7 @@ def _publish_diagnostics_debounced(server: JediLanguageServer, uri: str) -> None


# Adapted from jedi_language_server/server.py::_publish_diagnostics.
def _publish_diagnostics(server: JediLanguageServer, uri: str) -> None:
def _publish_diagnostics(server: PositronJediLanguageServer, uri: str) -> None:
"""Helper function to publish diagnostics for a file."""
# The debounce decorator delays the execution by 1 second
# canceling notifications that happen in that interval.
Expand All @@ -691,9 +692,14 @@ def _publish_diagnostics(server: JediLanguageServer, uri: str) -> None:

doc = server.workspace.get_text_document(uri)

# Comment out magic/shell command lines so that they don't appear as syntax errors.
# Comment out magic/shell/help command lines so that they don't appear as syntax errors.
source = "\n".join(
(f"#{line}" if line.lstrip().startswith((_LINE_MAGIC_PREFIX, _SHELL_PREFIX)) else line)
(
f"#{line}"
if line.lstrip().startswith((_LINE_MAGIC_PREFIX, _SHELL_PREFIX, _HELP_PREFIX_OR_SUFFIX))
or line.rstrip().endswith(_HELP_PREFIX_OR_SUFFIX)
else line
)
for line in doc.lines
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ def test_positron_completion_item_resolve(
(r"%%bash", []),
# No errors for shell commands.
("!ls", []),
("?str", []),
("??str.join", []),
("2?", []),
("object?? ", []),
],
)
def test_publish_diagnostics(source: str, messages: List[str]):
Expand Down

0 comments on commit 44ed531

Please sign in to comment.