From 44ed531e074d4b0b0886d370c5f879e0a61e68f4 Mon Sep 17 00:00:00 2001 From: Wasim Lorgat Date: Thu, 5 Dec 2024 17:52:02 +0200 Subject: [PATCH] Ignore syntax errors on help commands (#5561) Addresses #5483. --- .../positron_ipykernel/positron_jedilsp.py | 14 ++++++++++---- .../tests/test_positron_jedilsp.py | 4 ++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/extensions/positron-python/python_files/positron/positron_ipykernel/positron_jedilsp.py b/extensions/positron-python/python_files/positron/positron_ipykernel/positron_jedilsp.py index 9ba04c275e3..36055db094e 100644 --- a/extensions/positron-python/python_files/positron/positron_ipykernel/positron_jedilsp.py +++ b/extensions/positron-python/python_files/positron/positron_ipykernel/positron_jedilsp.py @@ -100,6 +100,7 @@ _LINE_MAGIC_PREFIX = r"%" _CELL_MAGIC_PREFIX = r"%%" _SHELL_PREFIX = "!" +_HELP_PREFIX_OR_SUFFIX = "?" _HELP_TOPIC = "positron/textDocument/helpTopic" @@ -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. @@ -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. @@ -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 ) diff --git a/extensions/positron-python/python_files/positron/positron_ipykernel/tests/test_positron_jedilsp.py b/extensions/positron-python/python_files/positron/positron_ipykernel/tests/test_positron_jedilsp.py index 743a752c949..9486d309d23 100644 --- a/extensions/positron-python/python_files/positron/positron_ipykernel/tests/test_positron_jedilsp.py +++ b/extensions/positron-python/python_files/positron/positron_ipykernel/tests/test_positron_jedilsp.py @@ -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]):