diff --git a/examples/Foo.vy b/examples/Foo.vy index 8cb9926..aa57892 100644 --- a/examples/Foo.vy +++ b/examples/Foo.vy @@ -1,4 +1,4 @@ -#pragma version 0.3.8 +#pragma version 0.3.10 event Foo: arg1: uint256 diff --git a/tests/test_ast.py b/tests/test_ast.py index 7574cc4..05d67ec 100644 --- a/tests/test_ast.py +++ b/tests/test_ast.py @@ -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): diff --git a/tests/test_navigation.py b/tests/test_navigation.py index 0cc8b37..41787ac 100644 --- a/tests/test_navigation.py +++ b/tests/test_navigation.py @@ -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): @@ -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 diff --git a/vyper_lsp/ast.py b/vyper_lsp/ast.py index c7eb6d6..9bac1dc 100644 --- a/vyper_lsp/ast.py +++ b/vyper_lsp/ast.py @@ -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): @@ -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): diff --git a/vyper_lsp/navigation.py b/vyper_lsp/navigation.py index f2202e6..0740b30 100644 --- a/vyper_lsp/navigation.py +++ b/vyper_lsp/navigation.py @@ -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: @@ -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):