Skip to content

Commit 68bdf60

Browse files
committed
Auto merge of rust-lang#14974 - max-heller:issue-14958, r=lowr
Properly format documentation for `SignatureHelpRequest`s Properly formats function documentation instead of returning it raw when responding to `SignatureHelpRequest`s. I added a test in `crates/rust-analyzer/tests/slow-tests/main.rs` -- not sure if this is the best location given the relevant code is in `crates/rust-analyzer` or if it's possible to test in a less heavyweight manner. Closes rust-lang#14958
2 parents 95228d2 + 78fab7d commit 68bdf60

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

crates/rust-analyzer/src/to_proto.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ pub(crate) fn signature_help(
410410
let documentation = call_info.doc.filter(|_| config.docs).map(|doc| {
411411
lsp_types::Documentation::MarkupContent(lsp_types::MarkupContent {
412412
kind: lsp_types::MarkupKind::Markdown,
413-
value: doc,
413+
value: crate::markdown::format_docs(&doc),
414414
})
415415
});
416416

@@ -1410,7 +1410,8 @@ pub(crate) fn rename_error(err: RenameError) -> crate::LspError {
14101410

14111411
#[cfg(test)]
14121412
mod tests {
1413-
use ide::Analysis;
1413+
use ide::{Analysis, FilePosition};
1414+
use test_utils::extract_offset;
14141415
use triomphe::Arc;
14151416

14161417
use super::*;
@@ -1451,6 +1452,34 @@ fn main() {
14511452
}
14521453
}
14531454

1455+
#[test]
1456+
fn calling_function_with_ignored_code_in_signature() {
1457+
let text = r#"
1458+
fn foo() {
1459+
bar($0);
1460+
}
1461+
/// ```
1462+
/// # use crate::bar;
1463+
/// bar(5);
1464+
/// ```
1465+
fn bar(_: usize) {}
1466+
"#;
1467+
1468+
let (offset, text) = extract_offset(text);
1469+
let (analysis, file_id) = Analysis::from_single_file(text);
1470+
let help = signature_help(
1471+
analysis.signature_help(FilePosition { file_id, offset }).unwrap().unwrap(),
1472+
CallInfoConfig { params_only: false, docs: true },
1473+
false,
1474+
);
1475+
let docs = match &help.signatures[help.active_signature.unwrap() as usize].documentation {
1476+
Some(lsp_types::Documentation::MarkupContent(content)) => &content.value,
1477+
_ => panic!("documentation contains markup"),
1478+
};
1479+
assert!(docs.contains("bar(5)"));
1480+
assert!(!docs.contains("use crate::bar"));
1481+
}
1482+
14541483
// `Url` is not able to parse windows paths on unix machines.
14551484
#[test]
14561485
#[cfg(target_os = "windows")]

0 commit comments

Comments
 (0)