mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
feat: treat fn keyword inside function pointer type as primitive
This commit is contained in:
parent
9f1a3ae5ab
commit
67cc6c1e16
2 changed files with 33 additions and 3 deletions
|
@ -237,9 +237,15 @@ pub(super) fn keyword(
|
||||||
if !token.kind().is_keyword() || !config.documentation.is_some() {
|
if !token.kind().is_keyword() || !config.documentation.is_some() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let famous_defs = FamousDefs(sema, sema.scope(&token.parent()?).krate());
|
let parent = token.parent()?;
|
||||||
// std exposes {}_keyword modules with docstrings on the root to document keywords
|
let famous_defs = FamousDefs(sema, sema.scope(&parent).krate());
|
||||||
let keyword_mod = format!("{}_keyword", token.text());
|
let keyword_mod = if token.kind() == T![fn] && ast::FnPtrType::cast(parent).is_some() {
|
||||||
|
// treat fn keyword inside function pointer type as primitive
|
||||||
|
format!("prim_{}", token.text())
|
||||||
|
} else {
|
||||||
|
// std exposes {}_keyword modules with docstrings on the root to document keywords
|
||||||
|
format!("{}_keyword", token.text())
|
||||||
|
};
|
||||||
let doc_owner = find_std_module(&famous_defs, &keyword_mod)?;
|
let doc_owner = find_std_module(&famous_defs, &keyword_mod)?;
|
||||||
let docs = doc_owner.attrs(sema.db).docs()?;
|
let docs = doc_owner.attrs(sema.db).docs()?;
|
||||||
let markup = process_markup(
|
let markup = process_markup(
|
||||||
|
|
|
@ -3382,6 +3382,30 @@ mod return_keyword {}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn hover_keyword_as_primitive() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
//- /main.rs crate:main deps:std
|
||||||
|
type F = f$0n(i32) -> i32;
|
||||||
|
//- /libstd.rs crate:std
|
||||||
|
/// Docs for prim_fn
|
||||||
|
mod prim_fn {}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
*fn*
|
||||||
|
|
||||||
|
```rust
|
||||||
|
fn
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Docs for prim_fn
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn hover_builtin() {
|
fn hover_builtin() {
|
||||||
check(
|
check(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue