aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ide/src/call_hierarchy.rs52
-rw-r--r--crates/ide/src/display.rs3
-rw-r--r--crates/ide/src/display/navigation_target.rs132
-rw-r--r--crates/ide/src/file_structure.rs80
-rw-r--r--crates/ide/src/goto_definition.rs4
-rw-r--r--crates/ide/src/hover.rs74
-rw-r--r--crates/ide/src/lib.rs2
-rw-r--r--crates/ide/src/parent_module.rs6
-rw-r--r--crates/ide/src/references.rs72
-rw-r--r--crates/ide/src/runnables.rs52
-rw-r--r--crates/ide_db/src/symbol_index.rs48
-rw-r--r--crates/rust-analyzer/src/handlers.rs14
-rw-r--r--crates/rust-analyzer/src/to_proto.rs37
13 files changed, 337 insertions, 239 deletions
diff --git a/crates/ide/src/call_hierarchy.rs b/crates/ide/src/call_hierarchy.rs
index 8ad50a2ee..60e0cd4ad 100644
--- a/crates/ide/src/call_hierarchy.rs
+++ b/crates/ide/src/call_hierarchy.rs
@@ -181,8 +181,8 @@ fn caller() {
181 call<|>ee(); 181 call<|>ee();
182} 182}
183"#, 183"#,
184 "callee FN FileId(0) 0..14 3..9", 184 "callee Function FileId(0) 0..14 3..9",
185 &["caller FN FileId(0) 15..44 18..24 : [33..39]"], 185 &["caller Function FileId(0) 15..44 18..24 : [33..39]"],
186 &[], 186 &[],
187 ); 187 );
188 } 188 }
@@ -197,8 +197,8 @@ fn caller() {
197 callee(); 197 callee();
198} 198}
199"#, 199"#,
200 "callee FN FileId(0) 0..14 3..9", 200 "callee Function FileId(0) 0..14 3..9",
201 &["caller FN FileId(0) 15..44 18..24 : [33..39]"], 201 &["caller Function FileId(0) 15..44 18..24 : [33..39]"],
202 &[], 202 &[],
203 ); 203 );
204 } 204 }
@@ -214,8 +214,8 @@ fn caller() {
214 callee(); 214 callee();
215} 215}
216"#, 216"#,
217 "callee FN FileId(0) 0..14 3..9", 217 "callee Function FileId(0) 0..14 3..9",
218 &["caller FN FileId(0) 15..58 18..24 : [33..39, 47..53]"], 218 &["caller Function FileId(0) 15..58 18..24 : [33..39, 47..53]"],
219 &[], 219 &[],
220 ); 220 );
221 } 221 }
@@ -234,10 +234,10 @@ fn caller2() {
234 callee(); 234 callee();
235} 235}
236"#, 236"#,
237 "callee FN FileId(0) 0..14 3..9", 237 "callee Function FileId(0) 0..14 3..9",
238 &[ 238 &[
239 "caller1 FN FileId(0) 15..45 18..25 : [34..40]", 239 "caller1 Function FileId(0) 15..45 18..25 : [34..40]",
240 "caller2 FN FileId(0) 47..77 50..57 : [66..72]", 240 "caller2 Function FileId(0) 47..77 50..57 : [66..72]",
241 ], 241 ],
242 &[], 242 &[],
243 ); 243 );
@@ -263,10 +263,10 @@ mod tests {
263 } 263 }
264} 264}
265"#, 265"#,
266 "callee FN FileId(0) 0..14 3..9", 266 "callee Function FileId(0) 0..14 3..9",
267 &[ 267 &[
268 "caller1 FN FileId(0) 15..45 18..25 : [34..40]", 268 "caller1 Function FileId(0) 15..45 18..25 : [34..40]",
269 "test_caller FN FileId(0) 95..149 110..121 : [134..140]", 269 "test_caller Function FileId(0) 95..149 110..121 : [134..140]",
270 ], 270 ],
271 &[], 271 &[],
272 ); 272 );
@@ -287,8 +287,8 @@ fn caller() {
287//- /foo/mod.rs 287//- /foo/mod.rs
288pub fn callee() {} 288pub fn callee() {}
289"#, 289"#,
290 "callee FN FileId(1) 0..18 7..13", 290 "callee Function FileId(1) 0..18 7..13",
291 &["caller FN FileId(0) 27..56 30..36 : [45..51]"], 291 &["caller Function FileId(0) 27..56 30..36 : [45..51]"],
292 &[], 292 &[],
293 ); 293 );
294 } 294 }
@@ -304,9 +304,9 @@ fn call<|>er() {
304 callee(); 304 callee();
305} 305}
306"#, 306"#,
307 "caller FN FileId(0) 15..58 18..24", 307 "caller Function FileId(0) 15..58 18..24",
308 &[], 308 &[],
309 &["callee FN FileId(0) 0..14 3..9 : [33..39, 47..53]"], 309 &["callee Function FileId(0) 0..14 3..9 : [33..39, 47..53]"],
310 ); 310 );
311 } 311 }
312 312
@@ -325,9 +325,9 @@ fn call<|>er() {
325//- /foo/mod.rs 325//- /foo/mod.rs
326pub fn callee() {} 326pub fn callee() {}
327"#, 327"#,
328 "caller FN FileId(0) 27..56 30..36", 328 "caller Function FileId(0) 27..56 30..36",
329 &[], 329 &[],
330 &["callee FN FileId(1) 0..18 7..13 : [45..51]"], 330 &["callee Function FileId(1) 0..18 7..13 : [45..51]"],
331 ); 331 );
332 } 332 }
333 333
@@ -348,9 +348,9 @@ fn caller3() {
348 348
349} 349}
350"#, 350"#,
351 "caller2 FN FileId(0) 33..64 36..43", 351 "caller2 Function FileId(0) 33..64 36..43",
352 &["caller1 FN FileId(0) 0..31 3..10 : [19..26]"], 352 &["caller1 Function FileId(0) 0..31 3..10 : [19..26]"],
353 &["caller3 FN FileId(0) 66..83 69..76 : [52..59]"], 353 &["caller3 Function FileId(0) 66..83 69..76 : [52..59]"],
354 ); 354 );
355 } 355 }
356 356
@@ -368,9 +368,9 @@ fn main() {
368 a<|>() 368 a<|>()
369} 369}
370"#, 370"#,
371 "a FN FileId(0) 0..18 3..4", 371 "a Function FileId(0) 0..18 3..4",
372 &["main FN FileId(0) 31..52 34..38 : [47..48]"], 372 &["main Function FileId(0) 31..52 34..38 : [47..48]"],
373 &["b FN FileId(0) 20..29 23..24 : [13..14]"], 373 &["b Function FileId(0) 20..29 23..24 : [13..14]"],
374 ); 374 );
375 375
376 check_hierarchy( 376 check_hierarchy(
@@ -385,8 +385,8 @@ fn main() {
385 a() 385 a()
386} 386}
387"#, 387"#,
388 "b FN FileId(0) 20..29 23..24", 388 "b Function FileId(0) 20..29 23..24",
389 &["a FN FileId(0) 0..18 3..4 : [13..14]"], 389 &["a Function FileId(0) 0..18 3..4 : [13..14]"],
390 &[], 390 &[],
391 ); 391 );
392 } 392 }
diff --git a/crates/ide/src/display.rs b/crates/ide/src/display.rs
index 0650915c5..bae9e40df 100644
--- a/crates/ide/src/display.rs
+++ b/crates/ide/src/display.rs
@@ -1,10 +1,9 @@
1//! This module contains utilities for turning SyntaxNodes and HIR types 1//! This module contains utilities for turning SyntaxNodes and HIR types
2//! into types that may be used to render in a UI. 2//! into types that may be used to render in a UI.
3 3
4mod navigation_target; 4pub(crate) mod navigation_target;
5mod short_label; 5mod short_label;
6 6
7pub use navigation_target::NavigationTarget;
8pub(crate) use navigation_target::{ToNav, TryToNav}; 7pub(crate) use navigation_target::{ToNav, TryToNav};
9pub(crate) use short_label::ShortLabel; 8pub(crate) use short_label::ShortLabel;
10 9
diff --git a/crates/ide/src/display/navigation_target.rs b/crates/ide/src/display/navigation_target.rs
index 48acb8c93..ac6346b2b 100644
--- a/crates/ide/src/display/navigation_target.rs
+++ b/crates/ide/src/display/navigation_target.rs
@@ -2,19 +2,43 @@
2 2
3use either::Either; 3use either::Either;
4use hir::{AssocItem, Documentation, FieldSource, HasAttrs, HasSource, InFile, ModuleSource}; 4use hir::{AssocItem, Documentation, FieldSource, HasAttrs, HasSource, InFile, ModuleSource};
5use ide_db::base_db::{FileId, SourceDatabase}; 5use ide_db::{
6 base_db::{FileId, SourceDatabase},
7 symbol_index::FileSymbolKind,
8};
6use ide_db::{defs::Definition, RootDatabase}; 9use ide_db::{defs::Definition, RootDatabase};
7use syntax::{ 10use syntax::{
8 ast::{self, NameOwner}, 11 ast::{self, NameOwner},
9 match_ast, AstNode, SmolStr, 12 match_ast, AstNode, SmolStr, TextRange,
10 SyntaxKind::{self, IDENT_PAT, LIFETIME_PARAM, TYPE_PARAM},
11 TextRange,
12}; 13};
13 14
14use crate::FileSymbol; 15use crate::FileSymbol;
15 16
16use super::short_label::ShortLabel; 17use super::short_label::ShortLabel;
17 18
19#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
20pub enum SymbolKind {
21 Module,
22 Impl,
23 Field,
24 TypeParam,
25 LifetimeParam,
26 SelfParam,
27 Local,
28 Function,
29 Const,
30 Static,
31 Struct,
32 Enum,
33 Variant,
34 Union,
35 TypeAlias,
36 Trait,
37 Macro,
38 // Do we actually need this?
39 DocTest,
40}
41
18/// `NavigationTarget` represents and element in the editor's UI which you can 42/// `NavigationTarget` represents and element in the editor's UI which you can
19/// click on to navigate to a particular piece of code. 43/// click on to navigate to a particular piece of code.
20/// 44///
@@ -40,7 +64,7 @@ pub struct NavigationTarget {
40 /// Clients should place the cursor on this range when navigating to this target. 64 /// Clients should place the cursor on this range when navigating to this target.
41 pub focus_range: Option<TextRange>, 65 pub focus_range: Option<TextRange>,
42 pub name: SmolStr, 66 pub name: SmolStr,
43 pub kind: SyntaxKind, 67 pub kind: SymbolKind,
44 pub container_name: Option<SmolStr>, 68 pub container_name: Option<SmolStr>,
45 pub description: Option<String>, 69 pub description: Option<String>,
46 pub docs: Option<Documentation>, 70 pub docs: Option<Documentation>,
@@ -69,7 +93,7 @@ impl NavigationTarget {
69 name, 93 name,
70 None, 94 None,
71 frange.range, 95 frange.range,
72 src.value.syntax().kind(), 96 SymbolKind::Module,
73 ); 97 );
74 res.docs = module.attrs(db).docs(); 98 res.docs = module.attrs(db).docs();
75 res.description = src.value.short_label(); 99 res.description = src.value.short_label();
@@ -101,6 +125,7 @@ impl NavigationTarget {
101 pub(crate) fn from_named( 125 pub(crate) fn from_named(
102 db: &RootDatabase, 126 db: &RootDatabase,
103 node: InFile<&dyn ast::NameOwner>, 127 node: InFile<&dyn ast::NameOwner>,
128 kind: SymbolKind,
104 ) -> NavigationTarget { 129 ) -> NavigationTarget {
105 let name = 130 let name =
106 node.value.name().map(|it| it.text().clone()).unwrap_or_else(|| SmolStr::new("_")); 131 node.value.name().map(|it| it.text().clone()).unwrap_or_else(|| SmolStr::new("_"));
@@ -108,13 +133,7 @@ impl NavigationTarget {
108 node.value.name().map(|it| node.with_value(it.syntax()).original_file_range(db).range); 133 node.value.name().map(|it| node.with_value(it.syntax()).original_file_range(db).range);
109 let frange = node.map(|it| it.syntax()).original_file_range(db); 134 let frange = node.map(|it| it.syntax()).original_file_range(db);
110 135
111 NavigationTarget::from_syntax( 136 NavigationTarget::from_syntax(frange.file_id, name, focus_range, frange.range, kind)
112 frange.file_id,
113 name,
114 focus_range,
115 frange.range,
116 node.value.syntax().kind(),
117 )
118 } 137 }
119 138
120 fn from_syntax( 139 fn from_syntax(
@@ -122,7 +141,7 @@ impl NavigationTarget {
122 name: SmolStr, 141 name: SmolStr,
123 focus_range: Option<TextRange>, 142 focus_range: Option<TextRange>,
124 full_range: TextRange, 143 full_range: TextRange,
125 kind: SyntaxKind, 144 kind: SymbolKind,
126 ) -> NavigationTarget { 145 ) -> NavigationTarget {
127 NavigationTarget { 146 NavigationTarget {
128 file_id, 147 file_id,
@@ -142,7 +161,17 @@ impl ToNav for FileSymbol {
142 NavigationTarget { 161 NavigationTarget {
143 file_id: self.file_id, 162 file_id: self.file_id,
144 name: self.name.clone(), 163 name: self.name.clone(),
145 kind: self.kind, 164 kind: match self.kind {
165 FileSymbolKind::Function => SymbolKind::Function,
166 FileSymbolKind::Struct => SymbolKind::Struct,
167 FileSymbolKind::Enum => SymbolKind::Enum,
168 FileSymbolKind::Trait => SymbolKind::Trait,
169 FileSymbolKind::Module => SymbolKind::Module,
170 FileSymbolKind::TypeAlias => SymbolKind::TypeAlias,
171 FileSymbolKind::Const => SymbolKind::Const,
172 FileSymbolKind::Static => SymbolKind::Static,
173 FileSymbolKind::Macro => SymbolKind::Macro,
174 },
146 full_range: self.range, 175 full_range: self.range,
147 focus_range: self.name_range, 176 focus_range: self.name_range,
148 container_name: self.container_name.clone(), 177 container_name: self.container_name.clone(),
@@ -191,16 +220,36 @@ impl TryToNav for hir::ModuleDef {
191 } 220 }
192} 221}
193 222
194pub(crate) trait ToNavFromAst {} 223pub(crate) trait ToNavFromAst {
195impl ToNavFromAst for hir::Function {} 224 const KIND: SymbolKind;
196impl ToNavFromAst for hir::Const {} 225}
197impl ToNavFromAst for hir::Static {} 226impl ToNavFromAst for hir::Function {
198impl ToNavFromAst for hir::Struct {} 227 const KIND: SymbolKind = SymbolKind::Function;
199impl ToNavFromAst for hir::Enum {} 228}
200impl ToNavFromAst for hir::EnumVariant {} 229impl ToNavFromAst for hir::Const {
201impl ToNavFromAst for hir::Union {} 230 const KIND: SymbolKind = SymbolKind::Const;
202impl ToNavFromAst for hir::TypeAlias {} 231}
203impl ToNavFromAst for hir::Trait {} 232impl ToNavFromAst for hir::Static {
233 const KIND: SymbolKind = SymbolKind::Static;
234}
235impl ToNavFromAst for hir::Struct {
236 const KIND: SymbolKind = SymbolKind::Struct;
237}
238impl ToNavFromAst for hir::Enum {
239 const KIND: SymbolKind = SymbolKind::Enum;
240}
241impl ToNavFromAst for hir::EnumVariant {
242 const KIND: SymbolKind = SymbolKind::Variant;
243}
244impl ToNavFromAst for hir::Union {
245 const KIND: SymbolKind = SymbolKind::Union;
246}
247impl ToNavFromAst for hir::TypeAlias {
248 const KIND: SymbolKind = SymbolKind::TypeAlias;
249}
250impl ToNavFromAst for hir::Trait {
251 const KIND: SymbolKind = SymbolKind::Trait;
252}
204 253
205impl<D> ToNav for D 254impl<D> ToNav for D
206where 255where
@@ -209,8 +258,11 @@ where
209{ 258{
210 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { 259 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
211 let src = self.source(db); 260 let src = self.source(db);
212 let mut res = 261 let mut res = NavigationTarget::from_named(
213 NavigationTarget::from_named(db, src.as_ref().map(|it| it as &dyn ast::NameOwner)); 262 db,
263 src.as_ref().map(|it| it as &dyn ast::NameOwner),
264 D::KIND,
265 );
214 res.docs = self.docs(db); 266 res.docs = self.docs(db);
215 res.description = src.value.short_label(); 267 res.description = src.value.short_label();
216 res 268 res
@@ -228,7 +280,7 @@ impl ToNav for hir::Module {
228 } 280 }
229 }; 281 };
230 let frange = src.with_value(syntax).original_file_range(db); 282 let frange = src.with_value(syntax).original_file_range(db);
231 NavigationTarget::from_syntax(frange.file_id, name, focus, frange.range, syntax.kind()) 283 NavigationTarget::from_syntax(frange.file_id, name, focus, frange.range, SymbolKind::Module)
232 } 284 }
233} 285}
234 286
@@ -252,7 +304,7 @@ impl ToNav for hir::Impl {
252 "impl".into(), 304 "impl".into(),
253 focus_range, 305 focus_range,
254 frange.range, 306 frange.range,
255 src.value.syntax().kind(), 307 SymbolKind::Impl,
256 ) 308 )
257 } 309 }
258} 310}
@@ -263,7 +315,8 @@ impl ToNav for hir::Field {
263 315
264 match &src.value { 316 match &src.value {
265 FieldSource::Named(it) => { 317 FieldSource::Named(it) => {
266 let mut res = NavigationTarget::from_named(db, src.with_value(it)); 318 let mut res =
319 NavigationTarget::from_named(db, src.with_value(it), SymbolKind::Field);
267 res.docs = self.docs(db); 320 res.docs = self.docs(db);
268 res.description = it.short_label(); 321 res.description = it.short_label();
269 res 322 res
@@ -275,7 +328,7 @@ impl ToNav for hir::Field {
275 "".into(), 328 "".into(),
276 None, 329 None,
277 frange.range, 330 frange.range,
278 it.syntax().kind(), 331 SymbolKind::Field,
279 ) 332 )
280 } 333 }
281 } 334 }
@@ -286,8 +339,11 @@ impl ToNav for hir::MacroDef {
286 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { 339 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
287 let src = self.source(db); 340 let src = self.source(db);
288 log::debug!("nav target {:#?}", src.value.syntax()); 341 log::debug!("nav target {:#?}", src.value.syntax());
289 let mut res = 342 let mut res = NavigationTarget::from_named(
290 NavigationTarget::from_named(db, src.as_ref().map(|it| it as &dyn ast::NameOwner)); 343 db,
344 src.as_ref().map(|it| it as &dyn ast::NameOwner),
345 SymbolKind::Macro,
346 );
291 res.docs = self.docs(db); 347 res.docs = self.docs(db);
292 res 348 res
293 } 349 }
@@ -330,7 +386,7 @@ impl ToNav for hir::Local {
330 NavigationTarget { 386 NavigationTarget {
331 file_id: full_range.file_id, 387 file_id: full_range.file_id,
332 name, 388 name,
333 kind: IDENT_PAT, 389 kind: SymbolKind::Local,
334 full_range: full_range.range, 390 full_range: full_range.range,
335 focus_range: None, 391 focus_range: None,
336 container_name: None, 392 container_name: None,
@@ -354,7 +410,7 @@ impl ToNav for hir::TypeParam {
354 NavigationTarget { 410 NavigationTarget {
355 file_id: src.file_id.original_file(db), 411 file_id: src.file_id.original_file(db),
356 name: self.name(db).to_string().into(), 412 name: self.name(db).to_string().into(),
357 kind: TYPE_PARAM, 413 kind: SymbolKind::TypeParam,
358 full_range, 414 full_range,
359 focus_range, 415 focus_range,
360 container_name: None, 416 container_name: None,
@@ -371,7 +427,7 @@ impl ToNav for hir::LifetimeParam {
371 NavigationTarget { 427 NavigationTarget {
372 file_id: src.file_id.original_file(db), 428 file_id: src.file_id.original_file(db),
373 name: self.name(db).to_string().into(), 429 name: self.name(db).to_string().into(),
374 kind: LIFETIME_PARAM, 430 kind: SymbolKind::LifetimeParam,
375 full_range, 431 full_range,
376 focus_range: Some(full_range), 432 focus_range: Some(full_range),
377 container_name: None, 433 container_name: None,
@@ -432,7 +488,7 @@ fn foo() { enum FooInner { } }
432 5..13, 488 5..13,
433 ), 489 ),
434 name: "FooInner", 490 name: "FooInner",
435 kind: ENUM, 491 kind: Enum,
436 container_name: None, 492 container_name: None,
437 description: Some( 493 description: Some(
438 "enum FooInner", 494 "enum FooInner",
@@ -448,7 +504,7 @@ fn foo() { enum FooInner { } }
448 34..42, 504 34..42,
449 ), 505 ),
450 name: "FooInner", 506 name: "FooInner",
451 kind: ENUM, 507 kind: Enum,
452 container_name: Some( 508 container_name: Some(
453 "foo", 509 "foo",
454 ), 510 ),
diff --git a/crates/ide/src/file_structure.rs b/crates/ide/src/file_structure.rs
index c51531391..32556dad3 100644
--- a/crates/ide/src/file_structure.rs
+++ b/crates/ide/src/file_structure.rs
@@ -1,15 +1,17 @@
1use syntax::{ 1use syntax::{
2 ast::{self, AttrsOwner, GenericParamsOwner, NameOwner}, 2 ast::{self, AttrsOwner, GenericParamsOwner, NameOwner},
3 match_ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, TextRange, WalkEvent, 3 match_ast, AstNode, SourceFile, SyntaxNode, TextRange, WalkEvent,
4}; 4};
5 5
6use crate::SymbolKind;
7
6#[derive(Debug, Clone)] 8#[derive(Debug, Clone)]
7pub struct StructureNode { 9pub struct StructureNode {
8 pub parent: Option<usize>, 10 pub parent: Option<usize>,
9 pub label: String, 11 pub label: String,
10 pub navigation_range: TextRange, 12 pub navigation_range: TextRange,
11 pub node_range: TextRange, 13 pub node_range: TextRange,
12 pub kind: SyntaxKind, 14 pub kind: SymbolKind,
13 pub detail: Option<String>, 15 pub detail: Option<String>,
14 pub deprecated: bool, 16 pub deprecated: bool,
15} 17}
@@ -51,25 +53,27 @@ pub(crate) fn file_structure(file: &SourceFile) -> Vec<StructureNode> {
51} 53}
52 54
53fn structure_node(node: &SyntaxNode) -> Option<StructureNode> { 55fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
54 fn decl<N: NameOwner + AttrsOwner>(node: N) -> Option<StructureNode> { 56 fn decl<N: NameOwner + AttrsOwner>(node: N, kind: SymbolKind) -> Option<StructureNode> {
55 decl_with_detail(&node, None) 57 decl_with_detail(&node, None, kind)
56 } 58 }
57 59
58 fn decl_with_type_ref<N: NameOwner + AttrsOwner>( 60 fn decl_with_type_ref<N: NameOwner + AttrsOwner>(
59 node: &N, 61 node: &N,
60 type_ref: Option<ast::Type>, 62 type_ref: Option<ast::Type>,
63 kind: SymbolKind,
61 ) -> Option<StructureNode> { 64 ) -> Option<StructureNode> {
62 let detail = type_ref.map(|type_ref| { 65 let detail = type_ref.map(|type_ref| {
63 let mut detail = String::new(); 66 let mut detail = String::new();
64 collapse_ws(type_ref.syntax(), &mut detail); 67 collapse_ws(type_ref.syntax(), &mut detail);
65 detail 68 detail
66 }); 69 });
67 decl_with_detail(node, detail) 70 decl_with_detail(node, detail, kind)
68 } 71 }
69 72
70 fn decl_with_detail<N: NameOwner + AttrsOwner>( 73 fn decl_with_detail<N: NameOwner + AttrsOwner>(
71 node: &N, 74 node: &N,
72 detail: Option<String>, 75 detail: Option<String>,
76 kind: SymbolKind,
73 ) -> Option<StructureNode> { 77 ) -> Option<StructureNode> {
74 let name = node.name()?; 78 let name = node.name()?;
75 79
@@ -78,7 +82,7 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
78 label: name.text().to_string(), 82 label: name.text().to_string(),
79 navigation_range: name.syntax().text_range(), 83 navigation_range: name.syntax().text_range(),
80 node_range: node.syntax().text_range(), 84 node_range: node.syntax().text_range(),
81 kind: node.syntax().kind(), 85 kind,
82 detail, 86 detail,
83 deprecated: node.attrs().filter_map(|x| x.simple_name()).any(|x| x == "deprecated"), 87 deprecated: node.attrs().filter_map(|x| x.simple_name()).any(|x| x == "deprecated"),
84 }) 88 })
@@ -117,18 +121,18 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
117 collapse_ws(ret_type.syntax(), &mut detail); 121 collapse_ws(ret_type.syntax(), &mut detail);
118 } 122 }
119 123
120 decl_with_detail(&it, Some(detail)) 124 decl_with_detail(&it, Some(detail), SymbolKind::Function)
121 }, 125 },
122 ast::Struct(it) => decl(it), 126 ast::Struct(it) => decl(it, SymbolKind::Struct),
123 ast::Union(it) => decl(it), 127 ast::Union(it) => decl(it, SymbolKind::Union),
124 ast::Enum(it) => decl(it), 128 ast::Enum(it) => decl(it, SymbolKind::Enum),
125 ast::Variant(it) => decl(it), 129 ast::Variant(it) => decl(it, SymbolKind::Variant),
126 ast::Trait(it) => decl(it), 130 ast::Trait(it) => decl(it, SymbolKind::Trait),
127 ast::Module(it) => decl(it), 131 ast::Module(it) => decl(it, SymbolKind::Module),
128 ast::TypeAlias(it) => decl_with_type_ref(&it, it.ty()), 132 ast::TypeAlias(it) => decl_with_type_ref(&it, it.ty(), SymbolKind::TypeAlias),
129 ast::RecordField(it) => decl_with_type_ref(&it, it.ty()), 133 ast::RecordField(it) => decl_with_type_ref(&it, it.ty(), SymbolKind::Field),
130 ast::Const(it) => decl_with_type_ref(&it, it.ty()), 134 ast::Const(it) => decl_with_type_ref(&it, it.ty(), SymbolKind::Const),
131 ast::Static(it) => decl_with_type_ref(&it, it.ty()), 135 ast::Static(it) => decl_with_type_ref(&it, it.ty(), SymbolKind::Static),
132 ast::Impl(it) => { 136 ast::Impl(it) => {
133 let target_type = it.self_ty()?; 137 let target_type = it.self_ty()?;
134 let target_trait = it.trait_(); 138 let target_trait = it.trait_();
@@ -144,13 +148,13 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
144 label, 148 label,
145 navigation_range: target_type.syntax().text_range(), 149 navigation_range: target_type.syntax().text_range(),
146 node_range: it.syntax().text_range(), 150 node_range: it.syntax().text_range(),
147 kind: it.syntax().kind(), 151 kind: SymbolKind::Impl,
148 detail: None, 152 detail: None,
149 deprecated: false, 153 deprecated: false,
150 }; 154 };
151 Some(node) 155 Some(node)
152 }, 156 },
153 ast::MacroRules(it) => decl(it), 157 ast::MacroRules(it) => decl(it, SymbolKind::Macro),
154 _ => None, 158 _ => None,
155 } 159 }
156 } 160 }
@@ -222,7 +226,7 @@ fn very_obsolete() {}
222 label: "Foo", 226 label: "Foo",
223 navigation_range: 8..11, 227 navigation_range: 8..11,
224 node_range: 1..26, 228 node_range: 1..26,
225 kind: STRUCT, 229 kind: Struct,
226 detail: None, 230 detail: None,
227 deprecated: false, 231 deprecated: false,
228 }, 232 },
@@ -233,7 +237,7 @@ fn very_obsolete() {}
233 label: "x", 237 label: "x",
234 navigation_range: 18..19, 238 navigation_range: 18..19,
235 node_range: 18..24, 239 node_range: 18..24,
236 kind: RECORD_FIELD, 240 kind: Field,
237 detail: Some( 241 detail: Some(
238 "i32", 242 "i32",
239 ), 243 ),
@@ -244,7 +248,7 @@ fn very_obsolete() {}
244 label: "m", 248 label: "m",
245 navigation_range: 32..33, 249 navigation_range: 32..33,
246 node_range: 28..158, 250 node_range: 28..158,
247 kind: MODULE, 251 kind: Module,
248 detail: None, 252 detail: None,
249 deprecated: false, 253 deprecated: false,
250 }, 254 },
@@ -255,7 +259,7 @@ fn very_obsolete() {}
255 label: "bar1", 259 label: "bar1",
256 navigation_range: 43..47, 260 navigation_range: 43..47,
257 node_range: 40..52, 261 node_range: 40..52,
258 kind: FN, 262 kind: Function,
259 detail: Some( 263 detail: Some(
260 "fn()", 264 "fn()",
261 ), 265 ),
@@ -268,7 +272,7 @@ fn very_obsolete() {}
268 label: "bar2", 272 label: "bar2",
269 navigation_range: 60..64, 273 navigation_range: 60..64,
270 node_range: 57..81, 274 node_range: 57..81,
271 kind: FN, 275 kind: Function,
272 detail: Some( 276 detail: Some(
273 "fn<T>(t: T) -> T", 277 "fn<T>(t: T) -> T",
274 ), 278 ),
@@ -281,7 +285,7 @@ fn very_obsolete() {}
281 label: "bar3", 285 label: "bar3",
282 navigation_range: 89..93, 286 navigation_range: 89..93,
283 node_range: 86..156, 287 node_range: 86..156,
284 kind: FN, 288 kind: Function,
285 detail: Some( 289 detail: Some(
286 "fn<A, B>(a: A, b: B) -> Vec< u32 >", 290 "fn<A, B>(a: A, b: B) -> Vec< u32 >",
287 ), 291 ),
@@ -292,7 +296,7 @@ fn very_obsolete() {}
292 label: "E", 296 label: "E",
293 navigation_range: 165..166, 297 navigation_range: 165..166,
294 node_range: 160..180, 298 node_range: 160..180,
295 kind: ENUM, 299 kind: Enum,
296 detail: None, 300 detail: None,
297 deprecated: false, 301 deprecated: false,
298 }, 302 },
@@ -303,7 +307,7 @@ fn very_obsolete() {}
303 label: "X", 307 label: "X",
304 navigation_range: 169..170, 308 navigation_range: 169..170,
305 node_range: 169..170, 309 node_range: 169..170,
306 kind: VARIANT, 310 kind: Variant,
307 detail: None, 311 detail: None,
308 deprecated: false, 312 deprecated: false,
309 }, 313 },
@@ -314,7 +318,7 @@ fn very_obsolete() {}
314 label: "Y", 318 label: "Y",
315 navigation_range: 172..173, 319 navigation_range: 172..173,
316 node_range: 172..178, 320 node_range: 172..178,
317 kind: VARIANT, 321 kind: Variant,
318 detail: None, 322 detail: None,
319 deprecated: false, 323 deprecated: false,
320 }, 324 },
@@ -323,7 +327,7 @@ fn very_obsolete() {}
323 label: "T", 327 label: "T",
324 navigation_range: 186..187, 328 navigation_range: 186..187,
325 node_range: 181..193, 329 node_range: 181..193,
326 kind: TYPE_ALIAS, 330 kind: TypeAlias,
327 detail: Some( 331 detail: Some(
328 "()", 332 "()",
329 ), 333 ),
@@ -334,7 +338,7 @@ fn very_obsolete() {}
334 label: "S", 338 label: "S",
335 navigation_range: 201..202, 339 navigation_range: 201..202,
336 node_range: 194..213, 340 node_range: 194..213,
337 kind: STATIC, 341 kind: Static,
338 detail: Some( 342 detail: Some(
339 "i32", 343 "i32",
340 ), 344 ),
@@ -345,7 +349,7 @@ fn very_obsolete() {}
345 label: "C", 349 label: "C",
346 navigation_range: 220..221, 350 navigation_range: 220..221,
347 node_range: 214..232, 351 node_range: 214..232,
348 kind: CONST, 352 kind: Const,
349 detail: Some( 353 detail: Some(
350 "i32", 354 "i32",
351 ), 355 ),
@@ -356,7 +360,7 @@ fn very_obsolete() {}
356 label: "impl E", 360 label: "impl E",
357 navigation_range: 239..240, 361 navigation_range: 239..240,
358 node_range: 234..243, 362 node_range: 234..243,
359 kind: IMPL, 363 kind: Impl,
360 detail: None, 364 detail: None,
361 deprecated: false, 365 deprecated: false,
362 }, 366 },
@@ -365,7 +369,7 @@ fn very_obsolete() {}
365 label: "impl fmt::Debug for E", 369 label: "impl fmt::Debug for E",
366 navigation_range: 265..266, 370 navigation_range: 265..266,
367 node_range: 245..269, 371 node_range: 245..269,
368 kind: IMPL, 372 kind: Impl,
369 detail: None, 373 detail: None,
370 deprecated: false, 374 deprecated: false,
371 }, 375 },
@@ -374,7 +378,7 @@ fn very_obsolete() {}
374 label: "mc", 378 label: "mc",
375 navigation_range: 284..286, 379 navigation_range: 284..286,
376 node_range: 271..303, 380 node_range: 271..303,
377 kind: MACRO_RULES, 381 kind: Macro,
378 detail: None, 382 detail: None,
379 deprecated: false, 383 deprecated: false,
380 }, 384 },
@@ -383,7 +387,7 @@ fn very_obsolete() {}
383 label: "mcexp", 387 label: "mcexp",
384 navigation_range: 334..339, 388 navigation_range: 334..339,
385 node_range: 305..356, 389 node_range: 305..356,
386 kind: MACRO_RULES, 390 kind: Macro,
387 detail: None, 391 detail: None,
388 deprecated: false, 392 deprecated: false,
389 }, 393 },
@@ -392,7 +396,7 @@ fn very_obsolete() {}
392 label: "mcexp", 396 label: "mcexp",
393 navigation_range: 387..392, 397 navigation_range: 387..392,
394 node_range: 358..409, 398 node_range: 358..409,
395 kind: MACRO_RULES, 399 kind: Macro,
396 detail: None, 400 detail: None,
397 deprecated: false, 401 deprecated: false,
398 }, 402 },
@@ -401,7 +405,7 @@ fn very_obsolete() {}
401 label: "obsolete", 405 label: "obsolete",
402 navigation_range: 428..436, 406 navigation_range: 428..436,
403 node_range: 411..441, 407 node_range: 411..441,
404 kind: FN, 408 kind: Function,
405 detail: Some( 409 detail: Some(
406 "fn()", 410 "fn()",
407 ), 411 ),
@@ -412,7 +416,7 @@ fn very_obsolete() {}
412 label: "very_obsolete", 416 label: "very_obsolete",
413 navigation_range: 481..494, 417 navigation_range: 481..494,
414 node_range: 443..499, 418 node_range: 443..499,
415 kind: FN, 419 kind: Function,
416 detail: Some( 420 detail: Some(
417 "fn()", 421 "fn()",
418 ), 422 ),
diff --git a/crates/ide/src/goto_definition.rs b/crates/ide/src/goto_definition.rs
index 173509b08..5bee69f4b 100644
--- a/crates/ide/src/goto_definition.rs
+++ b/crates/ide/src/goto_definition.rs
@@ -9,7 +9,7 @@ use syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxToken, TokenAtOffset,
9 9
10use crate::{ 10use crate::{
11 display::{ToNav, TryToNav}, 11 display::{ToNav, TryToNav},
12 FilePosition, NavigationTarget, RangeInfo, 12 FilePosition, NavigationTarget, RangeInfo, SymbolKind,
13}; 13};
14 14
15// Feature: Go to Definition 15// Feature: Go to Definition
@@ -86,7 +86,7 @@ fn self_to_nav_target(self_param: ast::SelfParam, file_id: FileId) -> Option<Nav
86 full_range: self_param.syntax().text_range(), 86 full_range: self_param.syntax().text_range(),
87 focus_range: Some(self_token.text_range()), 87 focus_range: Some(self_token.text_range()),
88 name: self_token.text().clone(), 88 name: self_token.text().clone(),
89 kind: self_token.kind(), 89 kind: SymbolKind::SelfParam,
90 container_name: None, 90 container_name: None,
91 description: None, 91 description: None,
92 docs: None, 92 docs: None,
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs
index da6bb726a..dca098af6 100644
--- a/crates/ide/src/hover.rs
+++ b/crates/ide/src/hover.rs
@@ -2191,7 +2191,7 @@ fn foo_<|>test() {}
2191 11..19, 2191 11..19,
2192 ), 2192 ),
2193 name: "foo_test", 2193 name: "foo_test",
2194 kind: FN, 2194 kind: Function,
2195 container_name: None, 2195 container_name: None,
2196 description: None, 2196 description: None,
2197 docs: None, 2197 docs: None,
@@ -2234,7 +2234,7 @@ mod tests<|> {
2234 4..9, 2234 4..9,
2235 ), 2235 ),
2236 name: "tests", 2236 name: "tests",
2237 kind: MODULE, 2237 kind: Module,
2238 container_name: None, 2238 container_name: None,
2239 description: None, 2239 description: None,
2240 docs: None, 2240 docs: None,
@@ -2273,7 +2273,7 @@ fn main() { let s<|>t = S{ f1:0 }; }
2273 7..8, 2273 7..8,
2274 ), 2274 ),
2275 name: "S", 2275 name: "S",
2276 kind: STRUCT, 2276 kind: Struct,
2277 container_name: None, 2277 container_name: None,
2278 description: Some( 2278 description: Some(
2279 "struct S", 2279 "struct S",
@@ -2312,7 +2312,7 @@ fn main() { let s<|>t = S{ f1:Arg(0) }; }
2312 24..25, 2312 24..25,
2313 ), 2313 ),
2314 name: "S", 2314 name: "S",
2315 kind: STRUCT, 2315 kind: Struct,
2316 container_name: None, 2316 container_name: None,
2317 description: Some( 2317 description: Some(
2318 "struct S", 2318 "struct S",
@@ -2331,7 +2331,7 @@ fn main() { let s<|>t = S{ f1:Arg(0) }; }
2331 7..10, 2331 7..10,
2332 ), 2332 ),
2333 name: "Arg", 2333 name: "Arg",
2334 kind: STRUCT, 2334 kind: Struct,
2335 container_name: None, 2335 container_name: None,
2336 description: Some( 2336 description: Some(
2337 "struct Arg", 2337 "struct Arg",
@@ -2370,7 +2370,7 @@ fn main() { let s<|>t = S{ f1: S{ f1: Arg(0) } }; }
2370 24..25, 2370 24..25,
2371 ), 2371 ),
2372 name: "S", 2372 name: "S",
2373 kind: STRUCT, 2373 kind: Struct,
2374 container_name: None, 2374 container_name: None,
2375 description: Some( 2375 description: Some(
2376 "struct S", 2376 "struct S",
@@ -2389,7 +2389,7 @@ fn main() { let s<|>t = S{ f1: S{ f1: Arg(0) } }; }
2389 7..10, 2389 7..10,
2390 ), 2390 ),
2391 name: "Arg", 2391 name: "Arg",
2392 kind: STRUCT, 2392 kind: Struct,
2393 container_name: None, 2393 container_name: None,
2394 description: Some( 2394 description: Some(
2395 "struct Arg", 2395 "struct Arg",
@@ -2431,7 +2431,7 @@ fn main() { let s<|>t = (A(1), B(2), M::C(3) ); }
2431 7..8, 2431 7..8,
2432 ), 2432 ),
2433 name: "A", 2433 name: "A",
2434 kind: STRUCT, 2434 kind: Struct,
2435 container_name: None, 2435 container_name: None,
2436 description: Some( 2436 description: Some(
2437 "struct A", 2437 "struct A",
@@ -2450,7 +2450,7 @@ fn main() { let s<|>t = (A(1), B(2), M::C(3) ); }
2450 22..23, 2450 22..23,
2451 ), 2451 ),
2452 name: "B", 2452 name: "B",
2453 kind: STRUCT, 2453 kind: Struct,
2454 container_name: None, 2454 container_name: None,
2455 description: Some( 2455 description: Some(
2456 "struct B", 2456 "struct B",
@@ -2469,7 +2469,7 @@ fn main() { let s<|>t = (A(1), B(2), M::C(3) ); }
2469 53..54, 2469 53..54,
2470 ), 2470 ),
2471 name: "C", 2471 name: "C",
2472 kind: STRUCT, 2472 kind: Struct,
2473 container_name: None, 2473 container_name: None,
2474 description: Some( 2474 description: Some(
2475 "pub struct C", 2475 "pub struct C",
@@ -2508,7 +2508,7 @@ fn main() { let s<|>t = foo(); }
2508 6..9, 2508 6..9,
2509 ), 2509 ),
2510 name: "Foo", 2510 name: "Foo",
2511 kind: TRAIT, 2511 kind: Trait,
2512 container_name: None, 2512 container_name: None,
2513 description: Some( 2513 description: Some(
2514 "trait Foo", 2514 "trait Foo",
@@ -2548,7 +2548,7 @@ fn main() { let s<|>t = foo(); }
2548 6..9, 2548 6..9,
2549 ), 2549 ),
2550 name: "Foo", 2550 name: "Foo",
2551 kind: TRAIT, 2551 kind: Trait,
2552 container_name: None, 2552 container_name: None,
2553 description: Some( 2553 description: Some(
2554 "trait Foo", 2554 "trait Foo",
@@ -2567,7 +2567,7 @@ fn main() { let s<|>t = foo(); }
2567 23..24, 2567 23..24,
2568 ), 2568 ),
2569 name: "S", 2569 name: "S",
2570 kind: STRUCT, 2570 kind: Struct,
2571 container_name: None, 2571 container_name: None,
2572 description: Some( 2572 description: Some(
2573 "struct S", 2573 "struct S",
@@ -2607,7 +2607,7 @@ fn main() { let s<|>t = foo(); }
2607 6..9, 2607 6..9,
2608 ), 2608 ),
2609 name: "Foo", 2609 name: "Foo",
2610 kind: TRAIT, 2610 kind: Trait,
2611 container_name: None, 2611 container_name: None,
2612 description: Some( 2612 description: Some(
2613 "trait Foo", 2613 "trait Foo",
@@ -2626,7 +2626,7 @@ fn main() { let s<|>t = foo(); }
2626 19..22, 2626 19..22,
2627 ), 2627 ),
2628 name: "Bar", 2628 name: "Bar",
2629 kind: TRAIT, 2629 kind: Trait,
2630 container_name: None, 2630 container_name: None,
2631 description: Some( 2631 description: Some(
2632 "trait Bar", 2632 "trait Bar",
@@ -2669,7 +2669,7 @@ fn main() { let s<|>t = foo(); }
2669 6..9, 2669 6..9,
2670 ), 2670 ),
2671 name: "Foo", 2671 name: "Foo",
2672 kind: TRAIT, 2672 kind: Trait,
2673 container_name: None, 2673 container_name: None,
2674 description: Some( 2674 description: Some(
2675 "trait Foo", 2675 "trait Foo",
@@ -2688,7 +2688,7 @@ fn main() { let s<|>t = foo(); }
2688 22..25, 2688 22..25,
2689 ), 2689 ),
2690 name: "Bar", 2690 name: "Bar",
2691 kind: TRAIT, 2691 kind: Trait,
2692 container_name: None, 2692 container_name: None,
2693 description: Some( 2693 description: Some(
2694 "trait Bar", 2694 "trait Bar",
@@ -2707,7 +2707,7 @@ fn main() { let s<|>t = foo(); }
2707 39..41, 2707 39..41,
2708 ), 2708 ),
2709 name: "S1", 2709 name: "S1",
2710 kind: STRUCT, 2710 kind: Struct,
2711 container_name: None, 2711 container_name: None,
2712 description: Some( 2712 description: Some(
2713 "struct S1", 2713 "struct S1",
@@ -2726,7 +2726,7 @@ fn main() { let s<|>t = foo(); }
2726 52..54, 2726 52..54,
2727 ), 2727 ),
2728 name: "S2", 2728 name: "S2",
2729 kind: STRUCT, 2729 kind: Struct,
2730 container_name: None, 2730 container_name: None,
2731 description: Some( 2731 description: Some(
2732 "struct S2", 2732 "struct S2",
@@ -2763,7 +2763,7 @@ fn foo(ar<|>g: &impl Foo) {}
2763 6..9, 2763 6..9,
2764 ), 2764 ),
2765 name: "Foo", 2765 name: "Foo",
2766 kind: TRAIT, 2766 kind: Trait,
2767 container_name: None, 2767 container_name: None,
2768 description: Some( 2768 description: Some(
2769 "trait Foo", 2769 "trait Foo",
@@ -2803,7 +2803,7 @@ fn foo(ar<|>g: &impl Foo + Bar<S>) {}
2803 6..9, 2803 6..9,
2804 ), 2804 ),
2805 name: "Foo", 2805 name: "Foo",
2806 kind: TRAIT, 2806 kind: Trait,
2807 container_name: None, 2807 container_name: None,
2808 description: Some( 2808 description: Some(
2809 "trait Foo", 2809 "trait Foo",
@@ -2822,7 +2822,7 @@ fn foo(ar<|>g: &impl Foo + Bar<S>) {}
2822 19..22, 2822 19..22,
2823 ), 2823 ),
2824 name: "Bar", 2824 name: "Bar",
2825 kind: TRAIT, 2825 kind: Trait,
2826 container_name: None, 2826 container_name: None,
2827 description: Some( 2827 description: Some(
2828 "trait Bar", 2828 "trait Bar",
@@ -2841,7 +2841,7 @@ fn foo(ar<|>g: &impl Foo + Bar<S>) {}
2841 36..37, 2841 36..37,
2842 ), 2842 ),
2843 name: "S", 2843 name: "S",
2844 kind: STRUCT, 2844 kind: Struct,
2845 container_name: None, 2845 container_name: None,
2846 description: Some( 2846 description: Some(
2847 "struct S", 2847 "struct S",
@@ -2886,7 +2886,7 @@ mod future {
2886 140..146, 2886 140..146,
2887 ), 2887 ),
2888 name: "Future", 2888 name: "Future",
2889 kind: TRAIT, 2889 kind: Trait,
2890 container_name: None, 2890 container_name: None,
2891 description: Some( 2891 description: Some(
2892 "pub trait Future", 2892 "pub trait Future",
@@ -2905,7 +2905,7 @@ mod future {
2905 7..8, 2905 7..8,
2906 ), 2906 ),
2907 name: "S", 2907 name: "S",
2908 kind: STRUCT, 2908 kind: Struct,
2909 container_name: None, 2909 container_name: None,
2910 description: Some( 2910 description: Some(
2911 "struct S", 2911 "struct S",
@@ -2943,7 +2943,7 @@ fn foo(ar<|>g: &impl Foo<S>) {}
2943 6..9, 2943 6..9,
2944 ), 2944 ),
2945 name: "Foo", 2945 name: "Foo",
2946 kind: TRAIT, 2946 kind: Trait,
2947 container_name: None, 2947 container_name: None,
2948 description: Some( 2948 description: Some(
2949 "trait Foo", 2949 "trait Foo",
@@ -2962,7 +2962,7 @@ fn foo(ar<|>g: &impl Foo<S>) {}
2962 23..24, 2962 23..24,
2963 ), 2963 ),
2964 name: "S", 2964 name: "S",
2965 kind: STRUCT, 2965 kind: Struct,
2966 container_name: None, 2966 container_name: None,
2967 description: Some( 2967 description: Some(
2968 "struct S", 2968 "struct S",
@@ -3005,7 +3005,7 @@ fn main() { let s<|>t = foo(); }
3005 49..50, 3005 49..50,
3006 ), 3006 ),
3007 name: "B", 3007 name: "B",
3008 kind: STRUCT, 3008 kind: Struct,
3009 container_name: None, 3009 container_name: None,
3010 description: Some( 3010 description: Some(
3011 "struct B", 3011 "struct B",
@@ -3024,7 +3024,7 @@ fn main() { let s<|>t = foo(); }
3024 6..9, 3024 6..9,
3025 ), 3025 ),
3026 name: "Foo", 3026 name: "Foo",
3027 kind: TRAIT, 3027 kind: Trait,
3028 container_name: None, 3028 container_name: None,
3029 description: Some( 3029 description: Some(
3030 "trait Foo", 3030 "trait Foo",
@@ -3061,7 +3061,7 @@ fn foo(ar<|>g: &dyn Foo) {}
3061 6..9, 3061 6..9,
3062 ), 3062 ),
3063 name: "Foo", 3063 name: "Foo",
3064 kind: TRAIT, 3064 kind: Trait,
3065 container_name: None, 3065 container_name: None,
3066 description: Some( 3066 description: Some(
3067 "trait Foo", 3067 "trait Foo",
@@ -3099,7 +3099,7 @@ fn foo(ar<|>g: &dyn Foo<S>) {}
3099 6..9, 3099 6..9,
3100 ), 3100 ),
3101 name: "Foo", 3101 name: "Foo",
3102 kind: TRAIT, 3102 kind: Trait,
3103 container_name: None, 3103 container_name: None,
3104 description: Some( 3104 description: Some(
3105 "trait Foo", 3105 "trait Foo",
@@ -3118,7 +3118,7 @@ fn foo(ar<|>g: &dyn Foo<S>) {}
3118 23..24, 3118 23..24,
3119 ), 3119 ),
3120 name: "S", 3120 name: "S",
3121 kind: STRUCT, 3121 kind: Struct,
3122 container_name: None, 3122 container_name: None,
3123 description: Some( 3123 description: Some(
3124 "struct S", 3124 "struct S",
@@ -3159,7 +3159,7 @@ fn foo(a<|>rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
3159 6..15, 3159 6..15,
3160 ), 3160 ),
3161 name: "ImplTrait", 3161 name: "ImplTrait",
3162 kind: TRAIT, 3162 kind: Trait,
3163 container_name: None, 3163 container_name: None,
3164 description: Some( 3164 description: Some(
3165 "trait ImplTrait", 3165 "trait ImplTrait",
@@ -3178,7 +3178,7 @@ fn foo(a<|>rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
3178 50..51, 3178 50..51,
3179 ), 3179 ),
3180 name: "B", 3180 name: "B",
3181 kind: STRUCT, 3181 kind: Struct,
3182 container_name: None, 3182 container_name: None,
3183 description: Some( 3183 description: Some(
3184 "struct B", 3184 "struct B",
@@ -3197,7 +3197,7 @@ fn foo(a<|>rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
3197 28..36, 3197 28..36,
3198 ), 3198 ),
3199 name: "DynTrait", 3199 name: "DynTrait",
3200 kind: TRAIT, 3200 kind: Trait,
3201 container_name: None, 3201 container_name: None,
3202 description: Some( 3202 description: Some(
3203 "trait DynTrait", 3203 "trait DynTrait",
@@ -3216,7 +3216,7 @@ fn foo(a<|>rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
3216 65..66, 3216 65..66,
3217 ), 3217 ),
3218 name: "S", 3218 name: "S",
3219 kind: STRUCT, 3219 kind: Struct,
3220 container_name: None, 3220 container_name: None,
3221 description: Some( 3221 description: Some(
3222 "struct S", 3222 "struct S",
@@ -3264,7 +3264,7 @@ fn main() { let s<|>t = test().get(); }
3264 6..9, 3264 6..9,
3265 ), 3265 ),
3266 name: "Foo", 3266 name: "Foo",
3267 kind: TRAIT, 3267 kind: Trait,
3268 container_name: None, 3268 container_name: None,
3269 description: Some( 3269 description: Some(
3270 "trait Foo", 3270 "trait Foo",
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs
index 4b245c040..dbad9a84f 100644
--- a/crates/ide/src/lib.rs
+++ b/crates/ide/src/lib.rs
@@ -64,7 +64,7 @@ use crate::display::ToNav;
64pub use crate::{ 64pub use crate::{
65 call_hierarchy::CallItem, 65 call_hierarchy::CallItem,
66 diagnostics::{Diagnostic, DiagnosticsConfig, Fix, Severity}, 66 diagnostics::{Diagnostic, DiagnosticsConfig, Fix, Severity},
67 display::NavigationTarget, 67 display::navigation_target::{NavigationTarget, SymbolKind},
68 expand_macro::ExpandedMacro, 68 expand_macro::ExpandedMacro,
69 file_structure::StructureNode, 69 file_structure::StructureNode,
70 folding_ranges::{Fold, FoldKind}, 70 folding_ranges::{Fold, FoldKind},
diff --git a/crates/ide/src/parent_module.rs b/crates/ide/src/parent_module.rs
index 6cc3b2991..be344a09b 100644
--- a/crates/ide/src/parent_module.rs
+++ b/crates/ide/src/parent_module.rs
@@ -78,7 +78,7 @@ mod tests {
78 ", 78 ",
79 ); 79 );
80 let nav = analysis.parent_module(pos).unwrap().pop().unwrap(); 80 let nav = analysis.parent_module(pos).unwrap().pop().unwrap();
81 nav.assert_match("foo MODULE FileId(0) 0..8"); 81 nav.assert_match("foo Module FileId(0) 0..8");
82 } 82 }
83 83
84 #[test] 84 #[test]
@@ -97,7 +97,7 @@ mod tests {
97 ", 97 ",
98 ); 98 );
99 let nav = analysis.parent_module(pos).unwrap().pop().unwrap(); 99 let nav = analysis.parent_module(pos).unwrap().pop().unwrap();
100 nav.assert_match("foo MODULE FileId(0) 0..8"); 100 nav.assert_match("foo Module FileId(0) 0..8");
101 } 101 }
102 102
103 #[test] 103 #[test]
@@ -113,7 +113,7 @@ mod tests {
113 ", 113 ",
114 ); 114 );
115 let nav = analysis.parent_module(pos).unwrap().pop().unwrap(); 115 let nav = analysis.parent_module(pos).unwrap().pop().unwrap();
116 nav.assert_match("baz MODULE FileId(0) 32..44"); 116 nav.assert_match("baz Module FileId(0) 32..44");
117 } 117 }
118 118
119 #[test] 119 #[test]
diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs
index 98190a86b..d8069eb64 100644
--- a/crates/ide/src/references.rs
+++ b/crates/ide/src/references.rs
@@ -24,7 +24,7 @@ use syntax::{
24 match_ast, AstNode, SyntaxKind, SyntaxNode, TextRange, TokenAtOffset, 24 match_ast, AstNode, SyntaxKind, SyntaxNode, TextRange, TokenAtOffset,
25}; 25};
26 26
27use crate::{display::TryToNav, FilePosition, FileRange, NavigationTarget, RangeInfo}; 27use crate::{display::TryToNav, FilePosition, FileRange, NavigationTarget, RangeInfo, SymbolKind};
28 28
29#[derive(Debug, Clone)] 29#[derive(Debug, Clone)]
30pub struct ReferenceSearchResult { 30pub struct ReferenceSearchResult {
@@ -278,7 +278,7 @@ fn try_find_self_references(
278 full_range: self_param.syntax().text_range(), 278 full_range: self_param.syntax().text_range(),
279 focus_range: Some(param_self_token.text_range()), 279 focus_range: Some(param_self_token.text_range()),
280 name: param_self_token.text().clone(), 280 name: param_self_token.text().clone(),
281 kind: param_self_token.kind(), 281 kind: SymbolKind::SelfParam,
282 container_name: None, 282 container_name: None,
283 description: None, 283 description: None,
284 docs: None, 284 docs: None,
@@ -343,7 +343,7 @@ fn main() {
343} 343}
344"#, 344"#,
345 expect![[r#" 345 expect![[r#"
346 Foo STRUCT FileId(0) 0..26 7..10 Other 346 Foo Struct FileId(0) 0..26 7..10 Other
347 347
348 FileId(0) 101..104 StructLiteral 348 FileId(0) 101..104 StructLiteral
349 "#]], 349 "#]],
@@ -361,7 +361,7 @@ struct Foo<|> {}
361} 361}
362"#, 362"#,
363 expect![[r#" 363 expect![[r#"
364 Foo STRUCT FileId(0) 0..13 7..10 Other 364 Foo Struct FileId(0) 0..13 7..10 Other
365 365
366 FileId(0) 41..44 Other 366 FileId(0) 41..44 Other
367 FileId(0) 54..57 StructLiteral 367 FileId(0) 54..57 StructLiteral
@@ -380,7 +380,7 @@ struct Foo<T> <|>{}
380} 380}
381"#, 381"#,
382 expect![[r#" 382 expect![[r#"
383 Foo STRUCT FileId(0) 0..16 7..10 Other 383 Foo Struct FileId(0) 0..16 7..10 Other
384 384
385 FileId(0) 64..67 StructLiteral 385 FileId(0) 64..67 StructLiteral
386 "#]], 386 "#]],
@@ -399,7 +399,7 @@ fn main() {
399} 399}
400"#, 400"#,
401 expect![[r#" 401 expect![[r#"
402 Foo STRUCT FileId(0) 0..16 7..10 Other 402 Foo Struct FileId(0) 0..16 7..10 Other
403 403
404 FileId(0) 54..57 StructLiteral 404 FileId(0) 54..57 StructLiteral
405 "#]], 405 "#]],
@@ -420,7 +420,7 @@ fn main() {
420} 420}
421"#, 421"#,
422 expect![[r#" 422 expect![[r#"
423 Foo ENUM FileId(0) 0..26 5..8 Other 423 Foo Enum FileId(0) 0..26 5..8 Other
424 424
425 FileId(0) 63..66 EnumLiteral 425 FileId(0) 63..66 EnumLiteral
426 "#]], 426 "#]],
@@ -441,7 +441,7 @@ fn main() {
441} 441}
442"#, 442"#,
443 expect![[r#" 443 expect![[r#"
444 Foo ENUM FileId(0) 0..26 5..8 Other 444 Foo Enum FileId(0) 0..26 5..8 Other
445 445
446 FileId(0) 50..53 Other 446 FileId(0) 50..53 Other
447 FileId(0) 63..66 EnumLiteral 447 FileId(0) 63..66 EnumLiteral
@@ -463,7 +463,7 @@ fn main() {
463} 463}
464"#, 464"#,
465 expect![[r#" 465 expect![[r#"
466 Foo ENUM FileId(0) 0..32 5..8 Other 466 Foo Enum FileId(0) 0..32 5..8 Other
467 467
468 FileId(0) 73..76 EnumLiteral 468 FileId(0) 73..76 EnumLiteral
469 "#]], 469 "#]],
@@ -484,7 +484,7 @@ fn main() {
484} 484}
485"#, 485"#,
486 expect![[r#" 486 expect![[r#"
487 Foo ENUM FileId(0) 0..33 5..8 Other 487 Foo Enum FileId(0) 0..33 5..8 Other
488 488
489 FileId(0) 70..73 EnumLiteral 489 FileId(0) 70..73 EnumLiteral
490 "#]], 490 "#]],
@@ -507,7 +507,7 @@ fn main() {
507 i = 5; 507 i = 5;
508}"#, 508}"#,
509 expect![[r#" 509 expect![[r#"
510 i IDENT_PAT FileId(0) 24..25 Other Write 510 i Local FileId(0) 24..25 Other Write
511 511
512 FileId(0) 50..51 Other Write 512 FileId(0) 50..51 Other Write
513 FileId(0) 54..55 Other Read 513 FileId(0) 54..55 Other Read
@@ -531,7 +531,7 @@ fn bar() {
531} 531}
532"#, 532"#,
533 expect![[r#" 533 expect![[r#"
534 spam IDENT_PAT FileId(0) 19..23 Other 534 spam Local FileId(0) 19..23 Other
535 535
536 FileId(0) 34..38 Other Read 536 FileId(0) 34..38 Other Read
537 FileId(0) 41..45 Other Read 537 FileId(0) 41..45 Other Read
@@ -546,7 +546,7 @@ fn bar() {
546fn foo(i : u32) -> u32 { i<|> } 546fn foo(i : u32) -> u32 { i<|> }
547"#, 547"#,
548 expect![[r#" 548 expect![[r#"
549 i IDENT_PAT FileId(0) 7..8 Other 549 i Local FileId(0) 7..8 Other
550 550
551 FileId(0) 25..26 Other Read 551 FileId(0) 25..26 Other Read
552 "#]], 552 "#]],
@@ -560,7 +560,7 @@ fn foo(i : u32) -> u32 { i<|> }
560fn foo(i<|> : u32) -> u32 { i } 560fn foo(i<|> : u32) -> u32 { i }
561"#, 561"#,
562 expect![[r#" 562 expect![[r#"
563 i IDENT_PAT FileId(0) 7..8 Other 563 i Local FileId(0) 7..8 Other
564 564
565 FileId(0) 25..26 Other Read 565 FileId(0) 25..26 Other Read
566 "#]], 566 "#]],
@@ -581,7 +581,7 @@ fn main(s: Foo) {
581} 581}
582"#, 582"#,
583 expect![[r#" 583 expect![[r#"
584 spam RECORD_FIELD FileId(0) 17..30 21..25 Other 584 spam Field FileId(0) 17..30 21..25 Other
585 585
586 FileId(0) 67..71 Other Read 586 FileId(0) 67..71 Other Read
587 "#]], 587 "#]],
@@ -598,7 +598,7 @@ impl Foo {
598} 598}
599"#, 599"#,
600 expect![[r#" 600 expect![[r#"
601 f FN FileId(0) 27..43 30..31 Other 601 f Function FileId(0) 27..43 30..31 Other
602 602
603 "#]], 603 "#]],
604 ); 604 );
@@ -615,7 +615,7 @@ enum Foo {
615} 615}
616"#, 616"#,
617 expect![[r#" 617 expect![[r#"
618 B VARIANT FileId(0) 22..23 22..23 Other 618 B Variant FileId(0) 22..23 22..23 Other
619 619
620 "#]], 620 "#]],
621 ); 621 );
@@ -632,7 +632,7 @@ enum Foo {
632} 632}
633"#, 633"#,
634 expect![[r#" 634 expect![[r#"
635 field RECORD_FIELD FileId(0) 26..35 26..31 Other 635 field Field FileId(0) 26..35 26..31 Other
636 636
637 "#]], 637 "#]],
638 ); 638 );
@@ -673,7 +673,7 @@ fn f() {
673} 673}
674"#, 674"#,
675 expect![[r#" 675 expect![[r#"
676 Foo STRUCT FileId(1) 17..51 28..31 Other 676 Foo Struct FileId(1) 17..51 28..31 Other
677 677
678 FileId(0) 53..56 StructLiteral 678 FileId(0) 53..56 StructLiteral
679 FileId(2) 79..82 StructLiteral 679 FileId(2) 79..82 StructLiteral
@@ -703,7 +703,7 @@ pub struct Foo {
703} 703}
704"#, 704"#,
705 expect![[r#" 705 expect![[r#"
706 foo SOURCE_FILE FileId(1) 0..35 Other 706 foo Module FileId(1) 0..35 Other
707 707
708 FileId(0) 14..17 Other 708 FileId(0) 14..17 Other
709 "#]], 709 "#]],
@@ -731,7 +731,7 @@ pub(super) struct Foo<|> {
731} 731}
732"#, 732"#,
733 expect![[r#" 733 expect![[r#"
734 Foo STRUCT FileId(2) 0..41 18..21 Other 734 Foo Struct FileId(2) 0..41 18..21 Other
735 735
736 FileId(1) 20..23 Other 736 FileId(1) 20..23 Other
737 FileId(1) 47..50 StructLiteral 737 FileId(1) 47..50 StructLiteral
@@ -759,7 +759,7 @@ pub(super) struct Foo<|> {
759 code, 759 code,
760 None, 760 None,
761 expect![[r#" 761 expect![[r#"
762 quux FN FileId(0) 19..35 26..30 Other 762 quux Function FileId(0) 19..35 26..30 Other
763 763
764 FileId(1) 16..20 StructLiteral 764 FileId(1) 16..20 StructLiteral
765 FileId(2) 16..20 StructLiteral 765 FileId(2) 16..20 StructLiteral
@@ -770,7 +770,7 @@ pub(super) struct Foo<|> {
770 code, 770 code,
771 Some(SearchScope::single_file(FileId(2))), 771 Some(SearchScope::single_file(FileId(2))),
772 expect![[r#" 772 expect![[r#"
773 quux FN FileId(0) 19..35 26..30 Other 773 quux Function FileId(0) 19..35 26..30 Other
774 774
775 FileId(2) 16..20 StructLiteral 775 FileId(2) 16..20 StructLiteral
776 "#]], 776 "#]],
@@ -790,7 +790,7 @@ fn foo() {
790} 790}
791"#, 791"#,
792 expect![[r#" 792 expect![[r#"
793 m1 MACRO_RULES FileId(0) 0..46 29..31 Other 793 m1 Macro FileId(0) 0..46 29..31 Other
794 794
795 FileId(0) 63..65 StructLiteral 795 FileId(0) 63..65 StructLiteral
796 FileId(0) 73..75 StructLiteral 796 FileId(0) 73..75 StructLiteral
@@ -808,7 +808,7 @@ fn foo() {
808} 808}
809"#, 809"#,
810 expect![[r#" 810 expect![[r#"
811 i IDENT_PAT FileId(0) 23..24 Other Write 811 i Local FileId(0) 23..24 Other Write
812 812
813 FileId(0) 34..35 Other Write 813 FileId(0) 34..35 Other Write
814 FileId(0) 38..39 Other Read 814 FileId(0) 38..39 Other Read
@@ -830,7 +830,7 @@ fn foo() {
830} 830}
831"#, 831"#,
832 expect![[r#" 832 expect![[r#"
833 f RECORD_FIELD FileId(0) 15..21 15..16 Other 833 f Field FileId(0) 15..21 15..16 Other
834 834
835 FileId(0) 55..56 RecordFieldExprOrPat Read 835 FileId(0) 55..56 RecordFieldExprOrPat Read
836 FileId(0) 68..69 Other Write 836 FileId(0) 68..69 Other Write
@@ -848,7 +848,7 @@ fn foo() {
848} 848}
849"#, 849"#,
850 expect![[r#" 850 expect![[r#"
851 i IDENT_PAT FileId(0) 19..20 Other 851 i Local FileId(0) 19..20 Other
852 852
853 FileId(0) 26..27 Other Write 853 FileId(0) 26..27 Other Write
854 "#]], 854 "#]],
@@ -872,7 +872,7 @@ fn main() {
872} 872}
873"#, 873"#,
874 expect![[r#" 874 expect![[r#"
875 new FN FileId(0) 54..81 61..64 Other 875 new Function FileId(0) 54..81 61..64 Other
876 876
877 FileId(0) 126..129 StructLiteral 877 FileId(0) 126..129 StructLiteral
878 "#]], 878 "#]],
@@ -894,7 +894,7 @@ use crate::f;
894fn g() { f(); } 894fn g() { f(); }
895"#, 895"#,
896 expect![[r#" 896 expect![[r#"
897 f FN FileId(0) 22..31 25..26 Other 897 f Function FileId(0) 22..31 25..26 Other
898 898
899 FileId(1) 11..12 Other 899 FileId(1) 11..12 Other
900 FileId(1) 24..25 StructLiteral 900 FileId(1) 24..25 StructLiteral
@@ -917,7 +917,7 @@ fn f(s: S) {
917} 917}
918"#, 918"#,
919 expect![[r#" 919 expect![[r#"
920 field RECORD_FIELD FileId(0) 15..24 15..20 Other 920 field Field FileId(0) 15..24 15..20 Other
921 921
922 FileId(0) 68..73 FieldShorthandForField Read 922 FileId(0) 68..73 FieldShorthandForField Read
923 "#]], 923 "#]],
@@ -941,7 +941,7 @@ fn f(e: En) {
941} 941}
942"#, 942"#,
943 expect![[r#" 943 expect![[r#"
944 field RECORD_FIELD FileId(0) 32..41 32..37 Other 944 field Field FileId(0) 32..41 32..37 Other
945 945
946 FileId(0) 102..107 FieldShorthandForField Read 946 FileId(0) 102..107 FieldShorthandForField Read
947 "#]], 947 "#]],
@@ -965,7 +965,7 @@ fn f() -> m::En {
965} 965}
966"#, 966"#,
967 expect![[r#" 967 expect![[r#"
968 field RECORD_FIELD FileId(0) 56..65 56..61 Other 968 field Field FileId(0) 56..65 56..61 Other
969 969
970 FileId(0) 125..130 RecordFieldExprOrPat Read 970 FileId(0) 125..130 RecordFieldExprOrPat Read
971 "#]], 971 "#]],
@@ -990,7 +990,7 @@ impl Foo {
990} 990}
991"#, 991"#,
992 expect![[r#" 992 expect![[r#"
993 self SELF_KW FileId(0) 47..51 47..51 SelfKw Read 993 self SelfParam FileId(0) 47..51 47..51 SelfKw Read
994 994
995 FileId(0) 71..75 SelfKw Read 995 FileId(0) 71..75 SelfKw Read
996 FileId(0) 152..156 SelfKw Read 996 FileId(0) 152..156 SelfKw Read
@@ -1038,7 +1038,7 @@ fn foo<'a, 'b: 'a>(x: &'a<|> ()) -> &'a () where &'a (): Foo<'a> {
1038} 1038}
1039"#, 1039"#,
1040 expect![[r#" 1040 expect![[r#"
1041 'a LIFETIME_PARAM FileId(0) 55..57 55..57 Lifetime 1041 'a LifetimeParam FileId(0) 55..57 55..57 Lifetime
1042 1042
1043 FileId(0) 63..65 Lifetime 1043 FileId(0) 63..65 Lifetime
1044 FileId(0) 71..73 Lifetime 1044 FileId(0) 71..73 Lifetime
@@ -1056,7 +1056,7 @@ fn foo<'a, 'b: 'a>(x: &'a<|> ()) -> &'a () where &'a (): Foo<'a> {
1056type Foo<'a, T> where T: 'a<|> = &'a T; 1056type Foo<'a, T> where T: 'a<|> = &'a T;
1057"#, 1057"#,
1058 expect![[r#" 1058 expect![[r#"
1059 'a LIFETIME_PARAM FileId(0) 9..11 9..11 Lifetime 1059 'a LifetimeParam FileId(0) 9..11 9..11 Lifetime
1060 1060
1061 FileId(0) 25..27 Lifetime 1061 FileId(0) 25..27 Lifetime
1062 FileId(0) 31..33 Lifetime 1062 FileId(0) 31..33 Lifetime
@@ -1078,7 +1078,7 @@ impl<'a> Foo<'a> for &'a () {
1078} 1078}
1079"#, 1079"#,
1080 expect![[r#" 1080 expect![[r#"
1081 'a LIFETIME_PARAM FileId(0) 47..49 47..49 Lifetime 1081 'a LifetimeParam FileId(0) 47..49 47..49 Lifetime
1082 1082
1083 FileId(0) 55..57 Lifetime 1083 FileId(0) 55..57 Lifetime
1084 FileId(0) 64..66 Lifetime 1084 FileId(0) 64..66 Lifetime
diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs
index 2f465c195..600e93b6a 100644
--- a/crates/ide/src/runnables.rs
+++ b/crates/ide/src/runnables.rs
@@ -12,7 +12,7 @@ use syntax::{
12 12
13use crate::{ 13use crate::{
14 display::{ToNav, TryToNav}, 14 display::{ToNav, TryToNav},
15 FileId, NavigationTarget, 15 FileId, NavigationTarget, SymbolKind,
16}; 16};
17 17
18#[derive(Debug, Clone)] 18#[derive(Debug, Clone)]
@@ -137,7 +137,11 @@ fn runnable_fn(sema: &Semantics<RootDatabase>, func: ast::Fn, file_id: FileId) -
137 } 137 }
138 }; 138 };
139 139
140 let nav = NavigationTarget::from_named(sema.db, InFile::new(file_id.into(), &func)); 140 let nav = NavigationTarget::from_named(
141 sema.db,
142 InFile::new(file_id.into(), &func),
143 SymbolKind::Function,
144 );
141 let cfg = def.attrs(sema.db).cfg(); 145 let cfg = def.attrs(sema.db).cfg();
142 Some(Runnable { nav, kind, cfg }) 146 Some(Runnable { nav, kind, cfg })
143} 147}
@@ -204,7 +208,7 @@ fn module_def_doctest(sema: &Semantics<RootDatabase>, def: hir::ModuleDef) -> Op
204 nav.focus_range = None; 208 nav.focus_range = None;
205 nav.description = None; 209 nav.description = None;
206 nav.docs = None; 210 nav.docs = None;
207 nav.kind = syntax::SyntaxKind::COMMENT; 211 nav.kind = SymbolKind::DocTest;
208 let res = Runnable { nav, kind: RunnableKind::DocTest { test_id }, cfg: attrs.cfg() }; 212 let res = Runnable { nav, kind: RunnableKind::DocTest { test_id }, cfg: attrs.cfg() };
209 Some(res) 213 Some(res)
210} 214}
@@ -352,7 +356,7 @@ fn bench() {}
352 4..8, 356 4..8,
353 ), 357 ),
354 name: "main", 358 name: "main",
355 kind: FN, 359 kind: Function,
356 container_name: None, 360 container_name: None,
357 description: None, 361 description: None,
358 docs: None, 362 docs: None,
@@ -370,7 +374,7 @@ fn bench() {}
370 26..34, 374 26..34,
371 ), 375 ),
372 name: "test_foo", 376 name: "test_foo",
373 kind: FN, 377 kind: Function,
374 container_name: None, 378 container_name: None,
375 description: None, 379 description: None,
376 docs: None, 380 docs: None,
@@ -395,7 +399,7 @@ fn bench() {}
395 62..70, 399 62..70,
396 ), 400 ),
397 name: "test_foo", 401 name: "test_foo",
398 kind: FN, 402 kind: Function,
399 container_name: None, 403 container_name: None,
400 description: None, 404 description: None,
401 docs: None, 405 docs: None,
@@ -420,7 +424,7 @@ fn bench() {}
420 89..94, 424 89..94,
421 ), 425 ),
422 name: "bench", 426 name: "bench",
423 kind: FN, 427 kind: Function,
424 container_name: None, 428 container_name: None,
425 description: None, 429 description: None,
426 docs: None, 430 docs: None,
@@ -517,7 +521,7 @@ struct StructWithRunnable(String);
517 4..8, 521 4..8,
518 ), 522 ),
519 name: "main", 523 name: "main",
520 kind: FN, 524 kind: Function,
521 container_name: None, 525 container_name: None,
522 description: None, 526 description: None,
523 docs: None, 527 docs: None,
@@ -533,7 +537,7 @@ struct StructWithRunnable(String);
533 full_range: 15..74, 537 full_range: 15..74,
534 focus_range: None, 538 focus_range: None,
535 name: "should_have_runnable", 539 name: "should_have_runnable",
536 kind: COMMENT, 540 kind: DocTest,
537 container_name: None, 541 container_name: None,
538 description: None, 542 description: None,
539 docs: None, 543 docs: None,
@@ -553,7 +557,7 @@ struct StructWithRunnable(String);
553 full_range: 76..148, 557 full_range: 76..148,
554 focus_range: None, 558 focus_range: None,
555 name: "should_have_runnable_1", 559 name: "should_have_runnable_1",
556 kind: COMMENT, 560 kind: DocTest,
557 container_name: None, 561 container_name: None,
558 description: None, 562 description: None,
559 docs: None, 563 docs: None,
@@ -573,7 +577,7 @@ struct StructWithRunnable(String);
573 full_range: 150..254, 577 full_range: 150..254,
574 focus_range: None, 578 focus_range: None,
575 name: "should_have_runnable_2", 579 name: "should_have_runnable_2",
576 kind: COMMENT, 580 kind: DocTest,
577 container_name: None, 581 container_name: None,
578 description: None, 582 description: None,
579 docs: None, 583 docs: None,
@@ -593,7 +597,7 @@ struct StructWithRunnable(String);
593 full_range: 756..821, 597 full_range: 756..821,
594 focus_range: None, 598 focus_range: None,
595 name: "StructWithRunnable", 599 name: "StructWithRunnable",
596 kind: COMMENT, 600 kind: DocTest,
597 container_name: None, 601 container_name: None,
598 description: None, 602 description: None,
599 docs: None, 603 docs: None,
@@ -639,7 +643,7 @@ impl Data {
639 4..8, 643 4..8,
640 ), 644 ),
641 name: "main", 645 name: "main",
642 kind: FN, 646 kind: Function,
643 container_name: None, 647 container_name: None,
644 description: None, 648 description: None,
645 docs: None, 649 docs: None,
@@ -655,7 +659,7 @@ impl Data {
655 full_range: 44..98, 659 full_range: 44..98,
656 focus_range: None, 660 focus_range: None,
657 name: "foo", 661 name: "foo",
658 kind: COMMENT, 662 kind: DocTest,
659 container_name: None, 663 container_name: None,
660 description: None, 664 description: None,
661 docs: None, 665 docs: None,
@@ -696,7 +700,7 @@ mod test_mod {
696 5..13, 700 5..13,
697 ), 701 ),
698 name: "test_mod", 702 name: "test_mod",
699 kind: MODULE, 703 kind: Module,
700 container_name: None, 704 container_name: None,
701 description: None, 705 description: None,
702 docs: None, 706 docs: None,
@@ -716,7 +720,7 @@ mod test_mod {
716 35..44, 720 35..44,
717 ), 721 ),
718 name: "test_foo1", 722 name: "test_foo1",
719 kind: FN, 723 kind: Function,
720 container_name: None, 724 container_name: None,
721 description: None, 725 description: None,
722 docs: None, 726 docs: None,
@@ -776,7 +780,7 @@ mod root_tests {
776 26..40, 780 26..40,
777 ), 781 ),
778 name: "nested_tests_0", 782 name: "nested_tests_0",
779 kind: MODULE, 783 kind: Module,
780 container_name: None, 784 container_name: None,
781 description: None, 785 description: None,
782 docs: None, 786 docs: None,
@@ -796,7 +800,7 @@ mod root_tests {
796 55..69, 800 55..69,
797 ), 801 ),
798 name: "nested_tests_1", 802 name: "nested_tests_1",
799 kind: MODULE, 803 kind: Module,
800 container_name: None, 804 container_name: None,
801 description: None, 805 description: None,
802 docs: None, 806 docs: None,
@@ -816,7 +820,7 @@ mod root_tests {
816 107..121, 820 107..121,
817 ), 821 ),
818 name: "nested_test_11", 822 name: "nested_test_11",
819 kind: FN, 823 kind: Function,
820 container_name: None, 824 container_name: None,
821 description: None, 825 description: None,
822 docs: None, 826 docs: None,
@@ -841,7 +845,7 @@ mod root_tests {
841 163..177, 845 163..177,
842 ), 846 ),
843 name: "nested_test_12", 847 name: "nested_test_12",
844 kind: FN, 848 kind: Function,
845 container_name: None, 849 container_name: None,
846 description: None, 850 description: None,
847 docs: None, 851 docs: None,
@@ -866,7 +870,7 @@ mod root_tests {
866 206..220, 870 206..220,
867 ), 871 ),
868 name: "nested_tests_2", 872 name: "nested_tests_2",
869 kind: MODULE, 873 kind: Module,
870 container_name: None, 874 container_name: None,
871 description: None, 875 description: None,
872 docs: None, 876 docs: None,
@@ -886,7 +890,7 @@ mod root_tests {
886 258..271, 890 258..271,
887 ), 891 ),
888 name: "nested_test_2", 892 name: "nested_test_2",
889 kind: FN, 893 kind: Function,
890 container_name: None, 894 container_name: None,
891 description: None, 895 description: None,
892 docs: None, 896 docs: None,
@@ -929,7 +933,7 @@ fn test_foo1() {}
929 36..45, 933 36..45,
930 ), 934 ),
931 name: "test_foo1", 935 name: "test_foo1",
932 kind: FN, 936 kind: Function,
933 container_name: None, 937 container_name: None,
934 description: None, 938 description: None,
935 docs: None, 939 docs: None,
@@ -979,7 +983,7 @@ fn test_foo1() {}
979 58..67, 983 58..67,
980 ), 984 ),
981 name: "test_foo1", 985 name: "test_foo1",
982 kind: FN, 986 kind: Function,
983 container_name: None, 987 container_name: None,
984 description: None, 988 description: None,
985 docs: None, 989 docs: None,
diff --git a/crates/ide_db/src/symbol_index.rs b/crates/ide_db/src/symbol_index.rs
index ca455fa03..0aa6a0765 100644
--- a/crates/ide_db/src/symbol_index.rs
+++ b/crates/ide_db/src/symbol_index.rs
@@ -39,7 +39,7 @@ use rustc_hash::{FxHashMap, FxHashSet};
39use syntax::{ 39use syntax::{
40 ast::{self, NameOwner}, 40 ast::{self, NameOwner},
41 match_ast, AstNode, Parse, SmolStr, SourceFile, 41 match_ast, AstNode, Parse, SmolStr, SourceFile,
42 SyntaxKind::{self, *}, 42 SyntaxKind::*,
43 SyntaxNode, SyntaxNodePtr, TextRange, WalkEvent, 43 SyntaxNode, SyntaxNodePtr, TextRange, WalkEvent,
44}; 44};
45 45
@@ -323,7 +323,7 @@ impl Query {
323 let (start, end) = SymbolIndex::map_value_to_range(indexed_value.value); 323 let (start, end) = SymbolIndex::map_value_to_range(indexed_value.value);
324 324
325 for symbol in &symbol_index.symbols[start..end] { 325 for symbol in &symbol_index.symbols[start..end] {
326 if self.only_types && !is_type(symbol.kind) { 326 if self.only_types && !symbol.kind.is_type() {
327 continue; 327 continue;
328 } 328 }
329 if self.exact && symbol.name != self.query { 329 if self.exact && symbol.name != self.query {
@@ -341,23 +341,44 @@ impl Query {
341 } 341 }
342} 342}
343 343
344fn is_type(kind: SyntaxKind) -> bool {
345 matches!(kind, STRUCT | ENUM | TRAIT | TYPE_ALIAS)
346}
347
348/// The actual data that is stored in the index. It should be as compact as 344/// The actual data that is stored in the index. It should be as compact as
349/// possible. 345/// possible.
350#[derive(Debug, Clone, PartialEq, Eq, Hash)] 346#[derive(Debug, Clone, PartialEq, Eq, Hash)]
351pub struct FileSymbol { 347pub struct FileSymbol {
352 pub file_id: FileId, 348 pub file_id: FileId,
353 pub name: SmolStr, 349 pub name: SmolStr,
354 pub kind: SyntaxKind, 350 pub kind: FileSymbolKind,
355 pub range: TextRange, 351 pub range: TextRange,
356 pub ptr: SyntaxNodePtr, 352 pub ptr: SyntaxNodePtr,
357 pub name_range: Option<TextRange>, 353 pub name_range: Option<TextRange>,
358 pub container_name: Option<SmolStr>, 354 pub container_name: Option<SmolStr>,
359} 355}
360 356
357#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
358pub enum FileSymbolKind {
359 Function,
360 Struct,
361 Enum,
362 Trait,
363 Module,
364 TypeAlias,
365 Const,
366 Static,
367 Macro,
368}
369
370impl FileSymbolKind {
371 fn is_type(self: FileSymbolKind) -> bool {
372 matches!(
373 self,
374 FileSymbolKind::Struct
375 | FileSymbolKind::Enum
376 | FileSymbolKind::Trait
377 | FileSymbolKind::TypeAlias
378 )
379 }
380}
381
361fn source_file_to_file_symbols(source_file: &SourceFile, file_id: FileId) -> Vec<FileSymbol> { 382fn source_file_to_file_symbols(source_file: &SourceFile, file_id: FileId) -> Vec<FileSymbol> {
362 let mut symbols = Vec::new(); 383 let mut symbols = Vec::new();
363 let mut stack = Vec::new(); 384 let mut stack = Vec::new();
@@ -412,7 +433,18 @@ fn to_symbol(node: &SyntaxNode) -> Option<(SmolStr, SyntaxNodePtr, TextRange)> {
412fn to_file_symbol(node: &SyntaxNode, file_id: FileId) -> Option<FileSymbol> { 433fn to_file_symbol(node: &SyntaxNode, file_id: FileId) -> Option<FileSymbol> {
413 to_symbol(node).map(move |(name, ptr, name_range)| FileSymbol { 434 to_symbol(node).map(move |(name, ptr, name_range)| FileSymbol {
414 name, 435 name,
415 kind: node.kind(), 436 kind: match node.kind() {
437 FN => FileSymbolKind::Function,
438 STRUCT => FileSymbolKind::Struct,
439 ENUM => FileSymbolKind::Enum,
440 TRAIT => FileSymbolKind::Trait,
441 MODULE => FileSymbolKind::Module,
442 TYPE_ALIAS => FileSymbolKind::TypeAlias,
443 CONST => FileSymbolKind::Const,
444 STATIC => FileSymbolKind::Static,
445 MACRO_RULES => FileSymbolKind::Macro,
446 kind => unreachable!("{:?}", kind),
447 },
416 range: node.text_range(), 448 range: node.text_range(),
417 ptr, 449 ptr,
418 file_id, 450 file_id,
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index af226c109..404b35025 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -9,7 +9,7 @@ use std::{
9 9
10use ide::{ 10use ide::{
11 CompletionResolveCapability, FileId, FilePosition, FileRange, HoverAction, HoverGotoTypeData, 11 CompletionResolveCapability, FileId, FilePosition, FileRange, HoverAction, HoverGotoTypeData,
12 NavigationTarget, Query, RangeInfo, Runnable, RunnableKind, SearchScope, TextEdit, 12 NavigationTarget, Query, RangeInfo, Runnable, RunnableKind, SearchScope, SymbolKind, TextEdit,
13}; 13};
14use itertools::Itertools; 14use itertools::Itertools;
15use lsp_server::ErrorCode; 15use lsp_server::ErrorCode;
@@ -27,7 +27,7 @@ use project_model::TargetKind;
27use serde::{Deserialize, Serialize}; 27use serde::{Deserialize, Serialize};
28use serde_json::to_value; 28use serde_json::to_value;
29use stdx::{format_to, split_once}; 29use stdx::{format_to, split_once};
30use syntax::{algo, ast, AstNode, SyntaxKind, TextRange, TextSize}; 30use syntax::{algo, ast, AstNode, TextRange, TextSize};
31 31
32use crate::{ 32use crate::{
33 cargo_target_spec::CargoTargetSpec, 33 cargo_target_spec::CargoTargetSpec,
@@ -1037,10 +1037,10 @@ pub(crate) fn handle_code_lens(
1037 .filter(|it| { 1037 .filter(|it| {
1038 matches!( 1038 matches!(
1039 it.kind, 1039 it.kind,
1040 SyntaxKind::TRAIT 1040 SymbolKind::Trait
1041 | SyntaxKind::STRUCT 1041 | SymbolKind::Struct
1042 | SyntaxKind::ENUM 1042 | SymbolKind::Enum
1043 | SyntaxKind::UNION 1043 | SymbolKind::Union
1044 ) 1044 )
1045 }) 1045 })
1046 .map(|it| { 1046 .map(|it| {
@@ -1263,7 +1263,7 @@ pub(crate) fn handle_call_hierarchy_prepare(
1263 let RangeInfo { range: _, info: navs } = nav_info; 1263 let RangeInfo { range: _, info: navs } = nav_info;
1264 let res = navs 1264 let res = navs
1265 .into_iter() 1265 .into_iter()
1266 .filter(|it| it.kind == SyntaxKind::FN) 1266 .filter(|it| it.kind == SymbolKind::Function)
1267 .map(|it| to_proto::call_hierarchy_item(&snap, it)) 1267 .map(|it| to_proto::call_hierarchy_item(&snap, it))
1268 .collect::<Result<Vec<_>>>()?; 1268 .collect::<Result<Vec<_>>>()?;
1269 1269
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs
index 1753bbff2..79caafe80 100644
--- a/crates/rust-analyzer/src/to_proto.rs
+++ b/crates/rust-analyzer/src/to_proto.rs
@@ -9,10 +9,9 @@ use ide::{
9 FileRange, FileSystemEdit, Fold, FoldKind, Highlight, HighlightModifier, HighlightTag, 9 FileRange, FileSystemEdit, Fold, FoldKind, Highlight, HighlightModifier, HighlightTag,
10 HighlightedRange, Indel, InlayHint, InlayKind, InsertTextFormat, LineIndex, Markup, 10 HighlightedRange, Indel, InlayHint, InlayKind, InsertTextFormat, LineIndex, Markup,
11 NavigationTarget, ReferenceAccess, ResolvedAssist, Runnable, Severity, SourceChange, 11 NavigationTarget, ReferenceAccess, ResolvedAssist, Runnable, Severity, SourceChange,
12 SourceFileEdit, TextEdit, TextRange, TextSize, 12 SourceFileEdit, SymbolKind, TextEdit, TextRange, TextSize,
13}; 13};
14use itertools::Itertools; 14use itertools::Itertools;
15use syntax::SyntaxKind;
16 15
17use crate::{ 16use crate::{
18 cargo_target_spec::CargoTargetSpec, global_state::GlobalStateSnapshot, 17 cargo_target_spec::CargoTargetSpec, global_state::GlobalStateSnapshot,
@@ -30,21 +29,25 @@ pub(crate) fn range(line_index: &LineIndex, range: TextRange) -> lsp_types::Rang
30 lsp_types::Range::new(start, end) 29 lsp_types::Range::new(start, end)
31} 30}
32 31
33pub(crate) fn symbol_kind(syntax_kind: SyntaxKind) -> lsp_types::SymbolKind { 32pub(crate) fn symbol_kind(symbol_kind: SymbolKind) -> lsp_types::SymbolKind {
34 match syntax_kind { 33 match symbol_kind {
35 SyntaxKind::FN => lsp_types::SymbolKind::Function, 34 SymbolKind::Function => lsp_types::SymbolKind::Function,
36 SyntaxKind::STRUCT => lsp_types::SymbolKind::Struct, 35 SymbolKind::Struct => lsp_types::SymbolKind::Struct,
37 SyntaxKind::ENUM => lsp_types::SymbolKind::Enum, 36 SymbolKind::Enum => lsp_types::SymbolKind::Enum,
38 SyntaxKind::VARIANT => lsp_types::SymbolKind::EnumMember, 37 SymbolKind::Variant => lsp_types::SymbolKind::EnumMember,
39 SyntaxKind::TRAIT => lsp_types::SymbolKind::Interface, 38 SymbolKind::Trait => lsp_types::SymbolKind::Interface,
40 SyntaxKind::MACRO_CALL => lsp_types::SymbolKind::Function, 39 SymbolKind::Macro => lsp_types::SymbolKind::Function,
41 SyntaxKind::MODULE => lsp_types::SymbolKind::Module, 40 SymbolKind::Module => lsp_types::SymbolKind::Module,
42 SyntaxKind::TYPE_ALIAS => lsp_types::SymbolKind::TypeParameter, 41 SymbolKind::TypeAlias | SymbolKind::TypeParam => lsp_types::SymbolKind::TypeParameter,
43 SyntaxKind::RECORD_FIELD => lsp_types::SymbolKind::Field, 42 SymbolKind::Field => lsp_types::SymbolKind::Field,
44 SyntaxKind::STATIC => lsp_types::SymbolKind::Constant, 43 SymbolKind::Static => lsp_types::SymbolKind::Constant,
45 SyntaxKind::CONST => lsp_types::SymbolKind::Constant, 44 SymbolKind::Const => lsp_types::SymbolKind::Constant,
46 SyntaxKind::IMPL => lsp_types::SymbolKind::Object, 45 SymbolKind::Impl => lsp_types::SymbolKind::Object,
47 _ => lsp_types::SymbolKind::Variable, 46 SymbolKind::Local
47 | SymbolKind::SelfParam
48 | SymbolKind::LifetimeParam
49 | SymbolKind::DocTest => lsp_types::SymbolKind::Variable,
50 SymbolKind::Union => lsp_types::SymbolKind::Struct,
48 } 51 }
49} 52}
50 53