From 1a33b0dd2bc1744c95238466033fb3a504ddb197 Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Sun, 8 Sep 2024 19:10:26 -0300 Subject: [PATCH] fix: LSP document symbol didn't work for primitive impls --- tooling/lsp/src/requests/document_symbol.rs | 27 ++++++++++++++----- .../test_programs/document_symbol/src/main.nr | 2 ++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/tooling/lsp/src/requests/document_symbol.rs b/tooling/lsp/src/requests/document_symbol.rs index e06a3451681..7d5efee2949 100644 --- a/tooling/lsp/src/requests/document_symbol.rs +++ b/tooling/lsp/src/requests/document_symbol.rs @@ -10,7 +10,7 @@ use noirc_errors::Span; use noirc_frontend::{ ast::{ Expression, FunctionReturnType, Ident, LetStatement, NoirFunction, NoirStruct, NoirTrait, - NoirTraitImpl, TypeImpl, UnresolvedType, UnresolvedTypeData, Visitor, + NoirTraitImpl, TypeImpl, UnresolvedType, Visitor, }, parser::ParsedSubModule, ParsedModule, @@ -391,13 +391,9 @@ impl<'a> Visitor for DocumentSymbolCollector<'a> { return false; }; - let UnresolvedTypeData::Named(name_path, ..) = &type_impl.object_type.typ else { - return false; - }; + let name = type_impl.object_type.typ.to_string(); - let name = name_path.last_ident(); - - let Some(name_location) = self.to_lsp_location(name.span()) else { + let Some(name_location) = self.to_lsp_location(type_impl.object_type.span) else { return false; }; @@ -710,6 +706,23 @@ mod document_symbol_tests { } ]), }, + #[allow(deprecated)] + DocumentSymbol { + name: "i32".to_string(), + detail: None, + kind: SymbolKind::NAMESPACE, + tags: None, + deprecated: None, + range: Range { + start: Position { line: 27, character: 0 }, + end: Position { line: 27, character: 11 } + }, + selection_range: Range { + start: Position { line: 27, character: 5 }, + end: Position { line: 27, character: 8 } + }, + children: Some(Vec::new()) + } ] ); } diff --git a/tooling/lsp/test_programs/document_symbol/src/main.nr b/tooling/lsp/test_programs/document_symbol/src/main.nr index 39b2c7fff12..a88a6a21e1f 100644 --- a/tooling/lsp/test_programs/document_symbol/src/main.nr +++ b/tooling/lsp/test_programs/document_symbol/src/main.nr @@ -24,3 +24,5 @@ impl SomeTrait for SomeStruct { mod submodule { global SOME_GLOBAL = 1; } + +impl i32 {}