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

Properly format documentation for SignatureHelpRequests #14974

Merged
merged 1 commit into from
Jun 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 31 additions & 2 deletions crates/rust-analyzer/src/to_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ pub(crate) fn signature_help(
let documentation = call_info.doc.filter(|_| config.docs).map(|doc| {
lsp_types::Documentation::MarkupContent(lsp_types::MarkupContent {
kind: lsp_types::MarkupKind::Markdown,
value: doc,
value: crate::markdown::format_docs(&doc),
})
});

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

#[cfg(test)]
mod tests {
use ide::Analysis;
use ide::{Analysis, FilePosition};
use test_utils::extract_offset;
use triomphe::Arc;

use super::*;
Expand Down Expand Up @@ -1451,6 +1452,34 @@ fn main() {
}
}

#[test]
fn calling_function_with_ignored_code_in_signature() {
let text = r#"
fn foo() {
bar($0);
}
/// ```
/// # use crate::bar;
/// bar(5);
/// ```
fn bar(_: usize) {}
"#;

let (offset, text) = extract_offset(text);
let (analysis, file_id) = Analysis::from_single_file(text);
let help = signature_help(
analysis.signature_help(FilePosition { file_id, offset }).unwrap().unwrap(),
CallInfoConfig { params_only: false, docs: true },
false,
);
let docs = match &help.signatures[help.active_signature.unwrap() as usize].documentation {
Some(lsp_types::Documentation::MarkupContent(content)) => &content.value,
_ => panic!("documentation contains markup"),
};
assert!(docs.contains("bar(5)"));
assert!(!docs.contains("use crate::bar"));
}

// `Url` is not able to parse windows paths on unix machines.
#[test]
#[cfg(target_os = "windows")]
Expand Down