Skip to content

Commit

Permalink
fix: LSP document symbol didn't work for primitive impls (#5970)
Browse files Browse the repository at this point in the history
# Description

## Problem

While working with the standard library I noticed Document Symbol didn't
work with primitive impls.

## Summary

If you have this:

```rust
impl i32 {
  fn foo() {}
}
```

then pressing command+shift+o on VS Code didn't show `impl i32` nor
`foo()`. I think when I coded this logic I didn't know you could have
impls for non-named types. This PR fixes that.

## Additional Context



## Documentation

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
  • Loading branch information
asterite authored Sep 9, 2024
1 parent 36756e8 commit e1f81da
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
27 changes: 20 additions & 7 deletions tooling/lsp/src/requests/document_symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
};

Expand Down Expand Up @@ -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())
}
]
);
}
Expand Down
2 changes: 2 additions & 0 deletions tooling/lsp/test_programs/document_symbol/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ impl SomeTrait<i32> for SomeStruct {
mod submodule {
global SOME_GLOBAL = 1;
}

impl i32 {}

0 comments on commit e1f81da

Please sign in to comment.