mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
fix derive hover in macro
This commit is contained in:
parent
0777698f29
commit
887b7ddc37
1 changed files with 55 additions and 14 deletions
|
@ -118,26 +118,36 @@ pub(crate) fn hover(
|
||||||
|
|
||||||
let mut fallback = None;
|
let mut fallback = None;
|
||||||
// attributes, require special machinery as they are mere ident tokens
|
// attributes, require special machinery as they are mere ident tokens
|
||||||
if token.kind() != COMMENT {
|
|
||||||
if let Some(attr) = token.ancestors().find_map(ast::Attr::cast) {
|
let descend_macros = sema.descend_into_macros_many(token.clone());
|
||||||
// lints
|
|
||||||
if let Some(res) = try_hover_for_lint(&attr, &token) {
|
for token in &descend_macros {
|
||||||
return Some(res);
|
if token.kind() != COMMENT {
|
||||||
// derives
|
if let Some(attr) = token.ancestors().find_map(ast::Attr::cast) {
|
||||||
} else {
|
// lints
|
||||||
let def = try_resolve_derive_input_at(&sema, &attr, &token).map(Definition::Macro);
|
if let Some(res) = try_hover_for_lint(&attr, &token) {
|
||||||
if let Some(def) = def {
|
return Some(res);
|
||||||
if let Some(hover) =
|
// derives
|
||||||
hover_for_definition(&sema, file_id, def, &token.parent().unwrap(), config)
|
} else {
|
||||||
{
|
let def =
|
||||||
return Some(RangeInfo::new(token.text_range(), hover));
|
try_resolve_derive_input_at(&sema, &attr, &token).map(Definition::Macro);
|
||||||
|
if let Some(def) = def {
|
||||||
|
if let Some(hover) = hover_for_definition(
|
||||||
|
&sema,
|
||||||
|
file_id,
|
||||||
|
def,
|
||||||
|
&token.parent().unwrap(),
|
||||||
|
config,
|
||||||
|
) {
|
||||||
|
return Some(RangeInfo::new(token.text_range(), hover));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sema.descend_into_macros_many(token.clone())
|
descend_macros
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|token| match token.parent() {
|
.filter_map(|token| match token.parent() {
|
||||||
Some(node) => {
|
Some(node) => {
|
||||||
|
@ -4560,6 +4570,37 @@ use crate as foo$0;
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: wrong range in macros. `es! ` should be `Copy`
|
||||||
|
#[test]
|
||||||
|
fn hover_attribute_in_macro() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
macro_rules! identity {
|
||||||
|
($struct:item) => {
|
||||||
|
$struct
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#[rustc_builtin_macro]
|
||||||
|
pub macro Copy {}
|
||||||
|
identity!{
|
||||||
|
#[derive(Copy$0)]
|
||||||
|
struct Foo;
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
*es! *
|
||||||
|
|
||||||
|
```rust
|
||||||
|
test
|
||||||
|
```
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub macro Copy
|
||||||
|
```
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn hover_derive_input() {
|
fn hover_derive_input() {
|
||||||
check(
|
check(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue