Skip to content

Commit c8d5ce5

Browse files
authored
fix: LSP hover over function with &mut self (#7155)
1 parent 7f9525d commit c8d5ce5

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

tooling/lsp/src/requests/hover.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -491,14 +491,24 @@ fn format_function(id: FuncId, args: &ProcessRequestCallbackArgs) -> String {
491491
string.push('(');
492492
let parameters = &func_meta.parameters;
493493
for (index, (pattern, typ, visibility)) in parameters.iter().enumerate() {
494+
let is_self = pattern_is_self(pattern, args.interner);
495+
496+
// `&mut self` is represented as a mutable reference type, not as a mutable pattern
497+
if is_self && matches!(typ, Type::MutableReference(..)) {
498+
string.push_str("&mut ");
499+
}
500+
494501
format_pattern(pattern, args.interner, &mut string);
495-
if !pattern_is_self(pattern, args.interner) {
502+
503+
// Don't add type for `self` param
504+
if !is_self {
496505
string.push_str(": ");
497506
if matches!(visibility, Visibility::Public) {
498507
string.push_str("pub ");
499508
}
500509
string.push_str(&format!("{}", typ));
501510
}
511+
502512
if index != parameters.len() - 1 {
503513
string.push_str(", ");
504514
}
@@ -1238,4 +1248,12 @@ mod hover_tests {
12381248
.await;
12391249
assert!(hover_text.contains("Some docs"));
12401250
}
1251+
1252+
#[test]
1253+
async fn hover_on_function_with_mut_self() {
1254+
let hover_text =
1255+
get_hover_text("workspace", "two/src/lib.nr", Position { line: 96, character: 10 })
1256+
.await;
1257+
assert!(hover_text.contains("fn mut_self(&mut self)"));
1258+
}
12411259
}

tooling/lsp/test_programs/workspace/two/src/lib.nr

+3
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,6 @@ impl TraitWithDocs for Field {
9393
fn foo() {}
9494
}
9595

96+
impl<U> Foo<U> {
97+
fn mut_self(&mut self) {}
98+
}

0 commit comments

Comments
 (0)