aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis')
-rw-r--r--crates/ra_analysis/src/symbol_index.rs29
-rw-r--r--crates/ra_analysis/tests/test/main.rs19
2 files changed, 37 insertions, 11 deletions
diff --git a/crates/ra_analysis/src/symbol_index.rs b/crates/ra_analysis/src/symbol_index.rs
index 55caae5c2..e2b1c88fe 100644
--- a/crates/ra_analysis/src/symbol_index.rs
+++ b/crates/ra_analysis/src/symbol_index.rs
@@ -28,11 +28,11 @@ use std::{
28use fst::{self, Streamer}; 28use fst::{self, Streamer};
29use ra_syntax::{ 29use ra_syntax::{
30 SyntaxNodeRef, SourceFileNode, SmolStr, 30 SyntaxNodeRef, SourceFileNode, SmolStr,
31 algo::visit::{visitor, Visitor}, 31 algo::{visit::{visitor, Visitor}, find_covering_node},
32 SyntaxKind::{self, *}, 32 SyntaxKind::{self, *},
33 ast::{self, NameOwner}, 33 ast::{self, NameOwner},
34}; 34};
35use ra_db::{SyntaxDatabase, SourceRootId, FilesDatabase, LocalSyntaxPtr}; 35use ra_db::{SourceRootId, FilesDatabase, LocalSyntaxPtr};
36use salsa::ParallelDatabase; 36use salsa::ParallelDatabase;
37use rayon::prelude::*; 37use rayon::prelude::*;
38 38
@@ -42,7 +42,7 @@ use crate::{
42}; 42};
43 43
44salsa::query_group! { 44salsa::query_group! {
45 pub(crate) trait SymbolsDatabase: SyntaxDatabase { 45 pub(crate) trait SymbolsDatabase: hir::db::HirDatabase {
46 fn file_symbols(file_id: FileId) -> Cancelable<Arc<SymbolIndex>> { 46 fn file_symbols(file_id: FileId) -> Cancelable<Arc<SymbolIndex>> {
47 type FileSymbolsQuery; 47 type FileSymbolsQuery;
48 } 48 }
@@ -53,10 +53,23 @@ salsa::query_group! {
53 } 53 }
54} 54}
55 55
56fn file_symbols(db: &impl SyntaxDatabase, file_id: FileId) -> Cancelable<Arc<SymbolIndex>> { 56fn file_symbols(db: &impl SymbolsDatabase, file_id: FileId) -> Cancelable<Arc<SymbolIndex>> {
57 db.check_canceled()?; 57 db.check_canceled()?;
58 let syntax = db.source_file(file_id); 58 let source_file = db.source_file(file_id);
59 Ok(Arc::new(SymbolIndex::for_file(file_id, syntax))) 59 let mut symbols = source_file
60 .syntax()
61 .descendants()
62 .filter_map(to_symbol)
63 .map(move |(name, ptr)| FileSymbol { name, ptr, file_id })
64 .collect::<Vec<_>>();
65
66 for (name, text_range) in hir::source_binder::macro_symbols(db, file_id)? {
67 let node = find_covering_node(source_file.syntax(), text_range);
68 let ptr = LocalSyntaxPtr::new(node);
69 symbols.push(FileSymbol { file_id, name, ptr })
70 }
71
72 Ok(Arc::new(SymbolIndex::new(symbols)))
60} 73}
61 74
62pub(crate) fn world_symbols(db: &RootDatabase, query: Query) -> Cancelable<Vec<FileSymbol>> { 75pub(crate) fn world_symbols(db: &RootDatabase, query: Query) -> Cancelable<Vec<FileSymbol>> {
@@ -141,10 +154,6 @@ impl SymbolIndex {
141 .collect::<Vec<_>>(); 154 .collect::<Vec<_>>();
142 SymbolIndex::new(symbols) 155 SymbolIndex::new(symbols)
143 } 156 }
144
145 fn for_file(file_id: FileId, file: SourceFileNode) -> SymbolIndex {
146 SymbolIndex::for_files(rayon::iter::once((file_id, file)))
147 }
148} 157}
149 158
150impl Query { 159impl Query {
diff --git a/crates/ra_analysis/tests/test/main.rs b/crates/ra_analysis/tests/test/main.rs
index 23a5799b9..bfdf8aef2 100644
--- a/crates/ra_analysis/tests/test/main.rs
+++ b/crates/ra_analysis/tests/test/main.rs
@@ -6,7 +6,7 @@ use test_utils::{assert_eq_dbg, assert_eq_text};
6 6
7use ra_analysis::{ 7use ra_analysis::{
8 mock_analysis::{analysis_and_position, single_file, single_file_with_position, MockAnalysis}, 8 mock_analysis::{analysis_and_position, single_file, single_file_with_position, MockAnalysis},
9 AnalysisChange, CrateGraph, FileId, FnSignatureInfo, 9 AnalysisChange, CrateGraph, FileId, FnSignatureInfo, Query
10}; 10};
11 11
12fn get_signature(text: &str) -> (FnSignatureInfo, Option<usize>) { 12fn get_signature(text: &str) -> (FnSignatureInfo, Option<usize>) {
@@ -531,6 +531,7 @@ fn test_rename_for_mut_param() {
531 }"#, 531 }"#,
532 ); 532 );
533} 533}
534
534fn test_rename(text: &str, new_name: &str, expected: &str) { 535fn test_rename(text: &str, new_name: &str, expected: &str) {
535 let (analysis, position) = single_file_with_position(text); 536 let (analysis, position) = single_file_with_position(text);
536 let edits = analysis.rename(position, new_name).unwrap(); 537 let edits = analysis.rename(position, new_name).unwrap();
@@ -547,3 +548,19 @@ fn test_rename(text: &str, new_name: &str, expected: &str) {
547 .apply(&*analysis.file_text(file_id.unwrap())); 548 .apply(&*analysis.file_text(file_id.unwrap()));
548 assert_eq_text!(expected, &*result); 549 assert_eq_text!(expected, &*result);
549} 550}
551
552#[test]
553fn world_symbols_include_stuff_from_macros() {
554 let (analysis, _) = single_file(
555 "
556salsa::query_group! {
557pub trait HirDatabase: SyntaxDatabase {}
558}
559 ",
560 );
561
562 let mut symbols = analysis.symbol_search(Query::new("Hir".into())).unwrap();
563 let s = symbols.pop().unwrap();
564 assert_eq!(s.name(), "HirDatabase");
565 assert_eq!(s.range(), TextRange::from_to(33.into(), 44.into()));
566}