diff options
-rw-r--r-- | crates/rust-analyzer/src/cargo_target_spec.rs | 2 | ||||
-rw-r--r-- | crates/rust-analyzer/src/from_proto.rs | 4 | ||||
-rw-r--r-- | crates/rust-analyzer/src/global_state.rs | 14 | ||||
-rw-r--r-- | crates/rust-analyzer/src/handlers.rs | 142 | ||||
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 2 | ||||
-rw-r--r-- | crates/rust-analyzer/src/to_proto.rs | 8 |
6 files changed, 84 insertions, 88 deletions
diff --git a/crates/rust-analyzer/src/cargo_target_spec.rs b/crates/rust-analyzer/src/cargo_target_spec.rs index e98d0f868..e4dd5d92d 100644 --- a/crates/rust-analyzer/src/cargo_target_spec.rs +++ b/crates/rust-analyzer/src/cargo_target_spec.rs | |||
@@ -94,7 +94,7 @@ impl CargoTargetSpec { | |||
94 | global_state_snapshot: &GlobalStateSnapshot, | 94 | global_state_snapshot: &GlobalStateSnapshot, |
95 | file_id: FileId, | 95 | file_id: FileId, |
96 | ) -> Result<Option<CargoTargetSpec>> { | 96 | ) -> Result<Option<CargoTargetSpec>> { |
97 | let crate_id = match global_state_snapshot.analysis().crate_for(file_id)?.first() { | 97 | let crate_id = match global_state_snapshot.analysis.crate_for(file_id)?.first() { |
98 | Some(crate_id) => *crate_id, | 98 | Some(crate_id) => *crate_id, |
99 | None => return Ok(None), | 99 | None => return Ok(None), |
100 | }; | 100 | }; |
diff --git a/crates/rust-analyzer/src/from_proto.rs b/crates/rust-analyzer/src/from_proto.rs index 40d440c67..15b281103 100644 --- a/crates/rust-analyzer/src/from_proto.rs +++ b/crates/rust-analyzer/src/from_proto.rs | |||
@@ -37,7 +37,7 @@ pub(crate) fn file_position( | |||
37 | tdpp: lsp_types::TextDocumentPositionParams, | 37 | tdpp: lsp_types::TextDocumentPositionParams, |
38 | ) -> Result<FilePosition> { | 38 | ) -> Result<FilePosition> { |
39 | let file_id = file_id(world, &tdpp.text_document.uri)?; | 39 | let file_id = file_id(world, &tdpp.text_document.uri)?; |
40 | let line_index = world.analysis().file_line_index(file_id)?; | 40 | let line_index = world.analysis.file_line_index(file_id)?; |
41 | let offset = offset(&*line_index, tdpp.position); | 41 | let offset = offset(&*line_index, tdpp.position); |
42 | Ok(FilePosition { file_id, offset }) | 42 | Ok(FilePosition { file_id, offset }) |
43 | } | 43 | } |
@@ -48,7 +48,7 @@ pub(crate) fn file_range( | |||
48 | range: lsp_types::Range, | 48 | range: lsp_types::Range, |
49 | ) -> Result<FileRange> { | 49 | ) -> Result<FileRange> { |
50 | let file_id = file_id(world, &text_document_identifier.uri)?; | 50 | let file_id = file_id(world, &text_document_identifier.uri)?; |
51 | let line_index = world.analysis().file_line_index(file_id)?; | 51 | let line_index = world.analysis.file_line_index(file_id)?; |
52 | let range = text_range(&line_index, range); | 52 | let range = text_range(&line_index, range); |
53 | Ok(FileRange { file_id, range }) | 53 | Ok(FileRange { file_id, range }) |
54 | } | 54 | } |
diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs index 0b42b88ac..87f3fe4db 100644 --- a/crates/rust-analyzer/src/global_state.rs +++ b/crates/rust-analyzer/src/global_state.rs | |||
@@ -60,7 +60,6 @@ impl Default for Status { | |||
60 | /// incremental salsa database. | 60 | /// incremental salsa database. |
61 | pub(crate) struct GlobalState { | 61 | pub(crate) struct GlobalState { |
62 | pub(crate) config: Config, | 62 | pub(crate) config: Config, |
63 | pub(crate) workspaces: Arc<Vec<ProjectWorkspace>>, | ||
64 | pub(crate) analysis_host: AnalysisHost, | 63 | pub(crate) analysis_host: AnalysisHost, |
65 | pub(crate) loader: Box<dyn vfs::loader::Handle>, | 64 | pub(crate) loader: Box<dyn vfs::loader::Handle>, |
66 | pub(crate) task_receiver: Receiver<vfs::loader::Message>, | 65 | pub(crate) task_receiver: Receiver<vfs::loader::Message>, |
@@ -70,19 +69,20 @@ pub(crate) struct GlobalState { | |||
70 | pub(crate) vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>, | 69 | pub(crate) vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>, |
71 | pub(crate) status: Status, | 70 | pub(crate) status: Status, |
72 | pub(crate) req_queue: ReqQueue, | 71 | pub(crate) req_queue: ReqQueue, |
73 | pub(crate) latest_requests: Arc<RwLock<LatestRequests>>, | 72 | latest_requests: Arc<RwLock<LatestRequests>>, |
74 | source_root_config: SourceRootConfig, | 73 | source_root_config: SourceRootConfig, |
75 | _proc_macro_client: ProcMacroClient, | 74 | _proc_macro_client: ProcMacroClient, |
75 | workspaces: Arc<Vec<ProjectWorkspace>>, | ||
76 | } | 76 | } |
77 | 77 | ||
78 | /// An immutable snapshot of the world's state at a point in time. | 78 | /// An immutable snapshot of the world's state at a point in time. |
79 | pub(crate) struct GlobalStateSnapshot { | 79 | pub(crate) struct GlobalStateSnapshot { |
80 | pub(crate) config: Config, | 80 | pub(crate) config: Config, |
81 | pub(crate) workspaces: Arc<Vec<ProjectWorkspace>>, | ||
82 | pub(crate) analysis: Analysis, | 81 | pub(crate) analysis: Analysis, |
83 | pub(crate) check_fixes: CheckFixes, | 82 | pub(crate) check_fixes: CheckFixes, |
84 | pub(crate) latest_requests: Arc<RwLock<LatestRequests>>, | 83 | pub(crate) latest_requests: Arc<RwLock<LatestRequests>>, |
85 | vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>, | 84 | vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>, |
85 | workspaces: Arc<Vec<ProjectWorkspace>>, | ||
86 | } | 86 | } |
87 | 87 | ||
88 | impl GlobalState { | 88 | impl GlobalState { |
@@ -149,7 +149,6 @@ impl GlobalState { | |||
149 | analysis_host.apply_change(change); | 149 | analysis_host.apply_change(change); |
150 | let mut res = GlobalState { | 150 | let mut res = GlobalState { |
151 | config, | 151 | config, |
152 | workspaces: Arc::new(workspaces), | ||
153 | analysis_host, | 152 | analysis_host, |
154 | loader, | 153 | loader, |
155 | task_receiver, | 154 | task_receiver, |
@@ -162,6 +161,7 @@ impl GlobalState { | |||
162 | latest_requests: Default::default(), | 161 | latest_requests: Default::default(), |
163 | source_root_config: project_folders.source_root_config, | 162 | source_root_config: project_folders.source_root_config, |
164 | _proc_macro_client: proc_macro_client, | 163 | _proc_macro_client: proc_macro_client, |
164 | workspaces: Arc::new(workspaces), | ||
165 | }; | 165 | }; |
166 | res.process_changes(); | 166 | res.process_changes(); |
167 | res | 167 | res |
@@ -240,10 +240,6 @@ impl GlobalState { | |||
240 | } | 240 | } |
241 | 241 | ||
242 | impl GlobalStateSnapshot { | 242 | impl GlobalStateSnapshot { |
243 | pub(crate) fn analysis(&self) -> &Analysis { | ||
244 | &self.analysis | ||
245 | } | ||
246 | |||
247 | pub(crate) fn url_to_file_id(&self, url: &Url) -> Result<FileId> { | 243 | pub(crate) fn url_to_file_id(&self, url: &Url) -> Result<FileId> { |
248 | let path = from_proto::abs_path(url)?; | 244 | let path = from_proto::abs_path(url)?; |
249 | let path = path.into(); | 245 | let path = path.into(); |
@@ -272,7 +268,7 @@ impl GlobalStateSnapshot { | |||
272 | &self, | 268 | &self, |
273 | crate_id: CrateId, | 269 | crate_id: CrateId, |
274 | ) -> Option<(&CargoWorkspace, Target)> { | 270 | ) -> Option<(&CargoWorkspace, Target)> { |
275 | let file_id = self.analysis().crate_root(crate_id).ok()?; | 271 | let file_id = self.analysis.crate_root(crate_id).ok()?; |
276 | let path = self.vfs.read().0.file_path(file_id); | 272 | let path = self.vfs.read().0.file_path(file_id); |
277 | let path = path.as_path()?; | 273 | let path = path.as_path()?; |
278 | self.workspaces.iter().find_map(|ws| match ws { | 274 | self.workspaces.iter().find_map(|ws| match ws { |
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index b38755b79..b2ff9a157 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs | |||
@@ -56,9 +56,9 @@ pub(crate) fn handle_syntax_tree( | |||
56 | ) -> Result<String> { | 56 | ) -> Result<String> { |
57 | let _p = profile("handle_syntax_tree"); | 57 | let _p = profile("handle_syntax_tree"); |
58 | let id = from_proto::file_id(&snap, ¶ms.text_document.uri)?; | 58 | let id = from_proto::file_id(&snap, ¶ms.text_document.uri)?; |
59 | let line_index = snap.analysis().file_line_index(id)?; | 59 | let line_index = snap.analysis.file_line_index(id)?; |
60 | let text_range = params.range.map(|r| from_proto::text_range(&line_index, r)); | 60 | let text_range = params.range.map(|r| from_proto::text_range(&line_index, r)); |
61 | let res = snap.analysis().syntax_tree(id, text_range)?; | 61 | let res = snap.analysis.syntax_tree(id, text_range)?; |
62 | Ok(res) | 62 | Ok(res) |
63 | } | 63 | } |
64 | 64 | ||
@@ -68,10 +68,10 @@ pub(crate) fn handle_expand_macro( | |||
68 | ) -> Result<Option<lsp_ext::ExpandedMacro>> { | 68 | ) -> Result<Option<lsp_ext::ExpandedMacro>> { |
69 | let _p = profile("handle_expand_macro"); | 69 | let _p = profile("handle_expand_macro"); |
70 | let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?; | 70 | let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?; |
71 | let line_index = snap.analysis().file_line_index(file_id)?; | 71 | let line_index = snap.analysis.file_line_index(file_id)?; |
72 | let offset = from_proto::offset(&line_index, params.position); | 72 | let offset = from_proto::offset(&line_index, params.position); |
73 | 73 | ||
74 | let res = snap.analysis().expand_macro(FilePosition { file_id, offset })?; | 74 | let res = snap.analysis.expand_macro(FilePosition { file_id, offset })?; |
75 | Ok(res.map(|it| lsp_ext::ExpandedMacro { name: it.name, expansion: it.expansion })) | 75 | Ok(res.map(|it| lsp_ext::ExpandedMacro { name: it.name, expansion: it.expansion })) |
76 | } | 76 | } |
77 | 77 | ||
@@ -81,7 +81,7 @@ pub(crate) fn handle_selection_range( | |||
81 | ) -> Result<Option<Vec<lsp_types::SelectionRange>>> { | 81 | ) -> Result<Option<Vec<lsp_types::SelectionRange>>> { |
82 | let _p = profile("handle_selection_range"); | 82 | let _p = profile("handle_selection_range"); |
83 | let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?; | 83 | let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?; |
84 | let line_index = snap.analysis().file_line_index(file_id)?; | 84 | let line_index = snap.analysis.file_line_index(file_id)?; |
85 | let res: Result<Vec<lsp_types::SelectionRange>> = params | 85 | let res: Result<Vec<lsp_types::SelectionRange>> = params |
86 | .positions | 86 | .positions |
87 | .into_iter() | 87 | .into_iter() |
@@ -93,7 +93,7 @@ pub(crate) fn handle_selection_range( | |||
93 | loop { | 93 | loop { |
94 | ranges.push(range); | 94 | ranges.push(range); |
95 | let frange = FileRange { file_id, range }; | 95 | let frange = FileRange { file_id, range }; |
96 | let next = snap.analysis().extend_selection(frange)?; | 96 | let next = snap.analysis.extend_selection(frange)?; |
97 | if next == range { | 97 | if next == range { |
98 | break; | 98 | break; |
99 | } else { | 99 | } else { |
@@ -124,13 +124,13 @@ pub(crate) fn handle_matching_brace( | |||
124 | ) -> Result<Vec<Position>> { | 124 | ) -> Result<Vec<Position>> { |
125 | let _p = profile("handle_matching_brace"); | 125 | let _p = profile("handle_matching_brace"); |
126 | let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?; | 126 | let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?; |
127 | let line_index = snap.analysis().file_line_index(file_id)?; | 127 | let line_index = snap.analysis.file_line_index(file_id)?; |
128 | let res = params | 128 | let res = params |
129 | .positions | 129 | .positions |
130 | .into_iter() | 130 | .into_iter() |
131 | .map(|position| { | 131 | .map(|position| { |
132 | let offset = from_proto::offset(&line_index, position); | 132 | let offset = from_proto::offset(&line_index, position); |
133 | let offset = match snap.analysis().matching_brace(FilePosition { file_id, offset }) { | 133 | let offset = match snap.analysis.matching_brace(FilePosition { file_id, offset }) { |
134 | Ok(Some(matching_brace_offset)) => matching_brace_offset, | 134 | Ok(Some(matching_brace_offset)) => matching_brace_offset, |
135 | Err(_) | Ok(None) => offset, | 135 | Err(_) | Ok(None) => offset, |
136 | }; | 136 | }; |
@@ -146,12 +146,12 @@ pub(crate) fn handle_join_lines( | |||
146 | ) -> Result<Vec<lsp_types::TextEdit>> { | 146 | ) -> Result<Vec<lsp_types::TextEdit>> { |
147 | let _p = profile("handle_join_lines"); | 147 | let _p = profile("handle_join_lines"); |
148 | let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?; | 148 | let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?; |
149 | let line_index = snap.analysis().file_line_index(file_id)?; | 149 | let line_index = snap.analysis.file_line_index(file_id)?; |
150 | let line_endings = snap.file_line_endings(file_id); | 150 | let line_endings = snap.file_line_endings(file_id); |
151 | let mut res = TextEdit::default(); | 151 | let mut res = TextEdit::default(); |
152 | for range in params.ranges { | 152 | for range in params.ranges { |
153 | let range = from_proto::text_range(&line_index, range); | 153 | let range = from_proto::text_range(&line_index, range); |
154 | let edit = snap.analysis().join_lines(FileRange { file_id, range })?; | 154 | let edit = snap.analysis.join_lines(FileRange { file_id, range })?; |
155 | match res.union(edit) { | 155 | match res.union(edit) { |
156 | Ok(()) => (), | 156 | Ok(()) => (), |
157 | Err(_edit) => { | 157 | Err(_edit) => { |
@@ -169,11 +169,11 @@ pub(crate) fn handle_on_enter( | |||
169 | ) -> Result<Option<Vec<lsp_ext::SnippetTextEdit>>> { | 169 | ) -> Result<Option<Vec<lsp_ext::SnippetTextEdit>>> { |
170 | let _p = profile("handle_on_enter"); | 170 | let _p = profile("handle_on_enter"); |
171 | let position = from_proto::file_position(&snap, params)?; | 171 | let position = from_proto::file_position(&snap, params)?; |
172 | let edit = match snap.analysis().on_enter(position)? { | 172 | let edit = match snap.analysis.on_enter(position)? { |
173 | None => return Ok(None), | 173 | None => return Ok(None), |
174 | Some(it) => it, | 174 | Some(it) => it, |
175 | }; | 175 | }; |
176 | let line_index = snap.analysis().file_line_index(position.file_id)?; | 176 | let line_index = snap.analysis.file_line_index(position.file_id)?; |
177 | let line_endings = snap.file_line_endings(position.file_id); | 177 | let line_endings = snap.file_line_endings(position.file_id); |
178 | let edit = to_proto::snippet_text_edit_vec(&line_index, line_endings, true, edit); | 178 | let edit = to_proto::snippet_text_edit_vec(&line_index, line_endings, true, edit); |
179 | Ok(Some(edit)) | 179 | Ok(Some(edit)) |
@@ -186,7 +186,7 @@ pub(crate) fn handle_on_type_formatting( | |||
186 | ) -> Result<Option<Vec<lsp_types::TextEdit>>> { | 186 | ) -> Result<Option<Vec<lsp_types::TextEdit>>> { |
187 | let _p = profile("handle_on_type_formatting"); | 187 | let _p = profile("handle_on_type_formatting"); |
188 | let mut position = from_proto::file_position(&snap, params.text_document_position)?; | 188 | let mut position = from_proto::file_position(&snap, params.text_document_position)?; |
189 | let line_index = snap.analysis().file_line_index(position.file_id)?; | 189 | let line_index = snap.analysis.file_line_index(position.file_id)?; |
190 | let line_endings = snap.file_line_endings(position.file_id); | 190 | let line_endings = snap.file_line_endings(position.file_id); |
191 | 191 | ||
192 | // in `ra_ide`, the `on_type` invariant is that | 192 | // in `ra_ide`, the `on_type` invariant is that |
@@ -194,7 +194,7 @@ pub(crate) fn handle_on_type_formatting( | |||
194 | position.offset -= TextSize::of('.'); | 194 | position.offset -= TextSize::of('.'); |
195 | let char_typed = params.ch.chars().next().unwrap_or('\0'); | 195 | let char_typed = params.ch.chars().next().unwrap_or('\0'); |
196 | assert!({ | 196 | assert!({ |
197 | let text = snap.analysis().file_text(position.file_id)?; | 197 | let text = snap.analysis.file_text(position.file_id)?; |
198 | text[usize::from(position.offset)..].starts_with(char_typed) | 198 | text[usize::from(position.offset)..].starts_with(char_typed) |
199 | }); | 199 | }); |
200 | 200 | ||
@@ -206,7 +206,7 @@ pub(crate) fn handle_on_type_formatting( | |||
206 | return Ok(None); | 206 | return Ok(None); |
207 | } | 207 | } |
208 | 208 | ||
209 | let edit = snap.analysis().on_char_typed(position, char_typed)?; | 209 | let edit = snap.analysis.on_char_typed(position, char_typed)?; |
210 | let mut edit = match edit { | 210 | let mut edit = match edit { |
211 | Some(it) => it, | 211 | Some(it) => it, |
212 | None => return Ok(None), | 212 | None => return Ok(None), |
@@ -225,11 +225,11 @@ pub(crate) fn handle_document_symbol( | |||
225 | ) -> Result<Option<lsp_types::DocumentSymbolResponse>> { | 225 | ) -> Result<Option<lsp_types::DocumentSymbolResponse>> { |
226 | let _p = profile("handle_document_symbol"); | 226 | let _p = profile("handle_document_symbol"); |
227 | let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?; | 227 | let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?; |
228 | let line_index = snap.analysis().file_line_index(file_id)?; | 228 | let line_index = snap.analysis.file_line_index(file_id)?; |
229 | 229 | ||
230 | let mut parents: Vec<(DocumentSymbol, Option<usize>)> = Vec::new(); | 230 | let mut parents: Vec<(DocumentSymbol, Option<usize>)> = Vec::new(); |
231 | 231 | ||
232 | for symbol in snap.analysis().file_structure(file_id)? { | 232 | for symbol in snap.analysis.file_structure(file_id)? { |
233 | let doc_symbol = DocumentSymbol { | 233 | let doc_symbol = DocumentSymbol { |
234 | name: symbol.label, | 234 | name: symbol.label, |
235 | detail: symbol.detail, | 235 | detail: symbol.detail, |
@@ -317,7 +317,7 @@ pub(crate) fn handle_workspace_symbol( | |||
317 | 317 | ||
318 | fn exec_query(snap: &GlobalStateSnapshot, query: Query) -> Result<Vec<SymbolInformation>> { | 318 | fn exec_query(snap: &GlobalStateSnapshot, query: Query) -> Result<Vec<SymbolInformation>> { |
319 | let mut res = Vec::new(); | 319 | let mut res = Vec::new(); |
320 | for nav in snap.analysis().symbol_search(query)? { | 320 | for nav in snap.analysis.symbol_search(query)? { |
321 | let info = SymbolInformation { | 321 | let info = SymbolInformation { |
322 | name: nav.name().to_string(), | 322 | name: nav.name().to_string(), |
323 | kind: to_proto::symbol_kind(nav.kind()), | 323 | kind: to_proto::symbol_kind(nav.kind()), |
@@ -337,7 +337,7 @@ pub(crate) fn handle_goto_definition( | |||
337 | ) -> Result<Option<lsp_types::GotoDefinitionResponse>> { | 337 | ) -> Result<Option<lsp_types::GotoDefinitionResponse>> { |
338 | let _p = profile("handle_goto_definition"); | 338 | let _p = profile("handle_goto_definition"); |
339 | let position = from_proto::file_position(&snap, params.text_document_position_params)?; | 339 | let position = from_proto::file_position(&snap, params.text_document_position_params)?; |
340 | let nav_info = match snap.analysis().goto_definition(position)? { | 340 | let nav_info = match snap.analysis.goto_definition(position)? { |
341 | None => return Ok(None), | 341 | None => return Ok(None), |
342 | Some(it) => it, | 342 | Some(it) => it, |
343 | }; | 343 | }; |
@@ -352,7 +352,7 @@ pub(crate) fn handle_goto_implementation( | |||
352 | ) -> Result<Option<lsp_types::request::GotoImplementationResponse>> { | 352 | ) -> Result<Option<lsp_types::request::GotoImplementationResponse>> { |
353 | let _p = profile("handle_goto_implementation"); | 353 | let _p = profile("handle_goto_implementation"); |
354 | let position = from_proto::file_position(&snap, params.text_document_position_params)?; | 354 | let position = from_proto::file_position(&snap, params.text_document_position_params)?; |
355 | let nav_info = match snap.analysis().goto_implementation(position)? { | 355 | let nav_info = match snap.analysis.goto_implementation(position)? { |
356 | None => return Ok(None), | 356 | None => return Ok(None), |
357 | Some(it) => it, | 357 | Some(it) => it, |
358 | }; | 358 | }; |
@@ -367,7 +367,7 @@ pub(crate) fn handle_goto_type_definition( | |||
367 | ) -> Result<Option<lsp_types::request::GotoTypeDefinitionResponse>> { | 367 | ) -> Result<Option<lsp_types::request::GotoTypeDefinitionResponse>> { |
368 | let _p = profile("handle_goto_type_definition"); | 368 | let _p = profile("handle_goto_type_definition"); |
369 | let position = from_proto::file_position(&snap, params.text_document_position_params)?; | 369 | let position = from_proto::file_position(&snap, params.text_document_position_params)?; |
370 | let nav_info = match snap.analysis().goto_type_definition(position)? { | 370 | let nav_info = match snap.analysis.goto_type_definition(position)? { |
371 | None => return Ok(None), | 371 | None => return Ok(None), |
372 | Some(it) => it, | 372 | Some(it) => it, |
373 | }; | 373 | }; |
@@ -382,7 +382,7 @@ pub(crate) fn handle_parent_module( | |||
382 | ) -> Result<Option<lsp_types::GotoDefinitionResponse>> { | 382 | ) -> Result<Option<lsp_types::GotoDefinitionResponse>> { |
383 | let _p = profile("handle_parent_module"); | 383 | let _p = profile("handle_parent_module"); |
384 | let position = from_proto::file_position(&snap, params)?; | 384 | let position = from_proto::file_position(&snap, params)?; |
385 | let navs = snap.analysis().parent_module(position)?; | 385 | let navs = snap.analysis.parent_module(position)?; |
386 | let res = to_proto::goto_definition_response(&snap, None, navs)?; | 386 | let res = to_proto::goto_definition_response(&snap, None, navs)?; |
387 | Ok(Some(res)) | 387 | Ok(Some(res)) |
388 | } | 388 | } |
@@ -393,11 +393,11 @@ pub(crate) fn handle_runnables( | |||
393 | ) -> Result<Vec<lsp_ext::Runnable>> { | 393 | ) -> Result<Vec<lsp_ext::Runnable>> { |
394 | let _p = profile("handle_runnables"); | 394 | let _p = profile("handle_runnables"); |
395 | let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?; | 395 | let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?; |
396 | let line_index = snap.analysis().file_line_index(file_id)?; | 396 | let line_index = snap.analysis.file_line_index(file_id)?; |
397 | let offset = params.position.map(|it| from_proto::offset(&line_index, it)); | 397 | let offset = params.position.map(|it| from_proto::offset(&line_index, it)); |
398 | let mut res = Vec::new(); | 398 | let mut res = Vec::new(); |
399 | let cargo_spec = CargoTargetSpec::for_file(&snap, file_id)?; | 399 | let cargo_spec = CargoTargetSpec::for_file(&snap, file_id)?; |
400 | for runnable in snap.analysis().runnables(file_id)? { | 400 | for runnable in snap.analysis.runnables(file_id)? { |
401 | if let Some(offset) = offset { | 401 | if let Some(offset) = offset { |
402 | if !runnable.nav.full_range().contains_inclusive(offset) { | 402 | if !runnable.nav.full_range().contains_inclusive(offset) { |
403 | continue; | 403 | continue; |
@@ -456,7 +456,7 @@ pub(crate) fn handle_completion( | |||
456 | let mut res = false; | 456 | let mut res = false; |
457 | if let Some(ctx) = params.context { | 457 | if let Some(ctx) = params.context { |
458 | if ctx.trigger_character.unwrap_or_default() == ":" { | 458 | if ctx.trigger_character.unwrap_or_default() == ":" { |
459 | let source_file = snap.analysis().parse(position.file_id)?; | 459 | let source_file = snap.analysis.parse(position.file_id)?; |
460 | let syntax = source_file.syntax(); | 460 | let syntax = source_file.syntax(); |
461 | let text = syntax.text(); | 461 | let text = syntax.text(); |
462 | if let Some(next_char) = text.char_at(position.offset) { | 462 | if let Some(next_char) = text.char_at(position.offset) { |
@@ -474,11 +474,11 @@ pub(crate) fn handle_completion( | |||
474 | return Ok(None); | 474 | return Ok(None); |
475 | } | 475 | } |
476 | 476 | ||
477 | let items = match snap.analysis().completions(&snap.config.completion, position)? { | 477 | let items = match snap.analysis.completions(&snap.config.completion, position)? { |
478 | None => return Ok(None), | 478 | None => return Ok(None), |
479 | Some(items) => items, | 479 | Some(items) => items, |
480 | }; | 480 | }; |
481 | let line_index = snap.analysis().file_line_index(position.file_id)?; | 481 | let line_index = snap.analysis.file_line_index(position.file_id)?; |
482 | let line_endings = snap.file_line_endings(position.file_id); | 482 | let line_endings = snap.file_line_endings(position.file_id); |
483 | let items: Vec<CompletionItem> = items | 483 | let items: Vec<CompletionItem> = items |
484 | .into_iter() | 484 | .into_iter() |
@@ -494,9 +494,9 @@ pub(crate) fn handle_folding_range( | |||
494 | ) -> Result<Option<Vec<FoldingRange>>> { | 494 | ) -> Result<Option<Vec<FoldingRange>>> { |
495 | let _p = profile("handle_folding_range"); | 495 | let _p = profile("handle_folding_range"); |
496 | let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?; | 496 | let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?; |
497 | let folds = snap.analysis().folding_ranges(file_id)?; | 497 | let folds = snap.analysis.folding_ranges(file_id)?; |
498 | let text = snap.analysis().file_text(file_id)?; | 498 | let text = snap.analysis.file_text(file_id)?; |
499 | let line_index = snap.analysis().file_line_index(file_id)?; | 499 | let line_index = snap.analysis.file_line_index(file_id)?; |
500 | let line_folding_only = snap.config.client_caps.line_folding_only; | 500 | let line_folding_only = snap.config.client_caps.line_folding_only; |
501 | let res = folds | 501 | let res = folds |
502 | .into_iter() | 502 | .into_iter() |
@@ -511,7 +511,7 @@ pub(crate) fn handle_signature_help( | |||
511 | ) -> Result<Option<lsp_types::SignatureHelp>> { | 511 | ) -> Result<Option<lsp_types::SignatureHelp>> { |
512 | let _p = profile("handle_signature_help"); | 512 | let _p = profile("handle_signature_help"); |
513 | let position = from_proto::file_position(&snap, params.text_document_position_params)?; | 513 | let position = from_proto::file_position(&snap, params.text_document_position_params)?; |
514 | let call_info = match snap.analysis().call_info(position)? { | 514 | let call_info = match snap.analysis.call_info(position)? { |
515 | None => return Ok(None), | 515 | None => return Ok(None), |
516 | Some(it) => it, | 516 | Some(it) => it, |
517 | }; | 517 | }; |
@@ -535,7 +535,7 @@ pub(crate) fn handle_hover( | |||
535 | ) -> Result<Option<lsp_ext::Hover>> { | 535 | ) -> Result<Option<lsp_ext::Hover>> { |
536 | let _p = profile("handle_hover"); | 536 | let _p = profile("handle_hover"); |
537 | let position = from_proto::file_position(&snap, params.text_document_position_params)?; | 537 | let position = from_proto::file_position(&snap, params.text_document_position_params)?; |
538 | let info = match snap.analysis().hover(position)? { | 538 | let info = match snap.analysis.hover(position)? { |
539 | None => return Ok(None), | 539 | None => return Ok(None), |
540 | Some(info) => info, | 540 | Some(info) => info, |
541 | }; | 541 | }; |
@@ -562,13 +562,13 @@ pub(crate) fn handle_prepare_rename( | |||
562 | let _p = profile("handle_prepare_rename"); | 562 | let _p = profile("handle_prepare_rename"); |
563 | let position = from_proto::file_position(&snap, params)?; | 563 | let position = from_proto::file_position(&snap, params)?; |
564 | 564 | ||
565 | let optional_change = snap.analysis().rename(position, "dummy")?; | 565 | let optional_change = snap.analysis.rename(position, "dummy")?; |
566 | let range = match optional_change { | 566 | let range = match optional_change { |
567 | None => return Ok(None), | 567 | None => return Ok(None), |
568 | Some(it) => it.range, | 568 | Some(it) => it.range, |
569 | }; | 569 | }; |
570 | 570 | ||
571 | let line_index = snap.analysis().file_line_index(position.file_id)?; | 571 | let line_index = snap.analysis.file_line_index(position.file_id)?; |
572 | let range = to_proto::range(&line_index, range); | 572 | let range = to_proto::range(&line_index, range); |
573 | Ok(Some(PrepareRenameResponse::Range(range))) | 573 | Ok(Some(PrepareRenameResponse::Range(range))) |
574 | } | 574 | } |
@@ -588,7 +588,7 @@ pub(crate) fn handle_rename( | |||
588 | .into()); | 588 | .into()); |
589 | } | 589 | } |
590 | 590 | ||
591 | let optional_change = snap.analysis().rename(position, &*params.new_name)?; | 591 | let optional_change = snap.analysis.rename(position, &*params.new_name)?; |
592 | let source_change = match optional_change { | 592 | let source_change = match optional_change { |
593 | None => return Ok(None), | 593 | None => return Ok(None), |
594 | Some(it) => it.info, | 594 | Some(it) => it.info, |
@@ -604,7 +604,7 @@ pub(crate) fn handle_references( | |||
604 | let _p = profile("handle_references"); | 604 | let _p = profile("handle_references"); |
605 | let position = from_proto::file_position(&snap, params.text_document_position)?; | 605 | let position = from_proto::file_position(&snap, params.text_document_position)?; |
606 | 606 | ||
607 | let refs = match snap.analysis().find_all_refs(position, None)? { | 607 | let refs = match snap.analysis.find_all_refs(position, None)? { |
608 | None => return Ok(None), | 608 | None => return Ok(None), |
609 | Some(refs) => refs, | 609 | Some(refs) => refs, |
610 | }; | 610 | }; |
@@ -630,10 +630,10 @@ pub(crate) fn handle_formatting( | |||
630 | ) -> Result<Option<Vec<lsp_types::TextEdit>>> { | 630 | ) -> Result<Option<Vec<lsp_types::TextEdit>>> { |
631 | let _p = profile("handle_formatting"); | 631 | let _p = profile("handle_formatting"); |
632 | let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?; | 632 | let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?; |
633 | let file = snap.analysis().file_text(file_id)?; | 633 | let file = snap.analysis.file_text(file_id)?; |
634 | let crate_ids = snap.analysis().crate_for(file_id)?; | 634 | let crate_ids = snap.analysis.crate_for(file_id)?; |
635 | 635 | ||
636 | let file_line_index = snap.analysis().file_line_index(file_id)?; | 636 | let file_line_index = snap.analysis.file_line_index(file_id)?; |
637 | let end_position = to_proto::position(&file_line_index, TextSize::of(file.as_str())); | 637 | let end_position = to_proto::position(&file_line_index, TextSize::of(file.as_str())); |
638 | 638 | ||
639 | let mut rustfmt = match &snap.config.rustfmt { | 639 | let mut rustfmt = match &snap.config.rustfmt { |
@@ -642,7 +642,7 @@ pub(crate) fn handle_formatting( | |||
642 | cmd.args(extra_args); | 642 | cmd.args(extra_args); |
643 | if let Some(&crate_id) = crate_ids.first() { | 643 | if let Some(&crate_id) = crate_ids.first() { |
644 | // Assume all crates are in the same edition | 644 | // Assume all crates are in the same edition |
645 | let edition = snap.analysis().crate_edition(crate_id)?; | 645 | let edition = snap.analysis.crate_edition(crate_id)?; |
646 | cmd.arg("--edition"); | 646 | cmd.arg("--edition"); |
647 | cmd.arg(edition.to_string()); | 647 | cmd.arg(edition.to_string()); |
648 | } | 648 | } |
@@ -706,9 +706,9 @@ fn handle_fixes( | |||
706 | res: &mut Vec<lsp_ext::CodeAction>, | 706 | res: &mut Vec<lsp_ext::CodeAction>, |
707 | ) -> Result<()> { | 707 | ) -> Result<()> { |
708 | let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?; | 708 | let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?; |
709 | let line_index = snap.analysis().file_line_index(file_id)?; | 709 | let line_index = snap.analysis.file_line_index(file_id)?; |
710 | let range = from_proto::text_range(&line_index, params.range); | 710 | let range = from_proto::text_range(&line_index, params.range); |
711 | let diagnostics = snap.analysis().diagnostics(file_id)?; | 711 | let diagnostics = snap.analysis.diagnostics(file_id)?; |
712 | 712 | ||
713 | let fixes_from_diagnostics = diagnostics | 713 | let fixes_from_diagnostics = diagnostics |
714 | .into_iter() | 714 | .into_iter() |
@@ -752,7 +752,7 @@ pub(crate) fn handle_code_action( | |||
752 | } | 752 | } |
753 | 753 | ||
754 | let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?; | 754 | let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?; |
755 | let line_index = snap.analysis().file_line_index(file_id)?; | 755 | let line_index = snap.analysis.file_line_index(file_id)?; |
756 | let range = from_proto::text_range(&line_index, params.range); | 756 | let range = from_proto::text_range(&line_index, params.range); |
757 | let frange = FileRange { file_id, range }; | 757 | let frange = FileRange { file_id, range }; |
758 | let mut res: Vec<lsp_ext::CodeAction> = Vec::new(); | 758 | let mut res: Vec<lsp_ext::CodeAction> = Vec::new(); |
@@ -761,12 +761,12 @@ pub(crate) fn handle_code_action( | |||
761 | 761 | ||
762 | if snap.config.client_caps.resolve_code_action { | 762 | if snap.config.client_caps.resolve_code_action { |
763 | for (index, assist) in | 763 | for (index, assist) in |
764 | snap.analysis().unresolved_assists(&snap.config.assist, frange)?.into_iter().enumerate() | 764 | snap.analysis.unresolved_assists(&snap.config.assist, frange)?.into_iter().enumerate() |
765 | { | 765 | { |
766 | res.push(to_proto::unresolved_code_action(&snap, assist, index)?); | 766 | res.push(to_proto::unresolved_code_action(&snap, assist, index)?); |
767 | } | 767 | } |
768 | } else { | 768 | } else { |
769 | for assist in snap.analysis().resolved_assists(&snap.config.assist, frange)?.into_iter() { | 769 | for assist in snap.analysis.resolved_assists(&snap.config.assist, frange)?.into_iter() { |
770 | res.push(to_proto::resolved_code_action(&snap, assist)?); | 770 | res.push(to_proto::resolved_code_action(&snap, assist)?); |
771 | } | 771 | } |
772 | } | 772 | } |
@@ -780,11 +780,11 @@ pub(crate) fn handle_resolve_code_action( | |||
780 | ) -> Result<Option<lsp_ext::SnippetWorkspaceEdit>> { | 780 | ) -> Result<Option<lsp_ext::SnippetWorkspaceEdit>> { |
781 | let _p = profile("handle_resolve_code_action"); | 781 | let _p = profile("handle_resolve_code_action"); |
782 | let file_id = from_proto::file_id(&snap, ¶ms.code_action_params.text_document.uri)?; | 782 | let file_id = from_proto::file_id(&snap, ¶ms.code_action_params.text_document.uri)?; |
783 | let line_index = snap.analysis().file_line_index(file_id)?; | 783 | let line_index = snap.analysis.file_line_index(file_id)?; |
784 | let range = from_proto::text_range(&line_index, params.code_action_params.range); | 784 | let range = from_proto::text_range(&line_index, params.code_action_params.range); |
785 | let frange = FileRange { file_id, range }; | 785 | let frange = FileRange { file_id, range }; |
786 | 786 | ||
787 | let assists = snap.analysis().resolved_assists(&snap.config.assist, frange)?; | 787 | let assists = snap.analysis.resolved_assists(&snap.config.assist, frange)?; |
788 | let (id_string, index) = split_delim(¶ms.id, ':').unwrap(); | 788 | let (id_string, index) = split_delim(¶ms.id, ':').unwrap(); |
789 | let index = index.parse::<usize>().unwrap(); | 789 | let index = index.parse::<usize>().unwrap(); |
790 | let assist = &assists[index]; | 790 | let assist = &assists[index]; |
@@ -805,12 +805,12 @@ pub(crate) fn handle_code_lens( | |||
805 | } | 805 | } |
806 | 806 | ||
807 | let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?; | 807 | let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?; |
808 | let line_index = snap.analysis().file_line_index(file_id)?; | 808 | let line_index = snap.analysis.file_line_index(file_id)?; |
809 | let cargo_spec = CargoTargetSpec::for_file(&snap, file_id)?; | 809 | let cargo_spec = CargoTargetSpec::for_file(&snap, file_id)?; |
810 | 810 | ||
811 | if snap.config.lens.runnable() { | 811 | if snap.config.lens.runnable() { |
812 | // Gather runnables | 812 | // Gather runnables |
813 | for runnable in snap.analysis().runnables(file_id)? { | 813 | for runnable in snap.analysis.runnables(file_id)? { |
814 | if should_skip_target(&runnable, cargo_spec.as_ref()) { | 814 | if should_skip_target(&runnable, cargo_spec.as_ref()) { |
815 | continue; | 815 | continue; |
816 | } | 816 | } |
@@ -838,7 +838,7 @@ pub(crate) fn handle_code_lens( | |||
838 | if snap.config.lens.impementations { | 838 | if snap.config.lens.impementations { |
839 | // Handle impls | 839 | // Handle impls |
840 | lenses.extend( | 840 | lenses.extend( |
841 | snap.analysis() | 841 | snap.analysis |
842 | .file_structure(file_id)? | 842 | .file_structure(file_id)? |
843 | .into_iter() | 843 | .into_iter() |
844 | .filter(|it| match it.kind { | 844 | .filter(|it| match it.kind { |
@@ -916,10 +916,10 @@ pub(crate) fn handle_document_highlight( | |||
916 | ) -> Result<Option<Vec<DocumentHighlight>>> { | 916 | ) -> Result<Option<Vec<DocumentHighlight>>> { |
917 | let _p = profile("handle_document_highlight"); | 917 | let _p = profile("handle_document_highlight"); |
918 | let position = from_proto::file_position(&snap, params.text_document_position_params)?; | 918 | let position = from_proto::file_position(&snap, params.text_document_position_params)?; |
919 | let line_index = snap.analysis().file_line_index(position.file_id)?; | 919 | let line_index = snap.analysis.file_line_index(position.file_id)?; |
920 | 920 | ||
921 | let refs = match snap | 921 | let refs = match snap |
922 | .analysis() | 922 | .analysis |
923 | .find_all_refs(position, Some(SearchScope::single_file(position.file_id)))? | 923 | .find_all_refs(position, Some(SearchScope::single_file(position.file_id)))? |
924 | { | 924 | { |
925 | None => return Ok(None), | 925 | None => return Ok(None), |
@@ -943,7 +943,7 @@ pub(crate) fn handle_ssr( | |||
943 | ) -> Result<lsp_types::WorkspaceEdit> { | 943 | ) -> Result<lsp_types::WorkspaceEdit> { |
944 | let _p = profile("handle_ssr"); | 944 | let _p = profile("handle_ssr"); |
945 | let source_change = | 945 | let source_change = |
946 | snap.analysis().structural_search_replace(¶ms.query, params.parse_only)??; | 946 | snap.analysis.structural_search_replace(¶ms.query, params.parse_only)??; |
947 | to_proto::workspace_edit(&snap, source_change) | 947 | to_proto::workspace_edit(&snap, source_change) |
948 | } | 948 | } |
949 | 949 | ||
@@ -952,9 +952,9 @@ pub(crate) fn publish_diagnostics( | |||
952 | file_id: FileId, | 952 | file_id: FileId, |
953 | ) -> Result<DiagnosticTask> { | 953 | ) -> Result<DiagnosticTask> { |
954 | let _p = profile("publish_diagnostics"); | 954 | let _p = profile("publish_diagnostics"); |
955 | let line_index = snap.analysis().file_line_index(file_id)?; | 955 | let line_index = snap.analysis.file_line_index(file_id)?; |
956 | let diagnostics: Vec<Diagnostic> = snap | 956 | let diagnostics: Vec<Diagnostic> = snap |
957 | .analysis() | 957 | .analysis |
958 | .diagnostics(file_id)? | 958 | .diagnostics(file_id)? |
959 | .into_iter() | 959 | .into_iter() |
960 | .map(|d| Diagnostic { | 960 | .map(|d| Diagnostic { |
@@ -976,9 +976,9 @@ pub(crate) fn handle_inlay_hints( | |||
976 | ) -> Result<Vec<InlayHint>> { | 976 | ) -> Result<Vec<InlayHint>> { |
977 | let _p = profile("handle_inlay_hints"); | 977 | let _p = profile("handle_inlay_hints"); |
978 | let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?; | 978 | let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?; |
979 | let analysis = snap.analysis(); | 979 | let line_index = snap.analysis.file_line_index(file_id)?; |
980 | let line_index = analysis.file_line_index(file_id)?; | 980 | Ok(snap |
981 | Ok(analysis | 981 | .analysis |
982 | .inlay_hints(file_id, &snap.config.inlay_hints)? | 982 | .inlay_hints(file_id, &snap.config.inlay_hints)? |
983 | .into_iter() | 983 | .into_iter() |
984 | .map(|it| to_proto::inlay_int(&line_index, it)) | 984 | .map(|it| to_proto::inlay_int(&line_index, it)) |
@@ -992,7 +992,7 @@ pub(crate) fn handle_call_hierarchy_prepare( | |||
992 | let _p = profile("handle_call_hierarchy_prepare"); | 992 | let _p = profile("handle_call_hierarchy_prepare"); |
993 | let position = from_proto::file_position(&snap, params.text_document_position_params)?; | 993 | let position = from_proto::file_position(&snap, params.text_document_position_params)?; |
994 | 994 | ||
995 | let nav_info = match snap.analysis().call_hierarchy(position)? { | 995 | let nav_info = match snap.analysis.call_hierarchy(position)? { |
996 | None => return Ok(None), | 996 | None => return Ok(None), |
997 | Some(it) => it, | 997 | Some(it) => it, |
998 | }; | 998 | }; |
@@ -1018,7 +1018,7 @@ pub(crate) fn handle_call_hierarchy_incoming( | |||
1018 | let frange = from_proto::file_range(&snap, doc, item.range)?; | 1018 | let frange = from_proto::file_range(&snap, doc, item.range)?; |
1019 | let fpos = FilePosition { file_id: frange.file_id, offset: frange.range.start() }; | 1019 | let fpos = FilePosition { file_id: frange.file_id, offset: frange.range.start() }; |
1020 | 1020 | ||
1021 | let call_items = match snap.analysis().incoming_calls(fpos)? { | 1021 | let call_items = match snap.analysis.incoming_calls(fpos)? { |
1022 | None => return Ok(None), | 1022 | None => return Ok(None), |
1023 | Some(it) => it, | 1023 | Some(it) => it, |
1024 | }; | 1024 | }; |
@@ -1027,7 +1027,7 @@ pub(crate) fn handle_call_hierarchy_incoming( | |||
1027 | 1027 | ||
1028 | for call_item in call_items.into_iter() { | 1028 | for call_item in call_items.into_iter() { |
1029 | let file_id = call_item.target.file_id(); | 1029 | let file_id = call_item.target.file_id(); |
1030 | let line_index = snap.analysis().file_line_index(file_id)?; | 1030 | let line_index = snap.analysis.file_line_index(file_id)?; |
1031 | let item = to_proto::call_hierarchy_item(&snap, call_item.target)?; | 1031 | let item = to_proto::call_hierarchy_item(&snap, call_item.target)?; |
1032 | res.push(CallHierarchyIncomingCall { | 1032 | res.push(CallHierarchyIncomingCall { |
1033 | from: item, | 1033 | from: item, |
@@ -1053,7 +1053,7 @@ pub(crate) fn handle_call_hierarchy_outgoing( | |||
1053 | let frange = from_proto::file_range(&snap, doc, item.range)?; | 1053 | let frange = from_proto::file_range(&snap, doc, item.range)?; |
1054 | let fpos = FilePosition { file_id: frange.file_id, offset: frange.range.start() }; | 1054 | let fpos = FilePosition { file_id: frange.file_id, offset: frange.range.start() }; |
1055 | 1055 | ||
1056 | let call_items = match snap.analysis().outgoing_calls(fpos)? { | 1056 | let call_items = match snap.analysis.outgoing_calls(fpos)? { |
1057 | None => return Ok(None), | 1057 | None => return Ok(None), |
1058 | Some(it) => it, | 1058 | Some(it) => it, |
1059 | }; | 1059 | }; |
@@ -1062,7 +1062,7 @@ pub(crate) fn handle_call_hierarchy_outgoing( | |||
1062 | 1062 | ||
1063 | for call_item in call_items.into_iter() { | 1063 | for call_item in call_items.into_iter() { |
1064 | let file_id = call_item.target.file_id(); | 1064 | let file_id = call_item.target.file_id(); |
1065 | let line_index = snap.analysis().file_line_index(file_id)?; | 1065 | let line_index = snap.analysis.file_line_index(file_id)?; |
1066 | let item = to_proto::call_hierarchy_item(&snap, call_item.target)?; | 1066 | let item = to_proto::call_hierarchy_item(&snap, call_item.target)?; |
1067 | res.push(CallHierarchyOutgoingCall { | 1067 | res.push(CallHierarchyOutgoingCall { |
1068 | to: item, | 1068 | to: item, |
@@ -1084,10 +1084,10 @@ pub(crate) fn handle_semantic_tokens( | |||
1084 | let _p = profile("handle_semantic_tokens"); | 1084 | let _p = profile("handle_semantic_tokens"); |
1085 | 1085 | ||
1086 | let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?; | 1086 | let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?; |
1087 | let text = snap.analysis().file_text(file_id)?; | 1087 | let text = snap.analysis.file_text(file_id)?; |
1088 | let line_index = snap.analysis().file_line_index(file_id)?; | 1088 | let line_index = snap.analysis.file_line_index(file_id)?; |
1089 | 1089 | ||
1090 | let highlights = snap.analysis().highlight(file_id)?; | 1090 | let highlights = snap.analysis.highlight(file_id)?; |
1091 | let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights); | 1091 | let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights); |
1092 | Ok(Some(semantic_tokens.into())) | 1092 | Ok(Some(semantic_tokens.into())) |
1093 | } | 1093 | } |
@@ -1099,10 +1099,10 @@ pub(crate) fn handle_semantic_tokens_range( | |||
1099 | let _p = profile("handle_semantic_tokens_range"); | 1099 | let _p = profile("handle_semantic_tokens_range"); |
1100 | 1100 | ||
1101 | let frange = from_proto::file_range(&snap, params.text_document, params.range)?; | 1101 | let frange = from_proto::file_range(&snap, params.text_document, params.range)?; |
1102 | let text = snap.analysis().file_text(frange.file_id)?; | 1102 | let text = snap.analysis.file_text(frange.file_id)?; |
1103 | let line_index = snap.analysis().file_line_index(frange.file_id)?; | 1103 | let line_index = snap.analysis.file_line_index(frange.file_id)?; |
1104 | 1104 | ||
1105 | let highlights = snap.analysis().highlight_range(frange)?; | 1105 | let highlights = snap.analysis.highlight_range(frange)?; |
1106 | let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights); | 1106 | let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights); |
1107 | Ok(Some(semantic_tokens.into())) | 1107 | Ok(Some(semantic_tokens.into())) |
1108 | } | 1108 | } |
@@ -1178,9 +1178,9 @@ fn show_impl_command_link( | |||
1178 | position: &FilePosition, | 1178 | position: &FilePosition, |
1179 | ) -> Option<lsp_ext::CommandLinkGroup> { | 1179 | ) -> Option<lsp_ext::CommandLinkGroup> { |
1180 | if snap.config.hover.implementations { | 1180 | if snap.config.hover.implementations { |
1181 | if let Some(nav_data) = snap.analysis().goto_implementation(*position).unwrap_or(None) { | 1181 | if let Some(nav_data) = snap.analysis.goto_implementation(*position).unwrap_or(None) { |
1182 | let uri = to_proto::url(snap, position.file_id); | 1182 | let uri = to_proto::url(snap, position.file_id); |
1183 | let line_index = snap.analysis().file_line_index(position.file_id).ok()?; | 1183 | let line_index = snap.analysis.file_line_index(position.file_id).ok()?; |
1184 | let position = to_proto::position(&line_index, position.offset); | 1184 | let position = to_proto::position(&line_index, position.offset); |
1185 | let locations: Vec<_> = nav_data | 1185 | let locations: Vec<_> = nav_data |
1186 | .info | 1186 | .info |
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 1787e8c16..eb9e7f913 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -300,7 +300,7 @@ fn loop_turn( | |||
300 | pool.execute({ | 300 | pool.execute({ |
301 | let subs = subscriptions; | 301 | let subs = subscriptions; |
302 | let snap = global_state.snapshot(); | 302 | let snap = global_state.snapshot(); |
303 | move || snap.analysis().prime_caches(subs).unwrap_or_else(|_: Canceled| ()) | 303 | move || snap.analysis.prime_caches(subs).unwrap_or_else(|_: Canceled| ()) |
304 | }); | 304 | }); |
305 | } | 305 | } |
306 | 306 | ||
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index 88d1c0d8a..f6cb8e4bb 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs | |||
@@ -440,7 +440,7 @@ pub(crate) fn location( | |||
440 | frange: FileRange, | 440 | frange: FileRange, |
441 | ) -> Result<lsp_types::Location> { | 441 | ) -> Result<lsp_types::Location> { |
442 | let url = url(snap, frange.file_id); | 442 | let url = url(snap, frange.file_id); |
443 | let line_index = snap.analysis().file_line_index(frange.file_id)?; | 443 | let line_index = snap.analysis.file_line_index(frange.file_id)?; |
444 | let range = range(&line_index, frange.range); | 444 | let range = range(&line_index, frange.range); |
445 | let loc = lsp_types::Location::new(url, range); | 445 | let loc = lsp_types::Location::new(url, range); |
446 | Ok(loc) | 446 | Ok(loc) |
@@ -453,7 +453,7 @@ pub(crate) fn location_link( | |||
453 | ) -> Result<lsp_types::LocationLink> { | 453 | ) -> Result<lsp_types::LocationLink> { |
454 | let origin_selection_range = match src { | 454 | let origin_selection_range = match src { |
455 | Some(src) => { | 455 | Some(src) => { |
456 | let line_index = snap.analysis().file_line_index(src.file_id)?; | 456 | let line_index = snap.analysis.file_line_index(src.file_id)?; |
457 | let range = range(&line_index, src.range); | 457 | let range = range(&line_index, src.range); |
458 | Some(range) | 458 | Some(range) |
459 | } | 459 | } |
@@ -473,7 +473,7 @@ fn location_info( | |||
473 | snap: &GlobalStateSnapshot, | 473 | snap: &GlobalStateSnapshot, |
474 | target: NavigationTarget, | 474 | target: NavigationTarget, |
475 | ) -> Result<(lsp_types::Url, lsp_types::Range, lsp_types::Range)> { | 475 | ) -> Result<(lsp_types::Url, lsp_types::Range, lsp_types::Range)> { |
476 | let line_index = snap.analysis().file_line_index(target.file_id())?; | 476 | let line_index = snap.analysis.file_line_index(target.file_id())?; |
477 | 477 | ||
478 | let target_uri = url(snap, target.file_id()); | 478 | let target_uri = url(snap, target.file_id()); |
479 | let target_range = range(&line_index, target.full_range()); | 479 | let target_range = range(&line_index, target.full_range()); |
@@ -516,7 +516,7 @@ pub(crate) fn snippet_text_document_edit( | |||
516 | source_file_edit: SourceFileEdit, | 516 | source_file_edit: SourceFileEdit, |
517 | ) -> Result<lsp_ext::SnippetTextDocumentEdit> { | 517 | ) -> Result<lsp_ext::SnippetTextDocumentEdit> { |
518 | let text_document = versioned_text_document_identifier(snap, source_file_edit.file_id, None); | 518 | let text_document = versioned_text_document_identifier(snap, source_file_edit.file_id, None); |
519 | let line_index = snap.analysis().file_line_index(source_file_edit.file_id)?; | 519 | let line_index = snap.analysis.file_line_index(source_file_edit.file_id)?; |
520 | let line_endings = snap.file_line_endings(source_file_edit.file_id); | 520 | let line_endings = snap.file_line_endings(source_file_edit.file_id); |
521 | let edits = source_file_edit | 521 | let edits = source_file_edit |
522 | .edit | 522 | .edit |