Skip to content

Commit

Permalink
fix: error parsing from annotations
Browse files Browse the repository at this point in the history
message is no longer on the annotation node, but instead on the
surrounding exception node, so we can now override the message for a
node when calling diagnostic_from_exception

We also check for end_lineno before trying to use it
  • Loading branch information
z80dev committed Aug 9, 2024
1 parent f8cf609 commit a731764
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion vyper_lsp/analyzer/AstAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def get_diagnostics(self, doc: Document) -> List[Diagnostic]:
diagnostics.append(diagnostic_from_exception(e))
else:
for a in e.annotations:
diagnostics.append(diagnostic_from_exception(a))
diagnostics.append(diagnostic_from_exception(a, message=e.message))
for warning in w:
m = deprecation_pattern.match(str(warning.message))
if not m:
Expand Down
9 changes: 7 additions & 2 deletions vyper_lsp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,21 @@ def range_from_node(node: VyperNode) -> Range:


def range_from_exception(node: VyperException) -> Range:
if getattr(node, "end_lineno", None) is None:
return Range(
start=Position(line=node.lineno - 1, character=node.col_offset),
end=Position(line=node.lineno - 1, character=node.col_offset),
)
return Range(
start=Position(line=node.lineno - 1, character=node.col_offset),
end=Position(line=node.end_lineno - 1, character=node.end_col_offset),
)


def diagnostic_from_exception(node: VyperException) -> Diagnostic:
def diagnostic_from_exception(node: VyperException, message=None) -> Diagnostic:
return Diagnostic(
range=range_from_exception(node),
message=str(node),
message=message or str(node),
severity=DiagnosticSeverity.Error,
)

Expand Down

0 comments on commit a731764

Please sign in to comment.