diff options
author | Aleksey Kladov <[email protected]> | 2019-02-08 08:52:18 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-02-08 11:34:30 +0000 |
commit | 842e8001b287b0e3d77215235ae96a3bd8944207 (patch) | |
tree | 671c17814199a95510121c359191a3217ba2c207 /crates/ra_ide_api/src/lib.rs | |
parent | 9a1d2a46c249fa81294c156b9e23b624e14495cd (diff) |
move changes to a separate file
Diffstat (limited to 'crates/ra_ide_api/src/lib.rs')
-rw-r--r-- | crates/ra_ide_api/src/lib.rs | 159 |
1 files changed, 4 insertions, 155 deletions
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 68d59aae1..22a601ec8 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs | |||
@@ -18,6 +18,7 @@ mod imp; | |||
18 | pub mod mock_analysis; | 18 | pub mod mock_analysis; |
19 | mod symbol_index; | 19 | mod symbol_index; |
20 | mod navigation_target; | 20 | mod navigation_target; |
21 | mod change; | ||
21 | 22 | ||
22 | mod status; | 23 | mod status; |
23 | mod completion; | 24 | mod completion; |
@@ -35,7 +36,7 @@ mod assists; | |||
35 | #[cfg(test)] | 36 | #[cfg(test)] |
36 | mod marks; | 37 | mod marks; |
37 | 38 | ||
38 | use std::{fmt, sync::Arc}; | 39 | use std::sync::Arc; |
39 | 40 | ||
40 | use ra_syntax::{SourceFile, TreeArc, TextRange, TextUnit}; | 41 | use ra_syntax::{SourceFile, TreeArc, TextRange, TextUnit}; |
41 | use ra_text_edit::TextEdit; | 42 | use ra_text_edit::TextEdit; |
@@ -43,12 +44,10 @@ use ra_db::{ | |||
43 | SourceDatabase, CheckCanceled, | 44 | SourceDatabase, CheckCanceled, |
44 | salsa::{self, ParallelDatabase}, | 45 | salsa::{self, ParallelDatabase}, |
45 | }; | 46 | }; |
46 | use rayon::prelude::*; | ||
47 | use relative_path::RelativePathBuf; | 47 | use relative_path::RelativePathBuf; |
48 | use rustc_hash::FxHashMap; | ||
49 | 48 | ||
50 | use crate::{ | 49 | use crate::{ |
51 | symbol_index::{FileSymbol, SymbolIndex}, | 50 | symbol_index::FileSymbol, |
52 | db::LineIndexDatabase, | 51 | db::LineIndexDatabase, |
53 | }; | 52 | }; |
54 | 53 | ||
@@ -56,6 +55,7 @@ pub use crate::{ | |||
56 | completion::{CompletionItem, CompletionItemKind, InsertTextFormat}, | 55 | completion::{CompletionItem, CompletionItemKind, InsertTextFormat}, |
57 | runnables::{Runnable, RunnableKind}, | 56 | runnables::{Runnable, RunnableKind}, |
58 | navigation_target::NavigationTarget, | 57 | navigation_target::NavigationTarget, |
58 | change::{AnalysisChange, LibraryData}, | ||
59 | }; | 59 | }; |
60 | pub use ra_ide_api_light::{ | 60 | pub use ra_ide_api_light::{ |
61 | Fold, FoldKind, HighlightedRange, Severity, StructureNode, | 61 | Fold, FoldKind, HighlightedRange, Severity, StructureNode, |
@@ -74,115 +74,6 @@ static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; | |||
74 | 74 | ||
75 | pub type Cancelable<T> = Result<T, Canceled>; | 75 | pub type Cancelable<T> = Result<T, Canceled>; |
76 | 76 | ||
77 | #[derive(Default)] | ||
78 | pub struct AnalysisChange { | ||
79 | new_roots: Vec<(SourceRootId, bool)>, | ||
80 | roots_changed: FxHashMap<SourceRootId, RootChange>, | ||
81 | files_changed: Vec<(FileId, Arc<String>)>, | ||
82 | libraries_added: Vec<LibraryData>, | ||
83 | crate_graph: Option<CrateGraph>, | ||
84 | } | ||
85 | |||
86 | #[derive(Default)] | ||
87 | struct RootChange { | ||
88 | added: Vec<AddFile>, | ||
89 | removed: Vec<RemoveFile>, | ||
90 | } | ||
91 | |||
92 | #[derive(Debug)] | ||
93 | struct AddFile { | ||
94 | file_id: FileId, | ||
95 | path: RelativePathBuf, | ||
96 | text: Arc<String>, | ||
97 | } | ||
98 | |||
99 | #[derive(Debug)] | ||
100 | struct RemoveFile { | ||
101 | file_id: FileId, | ||
102 | path: RelativePathBuf, | ||
103 | } | ||
104 | |||
105 | impl fmt::Debug for AnalysisChange { | ||
106 | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||
107 | let mut d = fmt.debug_struct("AnalysisChange"); | ||
108 | if !self.new_roots.is_empty() { | ||
109 | d.field("new_roots", &self.new_roots); | ||
110 | } | ||
111 | if !self.roots_changed.is_empty() { | ||
112 | d.field("roots_changed", &self.roots_changed); | ||
113 | } | ||
114 | if !self.files_changed.is_empty() { | ||
115 | d.field("files_changed", &self.files_changed.len()); | ||
116 | } | ||
117 | if !self.libraries_added.is_empty() { | ||
118 | d.field("libraries_added", &self.libraries_added.len()); | ||
119 | } | ||
120 | if self.crate_graph.is_none() { | ||
121 | d.field("crate_graph", &self.crate_graph); | ||
122 | } | ||
123 | d.finish() | ||
124 | } | ||
125 | } | ||
126 | |||
127 | impl fmt::Debug for RootChange { | ||
128 | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||
129 | fmt.debug_struct("AnalysisChange") | ||
130 | .field("added", &self.added.len()) | ||
131 | .field("removed", &self.removed.len()) | ||
132 | .finish() | ||
133 | } | ||
134 | } | ||
135 | |||
136 | impl AnalysisChange { | ||
137 | pub fn new() -> AnalysisChange { | ||
138 | AnalysisChange::default() | ||
139 | } | ||
140 | |||
141 | pub fn add_root(&mut self, root_id: SourceRootId, is_local: bool) { | ||
142 | self.new_roots.push((root_id, is_local)); | ||
143 | } | ||
144 | |||
145 | pub fn add_file( | ||
146 | &mut self, | ||
147 | root_id: SourceRootId, | ||
148 | file_id: FileId, | ||
149 | path: RelativePathBuf, | ||
150 | text: Arc<String>, | ||
151 | ) { | ||
152 | let file = AddFile { | ||
153 | file_id, | ||
154 | path, | ||
155 | text, | ||
156 | }; | ||
157 | self.roots_changed | ||
158 | .entry(root_id) | ||
159 | .or_default() | ||
160 | .added | ||
161 | .push(file); | ||
162 | } | ||
163 | |||
164 | pub fn change_file(&mut self, file_id: FileId, new_text: Arc<String>) { | ||
165 | self.files_changed.push((file_id, new_text)) | ||
166 | } | ||
167 | |||
168 | pub fn remove_file(&mut self, root_id: SourceRootId, file_id: FileId, path: RelativePathBuf) { | ||
169 | let file = RemoveFile { file_id, path }; | ||
170 | self.roots_changed | ||
171 | .entry(root_id) | ||
172 | .or_default() | ||
173 | .removed | ||
174 | .push(file); | ||
175 | } | ||
176 | |||
177 | pub fn add_library(&mut self, data: LibraryData) { | ||
178 | self.libraries_added.push(data) | ||
179 | } | ||
180 | |||
181 | pub fn set_crate_graph(&mut self, graph: CrateGraph) { | ||
182 | self.crate_graph = Some(graph); | ||
183 | } | ||
184 | } | ||
185 | |||
186 | #[derive(Debug)] | 77 | #[derive(Debug)] |
187 | pub struct SourceChange { | 78 | pub struct SourceChange { |
188 | pub label: String, | 79 | pub label: String, |
@@ -508,48 +399,6 @@ impl Analysis { | |||
508 | } | 399 | } |
509 | } | 400 | } |
510 | 401 | ||
511 | pub struct LibraryData { | ||
512 | root_id: SourceRootId, | ||
513 | root_change: RootChange, | ||
514 | symbol_index: SymbolIndex, | ||
515 | } | ||
516 | |||
517 | impl fmt::Debug for LibraryData { | ||
518 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
519 | f.debug_struct("LibraryData") | ||
520 | .field("root_id", &self.root_id) | ||
521 | .field("root_change", &self.root_change) | ||
522 | .field("n_symbols", &self.symbol_index.len()) | ||
523 | .finish() | ||
524 | } | ||
525 | } | ||
526 | |||
527 | impl LibraryData { | ||
528 | pub fn prepare( | ||
529 | root_id: SourceRootId, | ||
530 | files: Vec<(FileId, RelativePathBuf, Arc<String>)>, | ||
531 | ) -> LibraryData { | ||
532 | let symbol_index = SymbolIndex::for_files(files.par_iter().map(|(file_id, _, text)| { | ||
533 | let file = SourceFile::parse(text); | ||
534 | (*file_id, file) | ||
535 | })); | ||
536 | let mut root_change = RootChange::default(); | ||
537 | root_change.added = files | ||
538 | .into_iter() | ||
539 | .map(|(file_id, path, text)| AddFile { | ||
540 | file_id, | ||
541 | path, | ||
542 | text, | ||
543 | }) | ||
544 | .collect(); | ||
545 | LibraryData { | ||
546 | root_id, | ||
547 | root_change, | ||
548 | symbol_index, | ||
549 | } | ||
550 | } | ||
551 | } | ||
552 | |||
553 | #[test] | 402 | #[test] |
554 | fn analysis_is_send() { | 403 | fn analysis_is_send() { |
555 | fn is_send<T: Send>() {} | 404 | fn is_send<T: Send>() {} |