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

Ignore syntax errors on help commands #5561

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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 @@ -664,7 +665,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 @@ -675,7 +676,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 @@ -686,9 +687,14 @@ def _publish_diagnostics(server: JediLanguageServer, uri: str) -> None:

doc = server.workspace.get_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 @@ -282,6 +282,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
Loading