-
Notifications
You must be signed in to change notification settings - Fork 46
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
Add showSyntaxErrors
server setting
#454
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -614,7 +614,11 @@ async def _lint_document_impl( | |
show_error(f"Ruff: Lint failed ({result.stderr.decode('utf-8')})") | ||
return [] | ||
|
||
return _parse_output(result.stdout) if result.stdout else [] | ||
return ( | ||
_parse_output(result.stdout, settings.get("showSyntaxErrors", True)) | ||
if result.stdout | ||
else [] | ||
) | ||
|
||
|
||
def _parse_fix(content: Fix | LegacyFix | None) -> Fix | None: | ||
|
@@ -649,7 +653,7 @@ def _parse_fix(content: Fix | LegacyFix | None) -> Fix | None: | |
return fix | ||
|
||
|
||
def _parse_output(content: bytes) -> list[Diagnostic]: | ||
def _parse_output(content: bytes, show_syntax_errors: bool) -> list[Diagnostic]: | ||
"""Parse Ruff's JSON output.""" | ||
diagnostics: list[Diagnostic] = [] | ||
|
||
|
@@ -700,6 +704,8 @@ def _parse_output(content: bytes) -> list[Diagnostic]: | |
# Cell represents the cell number in a Notebook Document. It is null for normal | ||
# Python files. | ||
for check in json.loads(content): | ||
if not show_syntax_errors and check["code"] is None: | ||
continue | ||
start = Position( | ||
line=max([int(check["location"]["row"]) - 1, 0]), | ||
character=int(check["location"]["column"]) - 1, | ||
|
@@ -750,6 +756,7 @@ def _get_severity(code: str) -> DiagnosticSeverity: | |
"F821", # undefined name `name` | ||
"E902", # `IOError` | ||
"E999", # `SyntaxError` | ||
None, # `SyntaxError` as of Ruff v0.5.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is actually required after There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you say it is required, does it mean that Ruff-LSP crashes or is it because it otherwise shows syntax errors as warnings? I guess there's not much we can do about it other than keeping to emit There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I meant that the
Both are included in this list. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Oh, I think I read your question wrong but yes otherwise it'll emit syntax errors as warnings. This is why I'm including There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'm not sure about that. If we do keep The current change will only break if there are any other diagnostics emitted by Ruff which doesn't have a rule code and is suppose to be a warning instead. I think it'll be a quite some time before this happens and by that time I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. Let's ship as is. I expect that most users are using the most recent extension anyway because they auto-update. |
||
}: | ||
return DiagnosticSeverity.Error | ||
else: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use
settings.get
so this change is backwards compatible i.e., the newruff-lsp
version can be used with an old VS Code extension version.