Skip to content
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 @@ fn format_function(id: FuncId, args: &ProcessRequestCallbackArgs) -> String {
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 @@ -1238,4 +1248,12 @@ mod hover_tests {
.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) {}
}