Skip to content

Commit

Permalink
fix: dont suggest events in type suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
z80dev committed Nov 9, 2023
1 parent 596548a commit 037f653
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/Foo.vy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma version 0.3.8
#pragma version 0.3.10

event Foo:
arg1: uint256
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_get_user_defined_types(ast):
Baz
"""
ast.build_ast(src)
assert ast.get_user_defined_types() == ["Foo", "FooEvent", "FooEnum"]
assert ast.get_user_defined_types() == ["Foo", "FooEnum"]


def test_get_state_variables(ast):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_find_references_storage_var(doc, navigator):
def test_find_references_constant(doc, navigator):
pos = Position(line=16, character=0)
references = navigator.find_references(doc, pos)
assert len(references) == 2
assert len(references) == 1


def test_find_references_function_local_var(doc, navigator):
Expand All @@ -90,7 +90,7 @@ def test_find_interface_fn_implementation(doc, navigator: ASTNavigator):


def test_find_declaration_constant(doc, navigator: ASTNavigator):
pos = Position(line=20, character=19)
pos = Position(line=21, character=19)
declaration = navigator.find_declaration(doc, pos)
assert declaration and declaration.start.line == 16

Expand Down
5 changes: 3 additions & 2 deletions vyper_lsp/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AST:
ast_data_folded = None
ast_data_unfolded = None

custom_type_node_types = (nodes.StructDef, nodes.EnumDef, nodes.EventDef)
custom_type_node_types = (nodes.StructDef, nodes.EnumDef)

@classmethod
def from_node(cls, node: VyperNode):
Expand Down Expand Up @@ -180,7 +180,8 @@ def find_state_variable_declaration_node_for_name(self, variable: str):
return None

def find_type_declaration_node_for_name(self, symbol: str):
for node in self.get_descendants(self.custom_type_node_types):
searchable_types = self.custom_type_node_types + (nodes.EventDef,)
for node in self.get_descendants(searchable_types):
if node.name == symbol:
return node
if isinstance(node, nodes.EnumDef):
Expand Down
4 changes: 4 additions & 0 deletions vyper_lsp/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def find_declaration(self, document: Document, pos: Position) -> Optional[Range]
full_word = get_expression_at_cursor(line_content, pos.character)
top_level_node = self.ast.find_top_level_node_at_pos(pos)

print(f"word: {word} events: {self.ast.get_events()}")
# Determine the type of declaration and find it
if full_word.startswith("self."):
if "(" in full_word:
Expand All @@ -146,6 +147,9 @@ def find_declaration(self, document: Document, pos: Position) -> Optional[Range]
return self.find_state_variable_declaration(word)
elif word in self.ast.get_user_defined_types():
return self.find_type_declaration(word)
elif word in self.ast.get_events():
print(f"finding event declaration for {word}")
return self.find_type_declaration(word)
elif word in self.ast.get_constants():
return self.find_state_variable_declaration(word)
elif isinstance(top_level_node, FunctionDef):
Expand Down

0 comments on commit 037f653

Please sign in to comment.