diff options
Diffstat (limited to 'crates/ra_analysis/src/lib.rs')
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 78 |
1 files changed, 46 insertions, 32 deletions
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index d8b355a81..2eeacaabe 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs | |||
@@ -1,44 +1,40 @@ | |||
1 | extern crate parking_lot; | 1 | extern crate parking_lot; |
2 | #[macro_use] | 2 | #[macro_use] |
3 | extern crate log; | 3 | extern crate log; |
4 | extern crate fst; | ||
4 | extern crate once_cell; | 5 | extern crate once_cell; |
5 | extern crate ra_syntax; | ||
6 | extern crate ra_editor; | 6 | extern crate ra_editor; |
7 | extern crate fst; | 7 | extern crate ra_syntax; |
8 | extern crate rayon; | 8 | extern crate rayon; |
9 | extern crate relative_path; | 9 | extern crate relative_path; |
10 | #[macro_use] | 10 | #[macro_use] |
11 | extern crate crossbeam_channel; | 11 | extern crate crossbeam_channel; |
12 | extern crate im; | 12 | extern crate im; |
13 | extern crate salsa; | ||
14 | extern crate rustc_hash; | 13 | extern crate rustc_hash; |
14 | extern crate salsa; | ||
15 | 15 | ||
16 | mod symbol_index; | 16 | mod db; |
17 | mod module_map; | 17 | mod descriptors; |
18 | mod imp; | 18 | mod imp; |
19 | mod job; | 19 | mod job; |
20 | mod module_map; | ||
20 | mod roots; | 21 | mod roots; |
21 | mod db; | 22 | mod symbol_index; |
22 | mod descriptors; | ||
23 | 23 | ||
24 | use std::{ | 24 | use std::{fmt::Debug, sync::Arc}; |
25 | sync::Arc, | ||
26 | fmt::Debug, | ||
27 | }; | ||
28 | 25 | ||
26 | use crate::imp::{AnalysisHostImpl, AnalysisImpl, FileResolverImp}; | ||
27 | use ra_syntax::{AtomEdit, File, TextRange, TextUnit}; | ||
29 | use relative_path::{RelativePath, RelativePathBuf}; | 28 | use relative_path::{RelativePath, RelativePathBuf}; |
30 | use ra_syntax::{File, TextRange, TextUnit, AtomEdit}; | ||
31 | use rustc_hash::FxHashMap; | 29 | use rustc_hash::FxHashMap; |
32 | use crate::imp::{AnalysisImpl, AnalysisHostImpl, FileResolverImp}; | ||
33 | 30 | ||
34 | pub use ra_editor::{ | ||
35 | StructureNode, LineIndex, FileSymbol, | ||
36 | Runnable, RunnableKind, HighlightedRange, CompletionItem, | ||
37 | Fold, FoldKind | ||
38 | }; | ||
39 | pub use crate::{ | 31 | pub use crate::{ |
40 | job::{JobToken, JobHandle}, | ||
41 | descriptors::FnDescriptor, | 32 | descriptors::FnDescriptor, |
33 | job::{JobHandle, JobToken}, | ||
34 | }; | ||
35 | pub use ra_editor::{ | ||
36 | CompletionItem, FileSymbol, Fold, FoldKind, HighlightedRange, LineIndex, Runnable, | ||
37 | RunnableKind, StructureNode, | ||
42 | }; | 38 | }; |
43 | 39 | ||
44 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | 40 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] |
@@ -59,20 +55,24 @@ pub trait FileResolver: Debug + Send + Sync + 'static { | |||
59 | 55 | ||
60 | #[derive(Debug)] | 56 | #[derive(Debug)] |
61 | pub struct AnalysisHost { | 57 | pub struct AnalysisHost { |
62 | imp: AnalysisHostImpl | 58 | imp: AnalysisHostImpl, |
63 | } | 59 | } |
64 | 60 | ||
65 | impl AnalysisHost { | 61 | impl AnalysisHost { |
66 | pub fn new() -> AnalysisHost { | 62 | pub fn new() -> AnalysisHost { |
67 | AnalysisHost { imp: AnalysisHostImpl::new() } | 63 | AnalysisHost { |
64 | imp: AnalysisHostImpl::new(), | ||
65 | } | ||
68 | } | 66 | } |
69 | pub fn analysis(&self) -> Analysis { | 67 | pub fn analysis(&self) -> Analysis { |
70 | Analysis { imp: self.imp.analysis() } | 68 | Analysis { |
69 | imp: self.imp.analysis(), | ||
70 | } | ||
71 | } | 71 | } |
72 | pub fn change_file(&mut self, file_id: FileId, text: Option<String>) { | 72 | pub fn change_file(&mut self, file_id: FileId, text: Option<String>) { |
73 | self.change_files(::std::iter::once((file_id, text))); | 73 | self.change_files(::std::iter::once((file_id, text))); |
74 | } | 74 | } |
75 | pub fn change_files(&mut self, mut changes: impl Iterator<Item=(FileId, Option<String>)>) { | 75 | pub fn change_files(&mut self, mut changes: impl Iterator<Item = (FileId, Option<String>)>) { |
76 | self.imp.change_files(&mut changes) | 76 | self.imp.change_files(&mut changes) |
77 | } | 77 | } |
78 | pub fn set_file_resolver(&mut self, resolver: Arc<FileResolver>) { | 78 | pub fn set_file_resolver(&mut self, resolver: Arc<FileResolver>) { |
@@ -115,7 +115,7 @@ pub enum FileSystemEdit { | |||
115 | MoveFile { | 115 | MoveFile { |
116 | file: FileId, | 116 | file: FileId, |
117 | path: RelativePathBuf, | 117 | path: RelativePathBuf, |
118 | } | 118 | }, |
119 | } | 119 | } |
120 | 120 | ||
121 | #[derive(Debug)] | 121 | #[derive(Debug)] |
@@ -144,7 +144,7 @@ impl Query { | |||
144 | only_types: false, | 144 | only_types: false, |
145 | libs: false, | 145 | libs: false, |
146 | exact: false, | 146 | exact: false, |
147 | limit: usize::max_value() | 147 | limit: usize::max_value(), |
148 | } | 148 | } |
149 | } | 149 | } |
150 | pub fn only_types(&mut self) { | 150 | pub fn only_types(&mut self) { |
@@ -163,7 +163,7 @@ impl Query { | |||
163 | 163 | ||
164 | #[derive(Debug)] | 164 | #[derive(Debug)] |
165 | pub struct Analysis { | 165 | pub struct Analysis { |
166 | imp: AnalysisImpl | 166 | imp: AnalysisImpl, |
167 | } | 167 | } |
168 | 168 | ||
169 | impl Analysis { | 169 | impl Analysis { |
@@ -195,7 +195,11 @@ impl Analysis { | |||
195 | } | 195 | } |
196 | pub fn on_eq_typed(&self, file_id: FileId, offset: TextUnit) -> Option<SourceChange> { | 196 | pub fn on_eq_typed(&self, file_id: FileId, offset: TextUnit) -> Option<SourceChange> { |
197 | let file = self.imp.file_syntax(file_id); | 197 | let file = self.imp.file_syntax(file_id); |
198 | Some(SourceChange::from_local_edit(file_id, "add semicolon", ra_editor::on_eq_typed(&file, offset)?)) | 198 | Some(SourceChange::from_local_edit( |
199 | file_id, | ||
200 | "add semicolon", | ||
201 | ra_editor::on_eq_typed(&file, offset)?, | ||
202 | )) | ||
199 | } | 203 | } |
200 | pub fn file_structure(&self, file_id: FileId) -> Vec<StructureNode> { | 204 | pub fn file_structure(&self, file_id: FileId) -> Vec<StructureNode> { |
201 | let file = self.imp.file_syntax(file_id); | 205 | let file = self.imp.file_syntax(file_id); |
@@ -204,8 +208,14 @@ impl Analysis { | |||
204 | pub fn symbol_search(&self, query: Query, token: &JobToken) -> Vec<(FileId, FileSymbol)> { | 208 | pub fn symbol_search(&self, query: Query, token: &JobToken) -> Vec<(FileId, FileSymbol)> { |
205 | self.imp.world_symbols(query, token) | 209 | self.imp.world_symbols(query, token) |
206 | } | 210 | } |
207 | pub fn approximately_resolve_symbol(&self, file_id: FileId, offset: TextUnit, token: &JobToken) -> Vec<(FileId, FileSymbol)> { | 211 | pub fn approximately_resolve_symbol( |
208 | self.imp.approximately_resolve_symbol(file_id, offset, token) | 212 | &self, |
213 | file_id: FileId, | ||
214 | offset: TextUnit, | ||
215 | token: &JobToken, | ||
216 | ) -> Vec<(FileId, FileSymbol)> { | ||
217 | self.imp | ||
218 | .approximately_resolve_symbol(file_id, offset, token) | ||
209 | } | 219 | } |
210 | pub fn parent_module(&self, file_id: FileId) -> Vec<(FileId, FileSymbol)> { | 220 | pub fn parent_module(&self, file_id: FileId) -> Vec<(FileId, FileSymbol)> { |
211 | self.imp.parent_module(file_id) | 221 | self.imp.parent_module(file_id) |
@@ -239,15 +249,19 @@ impl Analysis { | |||
239 | ra_editor::folding_ranges(&file) | 249 | ra_editor::folding_ranges(&file) |
240 | } | 250 | } |
241 | 251 | ||
242 | pub fn resolve_callable(&self, file_id: FileId, offset: TextUnit, token: &JobToken) | 252 | pub fn resolve_callable( |
243 | -> Option<(FnDescriptor, Option<usize>)> { | 253 | &self, |
254 | file_id: FileId, | ||
255 | offset: TextUnit, | ||
256 | token: &JobToken, | ||
257 | ) -> Option<(FnDescriptor, Option<usize>)> { | ||
244 | self.imp.resolve_callable(file_id, offset, token) | 258 | self.imp.resolve_callable(file_id, offset, token) |
245 | } | 259 | } |
246 | } | 260 | } |
247 | 261 | ||
248 | #[derive(Debug)] | 262 | #[derive(Debug)] |
249 | pub struct LibraryData { | 263 | pub struct LibraryData { |
250 | root: roots::ReadonlySourceRoot | 264 | root: roots::ReadonlySourceRoot, |
251 | } | 265 | } |
252 | 266 | ||
253 | impl LibraryData { | 267 | impl LibraryData { |