Skip to content

Commit 538ac59

Browse files
committed
Add some more attribute ide tests
1 parent 6f9de71 commit 538ac59

File tree

8 files changed

+156
-9
lines changed

8 files changed

+156
-9
lines changed

crates/hir/src/semantics.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use itertools::Itertools;
1616
use rustc_hash::{FxHashMap, FxHashSet};
1717
use smallvec::{smallvec, SmallVec};
1818
use syntax::{
19-
algo::find_node_at_offset,
2019
ast::{self, GenericParamsOwner, LoopBodyOwner},
2120
match_ast, AstNode, SyntaxNode, SyntaxNodePtr, SyntaxToken, TextRange, TextSize,
2221
};
@@ -241,10 +240,6 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
241240
node: &SyntaxNode,
242241
offset: TextSize,
243242
) -> Option<N> {
244-
if let Some(it) = find_node_at_offset(node, offset) {
245-
return Some(it);
246-
}
247-
248243
self.imp.descend_node_at_offset(node, offset).flatten().find_map(N::cast)
249244
}
250245

crates/ide/src/expand_macro.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub(crate) fn expand_macro(db: &RootDatabase, position: FilePosition) -> Option<
3131
SyntaxKind::IDENT => 1,
3232
_ => 0,
3333
})?;
34+
3435
let descended = sema.descend_into_macros(tok.clone());
3536
if let Some(attr) = descended.ancestors().find_map(ast::Attr::cast) {
3637
if let Some((path, tt)) = attr.as_simple_call() {
@@ -45,6 +46,9 @@ pub(crate) fn expand_macro(db: &RootDatabase, position: FilePosition) -> Option<
4546
}
4647
}
4748
}
49+
50+
// FIXME: Intermix attribute and bang! expansions
51+
// currently we only recursively expand one of the two types
4852
let mut expanded = None;
4953
let mut name = None;
5054
for node in tok.ancestors() {

crates/ide/src/hover.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,6 +1661,28 @@ id! {
16611661
);
16621662
}
16631663

1664+
#[test]
1665+
fn test_hover_through_attr() {
1666+
check(
1667+
r#"
1668+
//- proc_macros: identity
1669+
#[proc_macros::identity]
1670+
fn foo$0() {}
1671+
"#,
1672+
expect![[r#"
1673+
*foo*
1674+
1675+
```rust
1676+
test
1677+
```
1678+
1679+
```rust
1680+
fn foo()
1681+
```
1682+
"#]],
1683+
);
1684+
}
1685+
16641686
#[test]
16651687
fn test_hover_through_expr_in_macro() {
16661688
check(

crates/ide/src/references.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,4 +1507,23 @@ fn f() {
15071507
"#]],
15081508
)
15091509
}
1510+
1511+
#[test]
1512+
fn attr_expanded() {
1513+
check(
1514+
r#"
1515+
//- proc_macros: identity
1516+
1517+
#[proc_macros::identity]
1518+
fn func$0() {
1519+
func();
1520+
}
1521+
"#,
1522+
expect![[r#"
1523+
func Function FileId(0) 26..51 29..33
1524+
1525+
FileId(0) 42..46
1526+
"#]],
1527+
)
1528+
}
15101529
}

crates/ide/src/rename.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,4 +1880,26 @@ fn main() { f$0() }
18801880
"error: No identifier available to rename",
18811881
)
18821882
}
1883+
1884+
#[test]
1885+
fn attributed_item() {
1886+
check(
1887+
"function",
1888+
r#"
1889+
//- proc_macros: identity
1890+
1891+
#[proc_macros::identity]
1892+
fn func$0() {
1893+
func();
1894+
}
1895+
"#,
1896+
r#"
1897+
1898+
#[proc_macros::identity]
1899+
fn function() {
1900+
function();
1901+
}
1902+
"#,
1903+
)
1904+
}
18831905
}

crates/ide/src/runnables.rs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,6 +1737,88 @@ fn t1() {}
17371737
);
17381738
}
17391739

1740+
#[test]
1741+
fn attributed_module() {
1742+
check(
1743+
r#"
1744+
//- proc_macros: identity
1745+
//- /lib.rs
1746+
$0
1747+
#[proc_macros::identity]
1748+
mod module {
1749+
#[test]
1750+
fn t0() {}
1751+
#[test]
1752+
fn t1() {}
1753+
}
1754+
"#,
1755+
&[TestMod, Test, Test],
1756+
expect![[r#"
1757+
[
1758+
Runnable {
1759+
use_name_in_title: true,
1760+
nav: NavigationTarget {
1761+
file_id: FileId(
1762+
0,
1763+
),
1764+
full_range: 26..94,
1765+
focus_range: 30..36,
1766+
name: "module",
1767+
kind: Module,
1768+
description: "mod module",
1769+
},
1770+
kind: TestMod {
1771+
path: "module",
1772+
},
1773+
cfg: None,
1774+
},
1775+
Runnable {
1776+
use_name_in_title: true,
1777+
nav: NavigationTarget {
1778+
file_id: FileId(
1779+
0,
1780+
),
1781+
full_range: 43..65,
1782+
focus_range: 58..60,
1783+
name: "t0",
1784+
kind: Function,
1785+
},
1786+
kind: Test {
1787+
test_id: Path(
1788+
"module::t0",
1789+
),
1790+
attr: TestAttr {
1791+
ignore: false,
1792+
},
1793+
},
1794+
cfg: None,
1795+
},
1796+
Runnable {
1797+
use_name_in_title: true,
1798+
nav: NavigationTarget {
1799+
file_id: FileId(
1800+
0,
1801+
),
1802+
full_range: 70..92,
1803+
focus_range: 85..87,
1804+
name: "t1",
1805+
kind: Function,
1806+
},
1807+
kind: Test {
1808+
test_id: Path(
1809+
"module::t1",
1810+
),
1811+
attr: TestAttr {
1812+
ignore: false,
1813+
},
1814+
},
1815+
cfg: None,
1816+
},
1817+
]
1818+
"#]],
1819+
);
1820+
}
1821+
17401822
#[test]
17411823
fn find_no_tests() {
17421824
check_tests(

crates/ide/src/syntax_highlighting/test_data/highlighting.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,15 @@
5151
<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>
5252
<span class="brace">}</span>
5353

54-
<span class="keyword">pub</span> <span class="keyword">mod</span> <span class="module declaration public">ops</span> <span class="brace">{</span>
55-
<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>
54+
<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>
55+
<span class="keyword">pub</span> <span class="keyword">mod</span> <span class="module declaration">ops</span> <span class="brace">{</span>
56+
<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>
5657
<span class="keyword">pub</span> <span class="keyword">trait</span> <span class="trait declaration public">FnOnce</span><span class="angle">&lt;</span><span class="type_param declaration">Args</span><span class="angle">&gt;</span> <span class="brace">{</span><span class="brace">}</span>
5758

58-
<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>
59+
<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>
5960
<span class="keyword">pub</span> <span class="keyword">trait</span> <span class="trait declaration public">FnMut</span><span class="angle">&lt;</span><span class="type_param declaration">Args</span><span class="angle">&gt;</span><span class="colon">:</span> <span class="trait public">FnOnce</span><span class="angle">&lt;</span><span class="type_param">Args</span><span class="angle">&gt;</span> <span class="brace">{</span><span class="brace">}</span>
6061

61-
<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>
62+
<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>
6263
<span class="keyword">pub</span> <span class="keyword">trait</span> <span class="trait declaration public">Fn</span><span class="angle">&lt;</span><span class="type_param declaration">Args</span><span class="angle">&gt;</span><span class="colon">:</span> <span class="trait public">FnMut</span><span class="angle">&lt;</span><span class="type_param">Args</span><span class="angle">&gt;</span> <span class="brace">{</span><span class="brace">}</span>
6364
<span class="brace">}</span>
6465

crates/ide/src/syntax_highlighting/tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::{fixture, FileRange, HlTag, TextRange};
1010
fn test_highlighting() {
1111
check_highlighting(
1212
r#"
13+
//- proc_macros: identity
1314
//- /main.rs crate:main deps:foo
1415
use inner::{self as inner_mod};
1516
mod inner {}
@@ -23,6 +24,7 @@ pub mod marker {
2324
pub trait Copy {}
2425
}
2526
27+
#[proc_macros::identity]
2628
pub mod ops {
2729
#[lang = "fn_once"]
2830
pub trait FnOnce<Args> {}

0 commit comments

Comments
 (0)