aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src/lib.rs')
-rw-r--r--crates/ra_analysis/src/lib.rs78
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 @@
1extern crate parking_lot; 1extern crate parking_lot;
2#[macro_use] 2#[macro_use]
3extern crate log; 3extern crate log;
4extern crate fst;
4extern crate once_cell; 5extern crate once_cell;
5extern crate ra_syntax;
6extern crate ra_editor; 6extern crate ra_editor;
7extern crate fst; 7extern crate ra_syntax;
8extern crate rayon; 8extern crate rayon;
9extern crate relative_path; 9extern crate relative_path;
10#[macro_use] 10#[macro_use]
11extern crate crossbeam_channel; 11extern crate crossbeam_channel;
12extern crate im; 12extern crate im;
13extern crate salsa;
14extern crate rustc_hash; 13extern crate rustc_hash;
14extern crate salsa;
15 15
16mod symbol_index; 16mod db;
17mod module_map; 17mod descriptors;
18mod imp; 18mod imp;
19mod job; 19mod job;
20mod module_map;
20mod roots; 21mod roots;
21mod db; 22mod symbol_index;
22mod descriptors;
23 23
24use std::{ 24use std::{fmt::Debug, sync::Arc};
25 sync::Arc,
26 fmt::Debug,
27};
28 25
26use crate::imp::{AnalysisHostImpl, AnalysisImpl, FileResolverImp};
27use ra_syntax::{AtomEdit, File, TextRange, TextUnit};
29use relative_path::{RelativePath, RelativePathBuf}; 28use relative_path::{RelativePath, RelativePathBuf};
30use ra_syntax::{File, TextRange, TextUnit, AtomEdit};
31use rustc_hash::FxHashMap; 29use rustc_hash::FxHashMap;
32use crate::imp::{AnalysisImpl, AnalysisHostImpl, FileResolverImp};
33 30
34pub use ra_editor::{
35 StructureNode, LineIndex, FileSymbol,
36 Runnable, RunnableKind, HighlightedRange, CompletionItem,
37 Fold, FoldKind
38};
39pub use crate::{ 31pub use crate::{
40 job::{JobToken, JobHandle},
41 descriptors::FnDescriptor, 32 descriptors::FnDescriptor,
33 job::{JobHandle, JobToken},
34};
35pub 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)]
61pub struct AnalysisHost { 57pub struct AnalysisHost {
62 imp: AnalysisHostImpl 58 imp: AnalysisHostImpl,
63} 59}
64 60
65impl AnalysisHost { 61impl 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)]
165pub struct Analysis { 165pub struct Analysis {
166 imp: AnalysisImpl 166 imp: AnalysisImpl,
167} 167}
168 168
169impl Analysis { 169impl 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)]
249pub struct LibraryData { 263pub struct LibraryData {
250 root: roots::ReadonlySourceRoot 264 root: roots::ReadonlySourceRoot,
251} 265}
252 266
253impl LibraryData { 267impl LibraryData {