diff options
author | ivan770 <[email protected]> | 2021-03-14 15:16:29 +0000 |
---|---|---|
committer | ivan770 <[email protected]> | 2021-03-14 17:00:41 +0000 |
commit | 7d48e04f316a384967d48a261f1e3b70b5f85a98 (patch) | |
tree | 76eb426dcfa87e3b32f3b0efb4f88ca4416c57af | |
parent | 8602f9573b3a450b6a29c23bb4bfb7bd4108a89c (diff) |
Introduce StructureNodeKind
-rw-r--r-- | crates/ide/src/annotations.rs | 16 | ||||
-rw-r--r-- | crates/ide/src/file_structure.rs | 126 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/tags.rs | 1 | ||||
-rw-r--r-- | crates/ide_completion/src/item.rs | 1 | ||||
-rw-r--r-- | crates/ide_db/src/lib.rs | 7 | ||||
-rw-r--r-- | crates/rust-analyzer/src/handlers.rs | 4 | ||||
-rw-r--r-- | crates/rust-analyzer/src/to_proto.rs | 12 |
7 files changed, 110 insertions, 57 deletions
diff --git a/crates/ide/src/annotations.rs b/crates/ide/src/annotations.rs index 2e8e82b70..fd317874e 100644 --- a/crates/ide/src/annotations.rs +++ b/crates/ide/src/annotations.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use hir::Semantics; | 1 | use hir::Semantics; |
2 | use ide_db::{ | 2 | use ide_db::{ |
3 | base_db::{FileId, FilePosition, FileRange, SourceDatabase}, | 3 | base_db::{FileId, FilePosition, FileRange, SourceDatabase}, |
4 | RootDatabase, SymbolKind, | 4 | RootDatabase, StructureNodeKind, SymbolKind, |
5 | }; | 5 | }; |
6 | use syntax::TextRange; | 6 | use syntax::TextRange; |
7 | 7 | ||
@@ -80,15 +80,17 @@ pub(crate) fn annotations( | |||
80 | .filter(|node| { | 80 | .filter(|node| { |
81 | matches!( | 81 | matches!( |
82 | node.kind, | 82 | node.kind, |
83 | SymbolKind::Trait | 83 | StructureNodeKind::SymbolKind(SymbolKind::Trait) |
84 | | SymbolKind::Struct | 84 | | StructureNodeKind::SymbolKind(SymbolKind::Struct) |
85 | | SymbolKind::Enum | 85 | | StructureNodeKind::SymbolKind(SymbolKind::Enum) |
86 | | SymbolKind::Union | 86 | | StructureNodeKind::SymbolKind(SymbolKind::Union) |
87 | | SymbolKind::Const | 87 | | StructureNodeKind::SymbolKind(SymbolKind::Const) |
88 | ) | 88 | ) |
89 | }) | 89 | }) |
90 | .for_each(|node| { | 90 | .for_each(|node| { |
91 | if config.annotate_impls && node.kind != SymbolKind::Const { | 91 | if config.annotate_impls |
92 | && node.kind != StructureNodeKind::SymbolKind(SymbolKind::Const) | ||
93 | { | ||
92 | annotations.push(Annotation { | 94 | annotations.push(Annotation { |
93 | range: node.node_range, | 95 | range: node.node_range, |
94 | kind: AnnotationKind::HasImpls { | 96 | kind: AnnotationKind::HasImpls { |
diff --git a/crates/ide/src/file_structure.rs b/crates/ide/src/file_structure.rs index c5ca6ff26..c21b3fa77 100644 --- a/crates/ide/src/file_structure.rs +++ b/crates/ide/src/file_structure.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use ide_db::SymbolKind; | 1 | use ide_db::{StructureNodeKind, SymbolKind}; |
2 | use syntax::{ | 2 | use syntax::{ |
3 | ast::{self, AttrsOwner, GenericParamsOwner, NameOwner}, | 3 | ast::{self, AttrsOwner, GenericParamsOwner, NameOwner}, |
4 | match_ast, AstNode, AstToken, NodeOrToken, SourceFile, SyntaxNode, SyntaxToken, TextRange, | 4 | match_ast, AstNode, AstToken, NodeOrToken, SourceFile, SyntaxNode, SyntaxToken, TextRange, |
@@ -11,7 +11,7 @@ pub struct StructureNode { | |||
11 | pub label: String, | 11 | pub label: String, |
12 | pub navigation_range: TextRange, | 12 | pub navigation_range: TextRange, |
13 | pub node_range: TextRange, | 13 | pub node_range: TextRange, |
14 | pub kind: SymbolKind, | 14 | pub kind: StructureNodeKind, |
15 | pub detail: Option<String>, | 15 | pub detail: Option<String>, |
16 | pub deprecated: bool, | 16 | pub deprecated: bool, |
17 | } | 17 | } |
@@ -65,14 +65,14 @@ pub(crate) fn file_structure(file: &SourceFile) -> Vec<StructureNode> { | |||
65 | } | 65 | } |
66 | 66 | ||
67 | fn structure_node(node: &SyntaxNode) -> Option<StructureNode> { | 67 | fn structure_node(node: &SyntaxNode) -> Option<StructureNode> { |
68 | fn decl<N: NameOwner + AttrsOwner>(node: N, kind: SymbolKind) -> Option<StructureNode> { | 68 | fn decl<N: NameOwner + AttrsOwner>(node: N, kind: StructureNodeKind) -> Option<StructureNode> { |
69 | decl_with_detail(&node, None, kind) | 69 | decl_with_detail(&node, None, kind) |
70 | } | 70 | } |
71 | 71 | ||
72 | fn decl_with_type_ref<N: NameOwner + AttrsOwner>( | 72 | fn decl_with_type_ref<N: NameOwner + AttrsOwner>( |
73 | node: &N, | 73 | node: &N, |
74 | type_ref: Option<ast::Type>, | 74 | type_ref: Option<ast::Type>, |
75 | kind: SymbolKind, | 75 | kind: StructureNodeKind, |
76 | ) -> Option<StructureNode> { | 76 | ) -> Option<StructureNode> { |
77 | let detail = type_ref.map(|type_ref| { | 77 | let detail = type_ref.map(|type_ref| { |
78 | let mut detail = String::new(); | 78 | let mut detail = String::new(); |
@@ -85,7 +85,7 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> { | |||
85 | fn decl_with_detail<N: NameOwner + AttrsOwner>( | 85 | fn decl_with_detail<N: NameOwner + AttrsOwner>( |
86 | node: &N, | 86 | node: &N, |
87 | detail: Option<String>, | 87 | detail: Option<String>, |
88 | kind: SymbolKind, | 88 | kind: StructureNodeKind, |
89 | ) -> Option<StructureNode> { | 89 | ) -> Option<StructureNode> { |
90 | let name = node.name()?; | 90 | let name = node.name()?; |
91 | 91 | ||
@@ -133,18 +133,18 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> { | |||
133 | collapse_ws(ret_type.syntax(), &mut detail); | 133 | collapse_ws(ret_type.syntax(), &mut detail); |
134 | } | 134 | } |
135 | 135 | ||
136 | decl_with_detail(&it, Some(detail), SymbolKind::Function) | 136 | decl_with_detail(&it, Some(detail), StructureNodeKind::SymbolKind(SymbolKind::Function)) |
137 | }, | 137 | }, |
138 | ast::Struct(it) => decl(it, SymbolKind::Struct), | 138 | ast::Struct(it) => decl(it, StructureNodeKind::SymbolKind(SymbolKind::Struct)), |
139 | ast::Union(it) => decl(it, SymbolKind::Union), | 139 | ast::Union(it) => decl(it, StructureNodeKind::SymbolKind(SymbolKind::Union)), |
140 | ast::Enum(it) => decl(it, SymbolKind::Enum), | 140 | ast::Enum(it) => decl(it, StructureNodeKind::SymbolKind(SymbolKind::Enum)), |
141 | ast::Variant(it) => decl(it, SymbolKind::Variant), | 141 | ast::Variant(it) => decl(it, StructureNodeKind::SymbolKind(SymbolKind::Variant)), |
142 | ast::Trait(it) => decl(it, SymbolKind::Trait), | 142 | ast::Trait(it) => decl(it, StructureNodeKind::SymbolKind(SymbolKind::Trait)), |
143 | ast::Module(it) => decl(it, SymbolKind::Module), | 143 | ast::Module(it) => decl(it, StructureNodeKind::SymbolKind(SymbolKind::Module)), |
144 | ast::TypeAlias(it) => decl_with_type_ref(&it, it.ty(), SymbolKind::TypeAlias), | 144 | ast::TypeAlias(it) => decl_with_type_ref(&it, it.ty(), StructureNodeKind::SymbolKind(SymbolKind::TypeAlias)), |
145 | ast::RecordField(it) => decl_with_type_ref(&it, it.ty(), SymbolKind::Field), | 145 | ast::RecordField(it) => decl_with_type_ref(&it, it.ty(), StructureNodeKind::SymbolKind(SymbolKind::Field)), |
146 | ast::Const(it) => decl_with_type_ref(&it, it.ty(), SymbolKind::Const), | 146 | ast::Const(it) => decl_with_type_ref(&it, it.ty(), StructureNodeKind::SymbolKind(SymbolKind::Const)), |
147 | ast::Static(it) => decl_with_type_ref(&it, it.ty(), SymbolKind::Static), | 147 | ast::Static(it) => decl_with_type_ref(&it, it.ty(), StructureNodeKind::SymbolKind(SymbolKind::Static)), |
148 | ast::Impl(it) => { | 148 | ast::Impl(it) => { |
149 | let target_type = it.self_ty()?; | 149 | let target_type = it.self_ty()?; |
150 | let target_trait = it.trait_(); | 150 | let target_trait = it.trait_(); |
@@ -160,13 +160,13 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> { | |||
160 | label, | 160 | label, |
161 | navigation_range: target_type.syntax().text_range(), | 161 | navigation_range: target_type.syntax().text_range(), |
162 | node_range: it.syntax().text_range(), | 162 | node_range: it.syntax().text_range(), |
163 | kind: SymbolKind::Impl, | 163 | kind: StructureNodeKind::SymbolKind(SymbolKind::Impl), |
164 | detail: None, | 164 | detail: None, |
165 | deprecated: false, | 165 | deprecated: false, |
166 | }; | 166 | }; |
167 | Some(node) | 167 | Some(node) |
168 | }, | 168 | }, |
169 | ast::MacroRules(it) => decl(it, SymbolKind::Macro), | 169 | ast::MacroRules(it) => decl(it, StructureNodeKind::SymbolKind(SymbolKind::Macro)), |
170 | _ => None, | 170 | _ => None, |
171 | } | 171 | } |
172 | } | 172 | } |
@@ -182,7 +182,7 @@ fn structure_token(token: SyntaxToken) -> Option<StructureNode> { | |||
182 | label: region_name.to_string(), | 182 | label: region_name.to_string(), |
183 | navigation_range: comment.syntax().text_range(), | 183 | navigation_range: comment.syntax().text_range(), |
184 | node_range: comment.syntax().text_range(), | 184 | node_range: comment.syntax().text_range(), |
185 | kind: SymbolKind::Region, | 185 | kind: StructureNodeKind::Region, |
186 | detail: None, | 186 | detail: None, |
187 | deprecated: false, | 187 | deprecated: false, |
188 | }); | 188 | }); |
@@ -268,7 +268,9 @@ fn g() {} | |||
268 | label: "Foo", | 268 | label: "Foo", |
269 | navigation_range: 8..11, | 269 | navigation_range: 8..11, |
270 | node_range: 1..26, | 270 | node_range: 1..26, |
271 | kind: Struct, | 271 | kind: SymbolKind( |
272 | Struct, | ||
273 | ), | ||
272 | detail: None, | 274 | detail: None, |
273 | deprecated: false, | 275 | deprecated: false, |
274 | }, | 276 | }, |
@@ -279,7 +281,9 @@ fn g() {} | |||
279 | label: "x", | 281 | label: "x", |
280 | navigation_range: 18..19, | 282 | navigation_range: 18..19, |
281 | node_range: 18..24, | 283 | node_range: 18..24, |
282 | kind: Field, | 284 | kind: SymbolKind( |
285 | Field, | ||
286 | ), | ||
283 | detail: Some( | 287 | detail: Some( |
284 | "i32", | 288 | "i32", |
285 | ), | 289 | ), |
@@ -290,7 +294,9 @@ fn g() {} | |||
290 | label: "m", | 294 | label: "m", |
291 | navigation_range: 32..33, | 295 | navigation_range: 32..33, |
292 | node_range: 28..158, | 296 | node_range: 28..158, |
293 | kind: Module, | 297 | kind: SymbolKind( |
298 | Module, | ||
299 | ), | ||
294 | detail: None, | 300 | detail: None, |
295 | deprecated: false, | 301 | deprecated: false, |
296 | }, | 302 | }, |
@@ -301,7 +307,9 @@ fn g() {} | |||
301 | label: "bar1", | 307 | label: "bar1", |
302 | navigation_range: 43..47, | 308 | navigation_range: 43..47, |
303 | node_range: 40..52, | 309 | node_range: 40..52, |
304 | kind: Function, | 310 | kind: SymbolKind( |
311 | Function, | ||
312 | ), | ||
305 | detail: Some( | 313 | detail: Some( |
306 | "fn()", | 314 | "fn()", |
307 | ), | 315 | ), |
@@ -314,7 +322,9 @@ fn g() {} | |||
314 | label: "bar2", | 322 | label: "bar2", |
315 | navigation_range: 60..64, | 323 | navigation_range: 60..64, |
316 | node_range: 57..81, | 324 | node_range: 57..81, |
317 | kind: Function, | 325 | kind: SymbolKind( |
326 | Function, | ||
327 | ), | ||
318 | detail: Some( | 328 | detail: Some( |
319 | "fn<T>(t: T) -> T", | 329 | "fn<T>(t: T) -> T", |
320 | ), | 330 | ), |
@@ -327,7 +337,9 @@ fn g() {} | |||
327 | label: "bar3", | 337 | label: "bar3", |
328 | navigation_range: 89..93, | 338 | navigation_range: 89..93, |
329 | node_range: 86..156, | 339 | node_range: 86..156, |
330 | kind: Function, | 340 | kind: SymbolKind( |
341 | Function, | ||
342 | ), | ||
331 | detail: Some( | 343 | detail: Some( |
332 | "fn<A, B>(a: A, b: B) -> Vec< u32 >", | 344 | "fn<A, B>(a: A, b: B) -> Vec< u32 >", |
333 | ), | 345 | ), |
@@ -338,7 +350,9 @@ fn g() {} | |||
338 | label: "E", | 350 | label: "E", |
339 | navigation_range: 165..166, | 351 | navigation_range: 165..166, |
340 | node_range: 160..180, | 352 | node_range: 160..180, |
341 | kind: Enum, | 353 | kind: SymbolKind( |
354 | Enum, | ||
355 | ), | ||
342 | detail: None, | 356 | detail: None, |
343 | deprecated: false, | 357 | deprecated: false, |
344 | }, | 358 | }, |
@@ -349,7 +363,9 @@ fn g() {} | |||
349 | label: "X", | 363 | label: "X", |
350 | navigation_range: 169..170, | 364 | navigation_range: 169..170, |
351 | node_range: 169..170, | 365 | node_range: 169..170, |
352 | kind: Variant, | 366 | kind: SymbolKind( |
367 | Variant, | ||
368 | ), | ||
353 | detail: None, | 369 | detail: None, |
354 | deprecated: false, | 370 | deprecated: false, |
355 | }, | 371 | }, |
@@ -360,7 +376,9 @@ fn g() {} | |||
360 | label: "Y", | 376 | label: "Y", |
361 | navigation_range: 172..173, | 377 | navigation_range: 172..173, |
362 | node_range: 172..178, | 378 | node_range: 172..178, |
363 | kind: Variant, | 379 | kind: SymbolKind( |
380 | Variant, | ||
381 | ), | ||
364 | detail: None, | 382 | detail: None, |
365 | deprecated: false, | 383 | deprecated: false, |
366 | }, | 384 | }, |
@@ -369,7 +387,9 @@ fn g() {} | |||
369 | label: "T", | 387 | label: "T", |
370 | navigation_range: 186..187, | 388 | navigation_range: 186..187, |
371 | node_range: 181..193, | 389 | node_range: 181..193, |
372 | kind: TypeAlias, | 390 | kind: SymbolKind( |
391 | TypeAlias, | ||
392 | ), | ||
373 | detail: Some( | 393 | detail: Some( |
374 | "()", | 394 | "()", |
375 | ), | 395 | ), |
@@ -380,7 +400,9 @@ fn g() {} | |||
380 | label: "S", | 400 | label: "S", |
381 | navigation_range: 201..202, | 401 | navigation_range: 201..202, |
382 | node_range: 194..213, | 402 | node_range: 194..213, |
383 | kind: Static, | 403 | kind: SymbolKind( |
404 | Static, | ||
405 | ), | ||
384 | detail: Some( | 406 | detail: Some( |
385 | "i32", | 407 | "i32", |
386 | ), | 408 | ), |
@@ -391,7 +413,9 @@ fn g() {} | |||
391 | label: "C", | 413 | label: "C", |
392 | navigation_range: 220..221, | 414 | navigation_range: 220..221, |
393 | node_range: 214..232, | 415 | node_range: 214..232, |
394 | kind: Const, | 416 | kind: SymbolKind( |
417 | Const, | ||
418 | ), | ||
395 | detail: Some( | 419 | detail: Some( |
396 | "i32", | 420 | "i32", |
397 | ), | 421 | ), |
@@ -402,7 +426,9 @@ fn g() {} | |||
402 | label: "impl E", | 426 | label: "impl E", |
403 | navigation_range: 239..240, | 427 | navigation_range: 239..240, |
404 | node_range: 234..243, | 428 | node_range: 234..243, |
405 | kind: Impl, | 429 | kind: SymbolKind( |
430 | Impl, | ||
431 | ), | ||
406 | detail: None, | 432 | detail: None, |
407 | deprecated: false, | 433 | deprecated: false, |
408 | }, | 434 | }, |
@@ -411,7 +437,9 @@ fn g() {} | |||
411 | label: "impl fmt::Debug for E", | 437 | label: "impl fmt::Debug for E", |
412 | navigation_range: 265..266, | 438 | navigation_range: 265..266, |
413 | node_range: 245..269, | 439 | node_range: 245..269, |
414 | kind: Impl, | 440 | kind: SymbolKind( |
441 | Impl, | ||
442 | ), | ||
415 | detail: None, | 443 | detail: None, |
416 | deprecated: false, | 444 | deprecated: false, |
417 | }, | 445 | }, |
@@ -420,7 +448,9 @@ fn g() {} | |||
420 | label: "mc", | 448 | label: "mc", |
421 | navigation_range: 284..286, | 449 | navigation_range: 284..286, |
422 | node_range: 271..303, | 450 | node_range: 271..303, |
423 | kind: Macro, | 451 | kind: SymbolKind( |
452 | Macro, | ||
453 | ), | ||
424 | detail: None, | 454 | detail: None, |
425 | deprecated: false, | 455 | deprecated: false, |
426 | }, | 456 | }, |
@@ -429,7 +459,9 @@ fn g() {} | |||
429 | label: "mcexp", | 459 | label: "mcexp", |
430 | navigation_range: 334..339, | 460 | navigation_range: 334..339, |
431 | node_range: 305..356, | 461 | node_range: 305..356, |
432 | kind: Macro, | 462 | kind: SymbolKind( |
463 | Macro, | ||
464 | ), | ||
433 | detail: None, | 465 | detail: None, |
434 | deprecated: false, | 466 | deprecated: false, |
435 | }, | 467 | }, |
@@ -438,7 +470,9 @@ fn g() {} | |||
438 | label: "mcexp", | 470 | label: "mcexp", |
439 | navigation_range: 387..392, | 471 | navigation_range: 387..392, |
440 | node_range: 358..409, | 472 | node_range: 358..409, |
441 | kind: Macro, | 473 | kind: SymbolKind( |
474 | Macro, | ||
475 | ), | ||
442 | detail: None, | 476 | detail: None, |
443 | deprecated: false, | 477 | deprecated: false, |
444 | }, | 478 | }, |
@@ -447,7 +481,9 @@ fn g() {} | |||
447 | label: "obsolete", | 481 | label: "obsolete", |
448 | navigation_range: 428..436, | 482 | navigation_range: 428..436, |
449 | node_range: 411..441, | 483 | node_range: 411..441, |
450 | kind: Function, | 484 | kind: SymbolKind( |
485 | Function, | ||
486 | ), | ||
451 | detail: Some( | 487 | detail: Some( |
452 | "fn()", | 488 | "fn()", |
453 | ), | 489 | ), |
@@ -458,7 +494,9 @@ fn g() {} | |||
458 | label: "very_obsolete", | 494 | label: "very_obsolete", |
459 | navigation_range: 481..494, | 495 | navigation_range: 481..494, |
460 | node_range: 443..499, | 496 | node_range: 443..499, |
461 | kind: Function, | 497 | kind: SymbolKind( |
498 | Function, | ||
499 | ), | ||
462 | detail: Some( | 500 | detail: Some( |
463 | "fn()", | 501 | "fn()", |
464 | ), | 502 | ), |
@@ -478,7 +516,9 @@ fn g() {} | |||
478 | label: "m", | 516 | label: "m", |
479 | navigation_range: 568..569, | 517 | navigation_range: 568..569, |
480 | node_range: 543..606, | 518 | node_range: 543..606, |
481 | kind: Module, | 519 | kind: SymbolKind( |
520 | Module, | ||
521 | ), | ||
482 | detail: None, | 522 | detail: None, |
483 | deprecated: false, | 523 | deprecated: false, |
484 | }, | 524 | }, |
@@ -500,7 +540,9 @@ fn g() {} | |||
500 | label: "f", | 540 | label: "f", |
501 | navigation_range: 575..576, | 541 | navigation_range: 575..576, |
502 | node_range: 572..581, | 542 | node_range: 572..581, |
503 | kind: Function, | 543 | kind: SymbolKind( |
544 | Function, | ||
545 | ), | ||
504 | detail: Some( | 546 | detail: Some( |
505 | "fn()", | 547 | "fn()", |
506 | ), | 548 | ), |
@@ -513,7 +555,9 @@ fn g() {} | |||
513 | label: "g", | 555 | label: "g", |
514 | navigation_range: 598..599, | 556 | navigation_range: 598..599, |
515 | node_range: 582..604, | 557 | node_range: 582..604, |
516 | kind: Function, | 558 | kind: SymbolKind( |
559 | Function, | ||
560 | ), | ||
517 | detail: Some( | 561 | detail: Some( |
518 | "fn()", | 562 | "fn()", |
519 | ), | 563 | ), |
diff --git a/crates/ide/src/syntax_highlighting/tags.rs b/crates/ide/src/syntax_highlighting/tags.rs index c7e74aed8..3c02fdb11 100644 --- a/crates/ide/src/syntax_highlighting/tags.rs +++ b/crates/ide/src/syntax_highlighting/tags.rs | |||
@@ -107,7 +107,6 @@ impl HlTag { | |||
107 | SymbolKind::ValueParam => "value_param", | 107 | SymbolKind::ValueParam => "value_param", |
108 | SymbolKind::SelfParam => "self_keyword", | 108 | SymbolKind::SelfParam => "self_keyword", |
109 | SymbolKind::Impl => "self_type", | 109 | SymbolKind::Impl => "self_type", |
110 | SymbolKind::Region => "region", | ||
111 | }, | 110 | }, |
112 | HlTag::Attribute => "attribute", | 111 | HlTag::Attribute => "attribute", |
113 | HlTag::BoolLiteral => "bool_literal", | 112 | HlTag::BoolLiteral => "bool_literal", |
diff --git a/crates/ide_completion/src/item.rs b/crates/ide_completion/src/item.rs index 7b553ea7a..9a4b5217a 100644 --- a/crates/ide_completion/src/item.rs +++ b/crates/ide_completion/src/item.rs | |||
@@ -225,7 +225,6 @@ impl CompletionItemKind { | |||
225 | SymbolKind::Local => "lc", | 225 | SymbolKind::Local => "lc", |
226 | SymbolKind::Macro => "ma", | 226 | SymbolKind::Macro => "ma", |
227 | SymbolKind::Module => "md", | 227 | SymbolKind::Module => "md", |
228 | SymbolKind::Region => "rn", | ||
229 | SymbolKind::SelfParam => "sp", | 228 | SymbolKind::SelfParam => "sp", |
230 | SymbolKind::Static => "sc", | 229 | SymbolKind::Static => "sc", |
231 | SymbolKind::Struct => "st", | 230 | SymbolKind::Struct => "st", |
diff --git a/crates/ide_db/src/lib.rs b/crates/ide_db/src/lib.rs index d478841e2..e8cafba43 100644 --- a/crates/ide_db/src/lib.rs +++ b/crates/ide_db/src/lib.rs | |||
@@ -136,6 +136,12 @@ fn line_index(db: &dyn LineIndexDatabase, file_id: FileId) -> Arc<LineIndex> { | |||
136 | } | 136 | } |
137 | 137 | ||
138 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] | 138 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] |
139 | pub enum StructureNodeKind { | ||
140 | SymbolKind(SymbolKind), | ||
141 | Region, | ||
142 | } | ||
143 | |||
144 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] | ||
139 | pub enum SymbolKind { | 145 | pub enum SymbolKind { |
140 | Const, | 146 | Const, |
141 | ConstParam, | 147 | ConstParam, |
@@ -148,7 +154,6 @@ pub enum SymbolKind { | |||
148 | Local, | 154 | Local, |
149 | Macro, | 155 | Macro, |
150 | Module, | 156 | Module, |
151 | Region, | ||
152 | SelfParam, | 157 | SelfParam, |
153 | Static, | 158 | Static, |
154 | Struct, | 159 | Struct, |
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index 706a39dab..3ff8bd940 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs | |||
@@ -11,7 +11,7 @@ use ide::{ | |||
11 | AnnotationConfig, FileId, FilePosition, FileRange, HoverAction, HoverGotoTypeData, Query, | 11 | AnnotationConfig, FileId, FilePosition, FileRange, HoverAction, HoverGotoTypeData, Query, |
12 | RangeInfo, Runnable, RunnableKind, SearchScope, SourceChange, TextEdit, | 12 | RangeInfo, Runnable, RunnableKind, SearchScope, SourceChange, TextEdit, |
13 | }; | 13 | }; |
14 | use ide_db::SymbolKind; | 14 | use ide_db::{StructureNodeKind, SymbolKind}; |
15 | use itertools::Itertools; | 15 | use itertools::Itertools; |
16 | use lsp_server::ErrorCode; | 16 | use lsp_server::ErrorCode; |
17 | use lsp_types::{ | 17 | use lsp_types::{ |
@@ -289,7 +289,7 @@ pub(crate) fn handle_document_symbol( | |||
289 | let doc_symbol = lsp_types::DocumentSymbol { | 289 | let doc_symbol = lsp_types::DocumentSymbol { |
290 | name: symbol.label, | 290 | name: symbol.label, |
291 | detail: symbol.detail, | 291 | detail: symbol.detail, |
292 | kind: to_proto::symbol_kind(symbol.kind), | 292 | kind: to_proto::structure_node_kind(symbol.kind), |
293 | tags: Some(tags), | 293 | tags: Some(tags), |
294 | deprecated: Some(symbol.deprecated), | 294 | deprecated: Some(symbol.deprecated), |
295 | range: to_proto::range(&line_index, symbol.node_range), | 295 | range: to_proto::range(&line_index, symbol.node_range), |
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index e88818eb0..ab742a17c 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs | |||
@@ -11,7 +11,7 @@ use ide::{ | |||
11 | Markup, NavigationTarget, ReferenceAccess, RenameError, Runnable, Severity, SourceChange, | 11 | Markup, NavigationTarget, ReferenceAccess, RenameError, Runnable, Severity, SourceChange, |
12 | TextEdit, TextRange, TextSize, | 12 | TextEdit, TextRange, TextSize, |
13 | }; | 13 | }; |
14 | use ide_db::SymbolKind; | 14 | use ide_db::{StructureNodeKind, SymbolKind}; |
15 | use itertools::Itertools; | 15 | use itertools::Itertools; |
16 | use serde_json::to_value; | 16 | use serde_json::to_value; |
17 | 17 | ||
@@ -60,7 +60,13 @@ pub(crate) fn symbol_kind(symbol_kind: SymbolKind) -> lsp_types::SymbolKind { | |||
60 | | SymbolKind::ValueParam | 60 | | SymbolKind::ValueParam |
61 | | SymbolKind::Label => lsp_types::SymbolKind::Variable, | 61 | | SymbolKind::Label => lsp_types::SymbolKind::Variable, |
62 | SymbolKind::Union => lsp_types::SymbolKind::Struct, | 62 | SymbolKind::Union => lsp_types::SymbolKind::Struct, |
63 | SymbolKind::Region => lsp_types::SymbolKind::Namespace, | 63 | } |
64 | } | ||
65 | |||
66 | pub(crate) fn structure_node_kind(kind: StructureNodeKind) -> lsp_types::SymbolKind { | ||
67 | match kind { | ||
68 | StructureNodeKind::SymbolKind(symbol) => symbol_kind(symbol), | ||
69 | StructureNodeKind::Region => lsp_types::SymbolKind::Namespace, | ||
64 | } | 70 | } |
65 | } | 71 | } |
66 | 72 | ||
@@ -118,7 +124,6 @@ pub(crate) fn completion_item_kind( | |||
118 | SymbolKind::Local => lsp_types::CompletionItemKind::Variable, | 124 | SymbolKind::Local => lsp_types::CompletionItemKind::Variable, |
119 | SymbolKind::Macro => lsp_types::CompletionItemKind::Method, | 125 | SymbolKind::Macro => lsp_types::CompletionItemKind::Method, |
120 | SymbolKind::Module => lsp_types::CompletionItemKind::Module, | 126 | SymbolKind::Module => lsp_types::CompletionItemKind::Module, |
121 | SymbolKind::Region => lsp_types::CompletionItemKind::Keyword, | ||
122 | SymbolKind::SelfParam => lsp_types::CompletionItemKind::Value, | 127 | SymbolKind::SelfParam => lsp_types::CompletionItemKind::Value, |
123 | SymbolKind::Static => lsp_types::CompletionItemKind::Value, | 128 | SymbolKind::Static => lsp_types::CompletionItemKind::Value, |
124 | SymbolKind::Struct => lsp_types::CompletionItemKind::Struct, | 129 | SymbolKind::Struct => lsp_types::CompletionItemKind::Struct, |
@@ -430,7 +435,6 @@ fn semantic_token_type_and_modifiers( | |||
430 | SymbolKind::TypeAlias => semantic_tokens::TYPE_ALIAS, | 435 | SymbolKind::TypeAlias => semantic_tokens::TYPE_ALIAS, |
431 | SymbolKind::Trait => lsp_types::SemanticTokenType::INTERFACE, | 436 | SymbolKind::Trait => lsp_types::SemanticTokenType::INTERFACE, |
432 | SymbolKind::Macro => lsp_types::SemanticTokenType::MACRO, | 437 | SymbolKind::Macro => lsp_types::SemanticTokenType::MACRO, |
433 | SymbolKind::Region => lsp_types::SemanticTokenType::NAMESPACE, | ||
434 | }, | 438 | }, |
435 | HlTag::BuiltinType => semantic_tokens::BUILTIN_TYPE, | 439 | HlTag::BuiltinType => semantic_tokens::BUILTIN_TYPE, |
436 | HlTag::None => semantic_tokens::GENERIC, | 440 | HlTag::None => semantic_tokens::GENERIC, |