aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-09-15 21:42:01 +0100
committerAleksey Kladov <[email protected]>2018-09-15 22:00:05 +0100
commitfcdf3a52b4b61a39474950486ea0edf5ebf33bea (patch)
tree94e7b42645037db8a1f92c6ba9571c2e6ed33cf8 /crates
parente69ff21207d83864e13f6c8631733f4f0c32ba0d (diff)
everysalsa
Diffstat (limited to 'crates')
-rw-r--r--crates/libanalysis/src/queries.rs21
-rw-r--r--crates/libanalysis/src/roots.rs28
-rw-r--r--crates/libanalysis/src/symbol_index.rs12
-rw-r--r--crates/libeditor/src/symbols.rs2
4 files changed, 40 insertions, 23 deletions
diff --git a/crates/libanalysis/src/queries.rs b/crates/libanalysis/src/queries.rs
index 9d6754fd4..0b60316e6 100644
--- a/crates/libanalysis/src/queries.rs
+++ b/crates/libanalysis/src/queries.rs
@@ -3,13 +3,11 @@ use libsyntax2::File;
3use libeditor::LineIndex; 3use libeditor::LineIndex;
4use { 4use {
5 FileId, 5 FileId,
6 db::{Query, QueryCtx, QueryRegistry, file_text}, 6 db::{Query, QueryCtx, QueryRegistry},
7 symbol_index::SymbolIndex,
7}; 8};
8 9
9pub(crate) fn register_queries(reg: &mut QueryRegistry) { 10pub(crate) use db::{file_text, file_set};
10 reg.add(FILE_SYNTAX, "FILE_SYNTAX");
11 reg.add(FILE_LINES, "FILE_LINES");
12}
13 11
14pub(crate) fn file_syntax(ctx: QueryCtx, file_id: FileId) -> File { 12pub(crate) fn file_syntax(ctx: QueryCtx, file_id: FileId) -> File {
15 (&*ctx.get(FILE_SYNTAX, file_id)).clone() 13 (&*ctx.get(FILE_SYNTAX, file_id)).clone()
@@ -17,6 +15,9 @@ pub(crate) fn file_syntax(ctx: QueryCtx, file_id: FileId) -> File {
17pub(crate) fn file_lines(ctx: QueryCtx, file_id: FileId) -> Arc<LineIndex> { 15pub(crate) fn file_lines(ctx: QueryCtx, file_id: FileId) -> Arc<LineIndex> {
18 ctx.get(FILE_LINES, file_id) 16 ctx.get(FILE_LINES, file_id)
19} 17}
18pub(crate) fn file_symbols(ctx: QueryCtx, file_id: FileId) -> Arc<SymbolIndex> {
19 ctx.get(FILE_SYMBOLS, file_id)
20}
20 21
21const FILE_SYNTAX: Query<FileId, File> = Query(16, |ctx, file_id: &FileId| { 22const FILE_SYNTAX: Query<FileId, File> = Query(16, |ctx, file_id: &FileId| {
22 let text = file_text(ctx, *file_id); 23 let text = file_text(ctx, *file_id);
@@ -26,3 +27,13 @@ const FILE_LINES: Query<FileId, LineIndex> = Query(17, |ctx, file_id: &FileId| {
26 let text = file_text(ctx, *file_id); 27 let text = file_text(ctx, *file_id);
27 LineIndex::new(&*text) 28 LineIndex::new(&*text)
28}); 29});
30const FILE_SYMBOLS: Query<FileId, SymbolIndex> = Query(18, |ctx, file_id: &FileId| {
31 let syntax = file_syntax(ctx, *file_id);
32 SymbolIndex::for_file(*file_id, syntax)
33});
34
35pub(crate) fn register_queries(reg: &mut QueryRegistry) {
36 reg.add(FILE_SYNTAX, "FILE_SYNTAX");
37 reg.add(FILE_LINES, "FILE_LINES");
38 reg.add(FILE_SYMBOLS, "FILE_SYMBOLS");
39}
diff --git a/crates/libanalysis/src/roots.rs b/crates/libanalysis/src/roots.rs
index 0e7253ba2..191d0d821 100644
--- a/crates/libanalysis/src/roots.rs
+++ b/crates/libanalysis/src/roots.rs
@@ -22,7 +22,7 @@ pub(crate) trait SourceRoot {
22 fn module_tree(&self) -> Arc<ModuleTreeDescriptor>; 22 fn module_tree(&self) -> Arc<ModuleTreeDescriptor>;
23 fn lines(&self, file_id: FileId) -> Arc<LineIndex>; 23 fn lines(&self, file_id: FileId) -> Arc<LineIndex>;
24 fn syntax(&self, file_id: FileId) -> File; 24 fn syntax(&self, file_id: FileId) -> File;
25 fn symbols<'a>(&'a self, acc: &mut Vec<&'a SymbolIndex>); 25 fn symbols(&self, acc: &mut Vec<Arc<SymbolIndex>>);
26} 26}
27 27
28#[derive(Default, Debug)] 28#[derive(Default, Debug)]
@@ -74,20 +74,16 @@ impl SourceRoot for WritableSourceRoot {
74 fn syntax(&self, file_id: FileId) -> File { 74 fn syntax(&self, file_id: FileId) -> File {
75 self.db.make_query(|ctx| ::queries::file_syntax(ctx, file_id)) 75 self.db.make_query(|ctx| ::queries::file_syntax(ctx, file_id))
76 } 76 }
77 fn symbols<'a>(&'a self, acc: &mut Vec<&'a SymbolIndex>) { 77 fn symbols<'a>(&'a self, acc: &mut Vec<Arc<SymbolIndex>>) {
78 // acc.extend( 78 self.db.make_query(|ctx| {
79 // self.file_map 79 let file_set = ::queries::file_set(ctx);
80 // .iter() 80 let syms = file_set.0.iter()
81 // .map(|(&file_id, data)| symbols(file_id, data)) 81 .map(|file_id| ::queries::file_symbols(ctx, *file_id));
82 // ) 82 acc.extend(syms);
83 });
83 } 84 }
84} 85}
85 86
86fn symbols(file_id: FileId, (data, symbols): &(FileData, OnceCell<SymbolIndex>)) -> &SymbolIndex {
87 let syntax = data.syntax_transient();
88 symbols.get_or_init(|| SymbolIndex::for_file(file_id, syntax))
89}
90
91#[derive(Debug)] 87#[derive(Debug)]
92struct FileData { 88struct FileData {
93 text: String, 89 text: String,
@@ -121,7 +117,7 @@ impl FileData {
121 117
122#[derive(Debug)] 118#[derive(Debug)]
123pub(crate) struct ReadonlySourceRoot { 119pub(crate) struct ReadonlySourceRoot {
124 symbol_index: SymbolIndex, 120 symbol_index: Arc<SymbolIndex>,
125 file_map: HashMap<FileId, FileData>, 121 file_map: HashMap<FileId, FileData>,
126 module_tree: Arc<ModuleTreeDescriptor>, 122 module_tree: Arc<ModuleTreeDescriptor>,
127} 123}
@@ -149,7 +145,7 @@ impl ReadonlySourceRoot {
149 .collect(); 145 .collect();
150 146
151 ReadonlySourceRoot { 147 ReadonlySourceRoot {
152 symbol_index, 148 symbol_index: Arc::new(symbol_index),
153 file_map, 149 file_map,
154 module_tree: Arc::new(module_tree), 150 module_tree: Arc::new(module_tree),
155 } 151 }
@@ -176,7 +172,7 @@ impl SourceRoot for ReadonlySourceRoot {
176 fn syntax(&self, file_id: FileId) -> File { 172 fn syntax(&self, file_id: FileId) -> File {
177 self.data(file_id).syntax().clone() 173 self.data(file_id).syntax().clone()
178 } 174 }
179 fn symbols<'a>(&'a self, acc: &mut Vec<&'a SymbolIndex>) { 175 fn symbols(&self, acc: &mut Vec<Arc<SymbolIndex>>) {
180 acc.push(&self.symbol_index) 176 acc.push(Arc::clone(&self.symbol_index))
181 } 177 }
182} 178}
diff --git a/crates/libanalysis/src/symbol_index.rs b/crates/libanalysis/src/symbol_index.rs
index 4c93761aa..d22187ac0 100644
--- a/crates/libanalysis/src/symbol_index.rs
+++ b/crates/libanalysis/src/symbol_index.rs
@@ -1,3 +1,7 @@
1use std::{
2 sync::Arc,
3 hash::{Hash, Hasher},
4};
1use libeditor::{FileSymbol, file_symbols}; 5use libeditor::{FileSymbol, file_symbols};
2use libsyntax2::{ 6use libsyntax2::{
3 File, 7 File,
@@ -13,6 +17,12 @@ pub(crate) struct SymbolIndex {
13 map: fst::Map, 17 map: fst::Map,
14} 18}
15 19
20impl Hash for SymbolIndex {
21 fn hash<H: Hasher>(&self, hasher: &mut H) {
22 self.symbols.hash(hasher)
23 }
24}
25
16impl SymbolIndex { 26impl SymbolIndex {
17 pub(crate) fn for_files(files: impl ParallelIterator<Item=(FileId, File)>) -> SymbolIndex { 27 pub(crate) fn for_files(files: impl ParallelIterator<Item=(FileId, File)>) -> SymbolIndex {
18 let mut symbols = files 28 let mut symbols = files
@@ -43,7 +53,7 @@ impl SymbolIndex {
43impl Query { 53impl Query {
44 pub(crate) fn search( 54 pub(crate) fn search(
45 self, 55 self,
46 indices: &[&SymbolIndex], 56 indices: &[Arc<SymbolIndex>],
47 token: &JobToken, 57 token: &JobToken,
48 ) -> Vec<(FileId, FileSymbol)> { 58 ) -> Vec<(FileId, FileSymbol)> {
49 59
diff --git a/crates/libeditor/src/symbols.rs b/crates/libeditor/src/symbols.rs
index 28b86c004..2f9cc9233 100644
--- a/crates/libeditor/src/symbols.rs
+++ b/crates/libeditor/src/symbols.rs
@@ -17,7 +17,7 @@ pub struct StructureNode {
17 pub kind: SyntaxKind, 17 pub kind: SyntaxKind,
18} 18}
19 19
20#[derive(Debug, Clone)] 20#[derive(Debug, Clone, Hash)]
21pub struct FileSymbol { 21pub struct FileSymbol {
22 pub name: SmolStr, 22 pub name: SmolStr,
23 pub node_range: TextRange, 23 pub node_range: TextRange,