mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
Set documentation field in SCIP from doc comment
Previously, the documentation field was the same as the text shown to users when they hover over that symbol. The documentation should really just be the doc comment, and as of #16179 the signature is already stored in the signatureDocumentation field.
This commit is contained in:
parent
dba59970bc
commit
dda641c62c
2 changed files with 44 additions and 10 deletions
|
@ -135,12 +135,11 @@ impl flags::Scip {
|
|||
}
|
||||
|
||||
if symbols_emitted.insert(id) {
|
||||
let documentation = token
|
||||
.hover
|
||||
.as_ref()
|
||||
.map(|hover| hover.markup.as_str())
|
||||
.filter(|it| !it.is_empty())
|
||||
.map(|it| vec![it.to_owned()]);
|
||||
let documentation = match &token.documentation {
|
||||
Some(doc) => vec![doc.as_str().to_owned()],
|
||||
None => vec![],
|
||||
};
|
||||
|
||||
let position_encoding =
|
||||
scip_types::PositionEncoding::UTF8CodeUnitOffsetFromLineStart.into();
|
||||
let signature_documentation =
|
||||
|
@ -153,7 +152,7 @@ impl flags::Scip {
|
|||
});
|
||||
let symbol_info = scip_types::SymbolInformation {
|
||||
symbol: symbol.clone(),
|
||||
documentation: documentation.unwrap_or_default(),
|
||||
documentation,
|
||||
relationships: Vec::new(),
|
||||
special_fields: Default::default(),
|
||||
kind: symbol_kind(token.kind).into(),
|
||||
|
@ -599,4 +598,22 @@ pub mod example_mod {
|
|||
"rust-analyzer cargo main . MyTypeAlias#",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn documentation_matches_doc_comment() {
|
||||
let s = "/// foo\nfn bar() {}";
|
||||
|
||||
let mut host = AnalysisHost::default();
|
||||
let change_fixture = ChangeFixture::parse(s);
|
||||
host.raw_database_mut().apply_change(change_fixture.change);
|
||||
|
||||
let analysis = host.analysis();
|
||||
let si = StaticIndex::compute(&analysis);
|
||||
|
||||
let file = si.files.first().unwrap();
|
||||
let (_, token_id) = file.tokens.first().unwrap();
|
||||
let token = si.tokens.get(*token_id).unwrap();
|
||||
|
||||
assert_eq!(token.documentation.as_ref().map(|d| d.as_str()), Some("foo"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue