Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: LSP inlay hints for let and global #5510

Merged
merged 17 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions compiler/noirc_errors/src/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ impl Span {
self.start() <= other.start() && self.end() >= other.end()
}

pub fn intersects(&self, other: &Span) -> bool {
self.end() > other.start() && self.start() < other.end()
}

pub fn is_smaller(&self, other: &Span) -> bool {
let self_distance = self.end() - self.start();
let other_distance = other.end() - other.start();
Expand Down
1 change: 1 addition & 0 deletions tooling/lsp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ license.workspace = true
acvm.workspace = true
codespan-lsp.workspace = true
lsp-types.workspace = true
lsp_types_0_88_0 = { package = "lsp-types", version = "0.88.0" }
nargo.workspace = true
nargo_fmt.workspace = true
nargo_toml.workspace = true
Expand Down
9 changes: 5 additions & 4 deletions tooling/lsp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use async_lsp::{
use fm::{codespan_files as files, FileManager};
use fxhash::FxHashSet;
use lsp_types::{
request::{HoverRequest, PrepareRenameRequest, References, Rename},
request::{HoverRequest, InlayHintRequest, PrepareRenameRequest, References, Rename},
CodeLens,
};
use nargo::{
Expand All @@ -46,9 +46,9 @@ use notifications::{
};
use requests::{
on_code_lens_request, on_formatting, on_goto_declaration_request, on_goto_definition_request,
on_goto_type_definition_request, on_hover_request, on_initialize, on_prepare_rename_request,
on_profile_run_request, on_references_request, on_rename_request, on_shutdown,
on_test_run_request, on_tests_request,
on_goto_type_definition_request, on_hover_request, on_initialize, on_inlay_hint_request,
on_prepare_rename_request, on_profile_run_request, on_references_request, on_rename_request,
on_shutdown, on_test_run_request, on_tests_request,
};
use serde_json::Value as JsonValue;
use thiserror::Error;
Expand Down Expand Up @@ -130,6 +130,7 @@ impl NargoLspService {
.request::<PrepareRenameRequest, _>(on_prepare_rename_request)
.request::<Rename, _>(on_rename_request)
.request::<HoverRequest, _>(on_hover_request)
.request::<InlayHintRequest, _>(on_inlay_hint_request)
.notification::<notification::Initialized>(on_initialized)
.notification::<notification::DidChangeConfiguration>(on_did_change_configuration)
.notification::<notification::DidOpenTextDocument>(on_did_open_text_document)
Expand Down
33 changes: 33 additions & 0 deletions tooling/lsp/src/requests/goto_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ fn on_goto_definition_inner(
process_request(state, params.text_document_position_params, |args| {
args.interner
.get_definition_location_from(args.location, return_type_location_instead)
.or_else(|| {
args.interner
.reference_at_location(args.location)
.map(|reference| args.interner.reference_location(reference))
})
.and_then(|found_location| {
let file_id = found_location.file;
let definition_position =
Expand Down Expand Up @@ -202,4 +207,32 @@ mod goto_definition_tests {
async fn goto_for_local_variable() {
expect_goto_for_all_references("local_variable", "some_var", 0).await;
}

#[test]
async fn goto_at_struct_definition_finds_same_struct() {
expect_goto(
"go_to_definition",
Position { line: 21, character: 7 }, // "Foo" in "struct Foo"
"src/main.nr",
Range {
start: Position { line: 21, character: 7 },
end: Position { line: 21, character: 10 },
},
)
.await;
}

#[test]
async fn goto_at_trait_definition_finds_same_trait() {
expect_goto(
"go_to_definition",
Position { line: 25, character: 6 }, // "Trait" in "trait Trait"
"src/main.nr",
Range {
start: Position { line: 25, character: 6 },
end: Position { line: 25, character: 11 },
},
)
.await;
}
}
Loading
Loading