mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Add some more attribute ide tests
This commit is contained in:
parent
6f9de71402
commit
538ac599d2
8 changed files with 156 additions and 9 deletions
|
@ -16,7 +16,6 @@ use itertools::Itertools;
|
||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
use smallvec::{smallvec, SmallVec};
|
use smallvec::{smallvec, SmallVec};
|
||||||
use syntax::{
|
use syntax::{
|
||||||
algo::find_node_at_offset,
|
|
||||||
ast::{self, GenericParamsOwner, LoopBodyOwner},
|
ast::{self, GenericParamsOwner, LoopBodyOwner},
|
||||||
match_ast, AstNode, SyntaxNode, SyntaxNodePtr, SyntaxToken, TextRange, TextSize,
|
match_ast, AstNode, SyntaxNode, SyntaxNodePtr, SyntaxToken, TextRange, TextSize,
|
||||||
};
|
};
|
||||||
|
@ -241,10 +240,6 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
|
||||||
node: &SyntaxNode,
|
node: &SyntaxNode,
|
||||||
offset: TextSize,
|
offset: TextSize,
|
||||||
) -> Option<N> {
|
) -> Option<N> {
|
||||||
if let Some(it) = find_node_at_offset(node, offset) {
|
|
||||||
return Some(it);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.imp.descend_node_at_offset(node, offset).flatten().find_map(N::cast)
|
self.imp.descend_node_at_offset(node, offset).flatten().find_map(N::cast)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ pub(crate) fn expand_macro(db: &RootDatabase, position: FilePosition) -> Option<
|
||||||
SyntaxKind::IDENT => 1,
|
SyntaxKind::IDENT => 1,
|
||||||
_ => 0,
|
_ => 0,
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let descended = sema.descend_into_macros(tok.clone());
|
let descended = sema.descend_into_macros(tok.clone());
|
||||||
if let Some(attr) = descended.ancestors().find_map(ast::Attr::cast) {
|
if let Some(attr) = descended.ancestors().find_map(ast::Attr::cast) {
|
||||||
if let Some((path, tt)) = attr.as_simple_call() {
|
if let Some((path, tt)) = attr.as_simple_call() {
|
||||||
|
@ -45,6 +46,9 @@ pub(crate) fn expand_macro(db: &RootDatabase, position: FilePosition) -> Option<
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: Intermix attribute and bang! expansions
|
||||||
|
// currently we only recursively expand one of the two types
|
||||||
let mut expanded = None;
|
let mut expanded = None;
|
||||||
let mut name = None;
|
let mut name = None;
|
||||||
for node in tok.ancestors() {
|
for node in tok.ancestors() {
|
||||||
|
|
|
@ -1661,6 +1661,28 @@ id! {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_hover_through_attr() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
//- proc_macros: identity
|
||||||
|
#[proc_macros::identity]
|
||||||
|
fn foo$0() {}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
*foo*
|
||||||
|
|
||||||
|
```rust
|
||||||
|
test
|
||||||
|
```
|
||||||
|
|
||||||
|
```rust
|
||||||
|
fn foo()
|
||||||
|
```
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_hover_through_expr_in_macro() {
|
fn test_hover_through_expr_in_macro() {
|
||||||
check(
|
check(
|
||||||
|
|
|
@ -1507,4 +1507,23 @@ fn f() {
|
||||||
"#]],
|
"#]],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn attr_expanded() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
//- proc_macros: identity
|
||||||
|
|
||||||
|
#[proc_macros::identity]
|
||||||
|
fn func$0() {
|
||||||
|
func();
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
func Function FileId(0) 26..51 29..33
|
||||||
|
|
||||||
|
FileId(0) 42..46
|
||||||
|
"#]],
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1880,4 +1880,26 @@ fn main() { f$0() }
|
||||||
"error: No identifier available to rename",
|
"error: No identifier available to rename",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn attributed_item() {
|
||||||
|
check(
|
||||||
|
"function",
|
||||||
|
r#"
|
||||||
|
//- proc_macros: identity
|
||||||
|
|
||||||
|
#[proc_macros::identity]
|
||||||
|
fn func$0() {
|
||||||
|
func();
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
r#"
|
||||||
|
|
||||||
|
#[proc_macros::identity]
|
||||||
|
fn function() {
|
||||||
|
function();
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1737,6 +1737,88 @@ fn t1() {}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn attributed_module() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
//- proc_macros: identity
|
||||||
|
//- /lib.rs
|
||||||
|
$0
|
||||||
|
#[proc_macros::identity]
|
||||||
|
mod module {
|
||||||
|
#[test]
|
||||||
|
fn t0() {}
|
||||||
|
#[test]
|
||||||
|
fn t1() {}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
&[TestMod, Test, Test],
|
||||||
|
expect![[r#"
|
||||||
|
[
|
||||||
|
Runnable {
|
||||||
|
use_name_in_title: true,
|
||||||
|
nav: NavigationTarget {
|
||||||
|
file_id: FileId(
|
||||||
|
0,
|
||||||
|
),
|
||||||
|
full_range: 26..94,
|
||||||
|
focus_range: 30..36,
|
||||||
|
name: "module",
|
||||||
|
kind: Module,
|
||||||
|
description: "mod module",
|
||||||
|
},
|
||||||
|
kind: TestMod {
|
||||||
|
path: "module",
|
||||||
|
},
|
||||||
|
cfg: None,
|
||||||
|
},
|
||||||
|
Runnable {
|
||||||
|
use_name_in_title: true,
|
||||||
|
nav: NavigationTarget {
|
||||||
|
file_id: FileId(
|
||||||
|
0,
|
||||||
|
),
|
||||||
|
full_range: 43..65,
|
||||||
|
focus_range: 58..60,
|
||||||
|
name: "t0",
|
||||||
|
kind: Function,
|
||||||
|
},
|
||||||
|
kind: Test {
|
||||||
|
test_id: Path(
|
||||||
|
"module::t0",
|
||||||
|
),
|
||||||
|
attr: TestAttr {
|
||||||
|
ignore: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
cfg: None,
|
||||||
|
},
|
||||||
|
Runnable {
|
||||||
|
use_name_in_title: true,
|
||||||
|
nav: NavigationTarget {
|
||||||
|
file_id: FileId(
|
||||||
|
0,
|
||||||
|
),
|
||||||
|
full_range: 70..92,
|
||||||
|
focus_range: 85..87,
|
||||||
|
name: "t1",
|
||||||
|
kind: Function,
|
||||||
|
},
|
||||||
|
kind: Test {
|
||||||
|
test_id: Path(
|
||||||
|
"module::t1",
|
||||||
|
),
|
||||||
|
attr: TestAttr {
|
||||||
|
ignore: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
cfg: None,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn find_no_tests() {
|
fn find_no_tests() {
|
||||||
check_tests(
|
check_tests(
|
||||||
|
|
|
@ -51,14 +51,15 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
||||||
<span class="keyword">pub</span> <span class="keyword">trait</span> <span class="trait declaration public">Copy</span> <span class="brace">{</span><span class="brace">}</span>
|
<span class="keyword">pub</span> <span class="keyword">trait</span> <span class="trait declaration public">Copy</span> <span class="brace">{</span><span class="brace">}</span>
|
||||||
<span class="brace">}</span>
|
<span class="brace">}</span>
|
||||||
|
|
||||||
<span class="keyword">pub</span> <span class="keyword">mod</span> <span class="module declaration public">ops</span> <span class="brace">{</span>
|
<span class="attribute attribute">#</span><span class="attribute attribute">[</span><span class="module attribute">proc_macros</span><span class="operator attribute">::</span><span class="builtin_attr attribute">identity</span><span class="attribute attribute">]</span>
|
||||||
<span class="attribute attribute">#</span><span class="attribute attribute">[</span><span class="builtin_attr attribute">lang</span><span class="attribute attribute"> </span><span class="operator attribute">=</span><span class="attribute attribute"> </span><span class="string_literal attribute">"fn_once"</span><span class="attribute attribute">]</span>
|
<span class="keyword">pub</span> <span class="keyword">mod</span> <span class="module declaration">ops</span> <span class="brace">{</span>
|
||||||
|
<span class="attribute attribute">#</span><span class="attribute attribute">[</span><span class="builtin_attr attribute">lang</span> <span class="operator attribute">=</span> <span class="string_literal attribute">"fn_once"</span><span class="attribute attribute">]</span>
|
||||||
<span class="keyword">pub</span> <span class="keyword">trait</span> <span class="trait declaration public">FnOnce</span><span class="angle"><</span><span class="type_param declaration">Args</span><span class="angle">></span> <span class="brace">{</span><span class="brace">}</span>
|
<span class="keyword">pub</span> <span class="keyword">trait</span> <span class="trait declaration public">FnOnce</span><span class="angle"><</span><span class="type_param declaration">Args</span><span class="angle">></span> <span class="brace">{</span><span class="brace">}</span>
|
||||||
|
|
||||||
<span class="attribute attribute">#</span><span class="attribute attribute">[</span><span class="builtin_attr attribute">lang</span><span class="attribute attribute"> </span><span class="operator attribute">=</span><span class="attribute attribute"> </span><span class="string_literal attribute">"fn_mut"</span><span class="attribute attribute">]</span>
|
<span class="attribute attribute">#</span><span class="attribute attribute">[</span><span class="builtin_attr attribute">lang</span> <span class="operator attribute">=</span> <span class="string_literal attribute">"fn_mut"</span><span class="attribute attribute">]</span>
|
||||||
<span class="keyword">pub</span> <span class="keyword">trait</span> <span class="trait declaration public">FnMut</span><span class="angle"><</span><span class="type_param declaration">Args</span><span class="angle">></span><span class="colon">:</span> <span class="trait public">FnOnce</span><span class="angle"><</span><span class="type_param">Args</span><span class="angle">></span> <span class="brace">{</span><span class="brace">}</span>
|
<span class="keyword">pub</span> <span class="keyword">trait</span> <span class="trait declaration public">FnMut</span><span class="angle"><</span><span class="type_param declaration">Args</span><span class="angle">></span><span class="colon">:</span> <span class="trait public">FnOnce</span><span class="angle"><</span><span class="type_param">Args</span><span class="angle">></span> <span class="brace">{</span><span class="brace">}</span>
|
||||||
|
|
||||||
<span class="attribute attribute">#</span><span class="attribute attribute">[</span><span class="builtin_attr attribute">lang</span><span class="attribute attribute"> </span><span class="operator attribute">=</span><span class="attribute attribute"> </span><span class="string_literal attribute">"fn"</span><span class="attribute attribute">]</span>
|
<span class="attribute attribute">#</span><span class="attribute attribute">[</span><span class="builtin_attr attribute">lang</span> <span class="operator attribute">=</span> <span class="string_literal attribute">"fn"</span><span class="attribute attribute">]</span>
|
||||||
<span class="keyword">pub</span> <span class="keyword">trait</span> <span class="trait declaration public">Fn</span><span class="angle"><</span><span class="type_param declaration">Args</span><span class="angle">></span><span class="colon">:</span> <span class="trait public">FnMut</span><span class="angle"><</span><span class="type_param">Args</span><span class="angle">></span> <span class="brace">{</span><span class="brace">}</span>
|
<span class="keyword">pub</span> <span class="keyword">trait</span> <span class="trait declaration public">Fn</span><span class="angle"><</span><span class="type_param declaration">Args</span><span class="angle">></span><span class="colon">:</span> <span class="trait public">FnMut</span><span class="angle"><</span><span class="type_param">Args</span><span class="angle">></span> <span class="brace">{</span><span class="brace">}</span>
|
||||||
<span class="brace">}</span>
|
<span class="brace">}</span>
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ use crate::{fixture, FileRange, HlTag, TextRange};
|
||||||
fn test_highlighting() {
|
fn test_highlighting() {
|
||||||
check_highlighting(
|
check_highlighting(
|
||||||
r#"
|
r#"
|
||||||
|
//- proc_macros: identity
|
||||||
//- /main.rs crate:main deps:foo
|
//- /main.rs crate:main deps:foo
|
||||||
use inner::{self as inner_mod};
|
use inner::{self as inner_mod};
|
||||||
mod inner {}
|
mod inner {}
|
||||||
|
@ -23,6 +24,7 @@ pub mod marker {
|
||||||
pub trait Copy {}
|
pub trait Copy {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[proc_macros::identity]
|
||||||
pub mod ops {
|
pub mod ops {
|
||||||
#[lang = "fn_once"]
|
#[lang = "fn_once"]
|
||||||
pub trait FnOnce<Args> {}
|
pub trait FnOnce<Args> {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue