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

fix: LSP hover over function with &mut self #7155

Merged
merged 1 commit into from
Jan 22, 2025
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
20 changes: 19 additions & 1 deletion tooling/lsp/src/requests/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,14 +491,24 @@
string.push('(');
let parameters = &func_meta.parameters;
for (index, (pattern, typ, visibility)) in parameters.iter().enumerate() {
let is_self = pattern_is_self(pattern, args.interner);

// `&mut self` is represented as a mutable reference type, not as a mutable pattern
if is_self && matches!(typ, Type::MutableReference(..)) {
string.push_str("&mut ");
}

format_pattern(pattern, args.interner, &mut string);
if !pattern_is_self(pattern, args.interner) {

// Don't add type for `self` param
if !is_self {
string.push_str(": ");
if matches!(visibility, Visibility::Public) {
string.push_str("pub ");
}
string.push_str(&format!("{}", typ));
}

if index != parameters.len() - 1 {
string.push_str(", ");
}
Expand Down Expand Up @@ -929,7 +939,7 @@
"two/src/lib.nr",
Position { line: 6, character: 9 },
r#" one
mod subone"#,

Check warning on line 942 in tooling/lsp/src/requests/hover.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (subone)
)
.await;
}
Expand All @@ -940,7 +950,7 @@
"workspace",
"two/src/lib.nr",
Position { line: 9, character: 20 },
r#" one::subone

Check warning on line 953 in tooling/lsp/src/requests/hover.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (subone)
struct SubOneStruct {
some_field: i32,
some_other_field: Field,
Expand All @@ -955,7 +965,7 @@
"workspace",
"two/src/lib.nr",
Position { line: 46, character: 17 },
r#" one::subone

Check warning on line 968 in tooling/lsp/src/requests/hover.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (subone)
struct GenericStruct<A, B> {
}"#,
)
Expand All @@ -968,7 +978,7 @@
"workspace",
"two/src/lib.nr",
Position { line: 9, character: 35 },
r#" one::subone::SubOneStruct

Check warning on line 981 in tooling/lsp/src/requests/hover.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (subone)
some_field: i32"#,
)
.await;
Expand All @@ -980,7 +990,7 @@
"workspace",
"two/src/lib.nr",
Position { line: 12, character: 17 },
r#" one::subone

Check warning on line 993 in tooling/lsp/src/requests/hover.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (subone)
trait SomeTrait"#,
)
.await;
Expand Down Expand Up @@ -1238,4 +1248,12 @@
.await;
assert!(hover_text.contains("Some docs"));
}

#[test]
async fn hover_on_function_with_mut_self() {
let hover_text =
get_hover_text("workspace", "two/src/lib.nr", Position { line: 96, character: 10 })
.await;
assert!(hover_text.contains("fn mut_self(&mut self)"));
}
}
3 changes: 3 additions & 0 deletions tooling/lsp/test_programs/workspace/two/src/lib.nr
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,6 @@ impl TraitWithDocs for Field {
fn foo() {}
}

impl<U> Foo<U> {
fn mut_self(&mut self) {}
}
Loading