diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-12-18 16:29:12 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-12-18 16:29:12 +0000 |
commit | 8be3f25b0bf77b547ba83c3eb9689a40d212a55b (patch) | |
tree | c29c3a31ea9e046d2767dfc189e0ab77b8ffdafe /crates/ide_db/src | |
parent | 03c177af89efcc238053b59069eda2c1c6772622 (diff) | |
parent | 55ba353b39db1e9d850f1df943ab6a16e7c15838 (diff) |
Merge #6930
6930: Don't expose SyntaxKind from IDE API r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ide_db/src')
-rw-r--r-- | crates/ide_db/src/symbol_index.rs | 48 |
1 files changed, 40 insertions, 8 deletions
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}; | |||
39 | use syntax::{ | 39 | use 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 | ||
344 | fn 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)] |
351 | pub struct FileSymbol { | 347 | pub 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)] | ||
358 | pub enum FileSymbolKind { | ||
359 | Function, | ||
360 | Struct, | ||
361 | Enum, | ||
362 | Trait, | ||
363 | Module, | ||
364 | TypeAlias, | ||
365 | Const, | ||
366 | Static, | ||
367 | Macro, | ||
368 | } | ||
369 | |||
370 | impl 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 | |||
361 | fn source_file_to_file_symbols(source_file: &SourceFile, file_id: FileId) -> Vec<FileSymbol> { | 382 | fn 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)> { | |||
412 | fn to_file_symbol(node: &SyntaxNode, file_id: FileId) -> Option<FileSymbol> { | 433 | fn 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, |