diff options
Diffstat (limited to 'crates/ra_analysis/src/lib.rs')
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 63 |
1 files changed, 31 insertions, 32 deletions
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 03994b7c4..efb483103 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs | |||
@@ -27,11 +27,9 @@ use ra_syntax::{SourceFileNode, TextRange, TextUnit, SmolStr, SyntaxKind}; | |||
27 | use ra_text_edit::TextEdit; | 27 | use ra_text_edit::TextEdit; |
28 | use rayon::prelude::*; | 28 | use rayon::prelude::*; |
29 | use relative_path::RelativePathBuf; | 29 | use relative_path::RelativePathBuf; |
30 | use salsa::ParallelDatabase; | ||
30 | 31 | ||
31 | use crate::{ | 32 | use crate::symbol_index::{SymbolIndex, FileSymbol}; |
32 | imp::AnalysisImpl, | ||
33 | symbol_index::{SymbolIndex, FileSymbol}, | ||
34 | }; | ||
35 | 33 | ||
36 | pub use crate::{ | 34 | pub use crate::{ |
37 | completion::{CompletionItem, CompletionItemKind, InsertText}, | 35 | completion::{CompletionItem, CompletionItemKind, InsertText}, |
@@ -161,7 +159,7 @@ impl AnalysisHost { | |||
161 | /// semantic information. | 159 | /// semantic information. |
162 | pub fn analysis(&self) -> Analysis { | 160 | pub fn analysis(&self) -> Analysis { |
163 | Analysis { | 161 | Analysis { |
164 | imp: self.db.analysis(), | 162 | db: self.db.snapshot(), |
165 | } | 163 | } |
166 | } | 164 | } |
167 | /// Applies changes to the current state of the world. If there are | 165 | /// Applies changes to the current state of the world. If there are |
@@ -293,56 +291,56 @@ impl ReferenceResolution { | |||
293 | /// `Analysis` are canceled (most method return `Err(Canceled)`). | 291 | /// `Analysis` are canceled (most method return `Err(Canceled)`). |
294 | #[derive(Debug)] | 292 | #[derive(Debug)] |
295 | pub struct Analysis { | 293 | pub struct Analysis { |
296 | pub(crate) imp: AnalysisImpl, | 294 | db: salsa::Snapshot<db::RootDatabase>, |
297 | } | 295 | } |
298 | 296 | ||
299 | impl Analysis { | 297 | impl Analysis { |
300 | pub fn file_text(&self, file_id: FileId) -> Arc<String> { | 298 | pub fn file_text(&self, file_id: FileId) -> Arc<String> { |
301 | self.imp.db.file_text(file_id) | 299 | self.db.file_text(file_id) |
302 | } | 300 | } |
303 | pub fn file_syntax(&self, file_id: FileId) -> SourceFileNode { | 301 | pub fn file_syntax(&self, file_id: FileId) -> SourceFileNode { |
304 | self.imp.db.source_file(file_id).clone() | 302 | self.db.source_file(file_id).clone() |
305 | } | 303 | } |
306 | pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> { | 304 | pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> { |
307 | self.imp.db.file_lines(file_id) | 305 | self.db.file_lines(file_id) |
308 | } | 306 | } |
309 | pub fn extend_selection(&self, frange: FileRange) -> TextRange { | 307 | pub fn extend_selection(&self, frange: FileRange) -> TextRange { |
310 | extend_selection::extend_selection(&self.imp.db, frange) | 308 | extend_selection::extend_selection(&self.db, frange) |
311 | } | 309 | } |
312 | pub fn matching_brace(&self, file: &SourceFileNode, offset: TextUnit) -> Option<TextUnit> { | 310 | pub fn matching_brace(&self, file: &SourceFileNode, offset: TextUnit) -> Option<TextUnit> { |
313 | ra_editor::matching_brace(file, offset) | 311 | ra_editor::matching_brace(file, offset) |
314 | } | 312 | } |
315 | pub fn syntax_tree(&self, file_id: FileId) -> String { | 313 | pub fn syntax_tree(&self, file_id: FileId) -> String { |
316 | let file = self.imp.db.source_file(file_id); | 314 | let file = self.db.source_file(file_id); |
317 | ra_editor::syntax_tree(&file) | 315 | ra_editor::syntax_tree(&file) |
318 | } | 316 | } |
319 | pub fn join_lines(&self, frange: FileRange) -> SourceChange { | 317 | pub fn join_lines(&self, frange: FileRange) -> SourceChange { |
320 | let file = self.imp.db.source_file(frange.file_id); | 318 | let file = self.db.source_file(frange.file_id); |
321 | SourceChange::from_local_edit(frange.file_id, ra_editor::join_lines(&file, frange.range)) | 319 | SourceChange::from_local_edit(frange.file_id, ra_editor::join_lines(&file, frange.range)) |
322 | } | 320 | } |
323 | pub fn on_enter(&self, position: FilePosition) -> Option<SourceChange> { | 321 | pub fn on_enter(&self, position: FilePosition) -> Option<SourceChange> { |
324 | let file = self.imp.db.source_file(position.file_id); | 322 | let file = self.db.source_file(position.file_id); |
325 | let edit = ra_editor::on_enter(&file, position.offset)?; | 323 | let edit = ra_editor::on_enter(&file, position.offset)?; |
326 | let res = SourceChange::from_local_edit(position.file_id, edit); | 324 | let res = SourceChange::from_local_edit(position.file_id, edit); |
327 | Some(res) | 325 | Some(res) |
328 | } | 326 | } |
329 | pub fn on_eq_typed(&self, position: FilePosition) -> Option<SourceChange> { | 327 | pub fn on_eq_typed(&self, position: FilePosition) -> Option<SourceChange> { |
330 | let file = self.imp.db.source_file(position.file_id); | 328 | let file = self.db.source_file(position.file_id); |
331 | Some(SourceChange::from_local_edit( | 329 | Some(SourceChange::from_local_edit( |
332 | position.file_id, | 330 | position.file_id, |
333 | ra_editor::on_eq_typed(&file, position.offset)?, | 331 | ra_editor::on_eq_typed(&file, position.offset)?, |
334 | )) | 332 | )) |
335 | } | 333 | } |
336 | pub fn file_structure(&self, file_id: FileId) -> Vec<StructureNode> { | 334 | pub fn file_structure(&self, file_id: FileId) -> Vec<StructureNode> { |
337 | let file = self.imp.db.source_file(file_id); | 335 | let file = self.db.source_file(file_id); |
338 | ra_editor::file_structure(&file) | 336 | ra_editor::file_structure(&file) |
339 | } | 337 | } |
340 | pub fn folding_ranges(&self, file_id: FileId) -> Vec<Fold> { | 338 | pub fn folding_ranges(&self, file_id: FileId) -> Vec<Fold> { |
341 | let file = self.imp.db.source_file(file_id); | 339 | let file = self.db.source_file(file_id); |
342 | ra_editor::folding_ranges(&file) | 340 | ra_editor::folding_ranges(&file) |
343 | } | 341 | } |
344 | pub fn symbol_search(&self, query: Query) -> Cancelable<Vec<NavigationTarget>> { | 342 | pub fn symbol_search(&self, query: Query) -> Cancelable<Vec<NavigationTarget>> { |
345 | let res = symbol_index::world_symbols(&*self.imp.db, query)? | 343 | let res = symbol_index::world_symbols(&*self.db, query)? |
346 | .into_iter() | 344 | .into_iter() |
347 | .map(|(file_id, symbol)| NavigationTarget { file_id, symbol }) | 345 | .map(|(file_id, symbol)| NavigationTarget { file_id, symbol }) |
348 | .collect(); | 346 | .collect(); |
@@ -352,57 +350,58 @@ impl Analysis { | |||
352 | &self, | 350 | &self, |
353 | position: FilePosition, | 351 | position: FilePosition, |
354 | ) -> Cancelable<Option<ReferenceResolution>> { | 352 | ) -> Cancelable<Option<ReferenceResolution>> { |
355 | self.imp.approximately_resolve_symbol(position) | 353 | self.db.approximately_resolve_symbol(position) |
356 | } | 354 | } |
357 | pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> { | 355 | pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> { |
358 | self.imp.find_all_refs(position) | 356 | self.db.find_all_refs(position) |
359 | } | 357 | } |
360 | pub fn doc_text_for(&self, nav: NavigationTarget) -> Cancelable<Option<String>> { | 358 | pub fn doc_text_for(&self, nav: NavigationTarget) -> Cancelable<Option<String>> { |
361 | self.imp.doc_text_for(nav) | 359 | self.db.doc_text_for(nav) |
362 | } | 360 | } |
363 | pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<NavigationTarget>> { | 361 | pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<NavigationTarget>> { |
364 | self.imp.parent_module(position) | 362 | self.db.parent_module(position) |
365 | } | 363 | } |
366 | pub fn module_path(&self, position: FilePosition) -> Cancelable<Option<String>> { | 364 | pub fn module_path(&self, position: FilePosition) -> Cancelable<Option<String>> { |
367 | self.imp.module_path(position) | 365 | self.db.module_path(position) |
368 | } | 366 | } |
369 | pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> { | 367 | pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> { |
370 | self.imp.crate_for(file_id) | 368 | self.db.crate_for(file_id) |
371 | } | 369 | } |
372 | pub fn crate_root(&self, crate_id: CrateId) -> Cancelable<FileId> { | 370 | pub fn crate_root(&self, crate_id: CrateId) -> Cancelable<FileId> { |
373 | Ok(self.imp.crate_root(crate_id)) | 371 | Ok(self.db.crate_root(crate_id)) |
374 | } | 372 | } |
375 | pub fn runnables(&self, file_id: FileId) -> Cancelable<Vec<Runnable>> { | 373 | pub fn runnables(&self, file_id: FileId) -> Cancelable<Vec<Runnable>> { |
376 | let file = self.imp.db.source_file(file_id); | 374 | let file = self.db.source_file(file_id); |
377 | Ok(runnables::runnables(self, &file, file_id)) | 375 | Ok(runnables::runnables(self, &file, file_id)) |
378 | } | 376 | } |
379 | pub fn highlight(&self, file_id: FileId) -> Cancelable<Vec<HighlightedRange>> { | 377 | pub fn highlight(&self, file_id: FileId) -> Cancelable<Vec<HighlightedRange>> { |
380 | syntax_highlighting::highlight(&*self.imp.db, file_id) | 378 | syntax_highlighting::highlight(&*self.db, file_id) |
381 | } | 379 | } |
382 | pub fn completions(&self, position: FilePosition) -> Cancelable<Option<Vec<CompletionItem>>> { | 380 | pub fn completions(&self, position: FilePosition) -> Cancelable<Option<Vec<CompletionItem>>> { |
383 | self.imp.completions(position) | 381 | let completions = completion::completions(&self.db, position)?; |
382 | Ok(completions.map(|it| it.into())) | ||
384 | } | 383 | } |
385 | pub fn assists(&self, frange: FileRange) -> Cancelable<Vec<SourceChange>> { | 384 | pub fn assists(&self, frange: FileRange) -> Cancelable<Vec<SourceChange>> { |
386 | Ok(self.imp.assists(frange)) | 385 | Ok(self.db.assists(frange)) |
387 | } | 386 | } |
388 | pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> { | 387 | pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> { |
389 | self.imp.diagnostics(file_id) | 388 | self.db.diagnostics(file_id) |
390 | } | 389 | } |
391 | pub fn resolve_callable( | 390 | pub fn resolve_callable( |
392 | &self, | 391 | &self, |
393 | position: FilePosition, | 392 | position: FilePosition, |
394 | ) -> Cancelable<Option<(FnSignatureInfo, Option<usize>)>> { | 393 | ) -> Cancelable<Option<(FnSignatureInfo, Option<usize>)>> { |
395 | self.imp.resolve_callable(position) | 394 | self.db.resolve_callable(position) |
396 | } | 395 | } |
397 | pub fn type_of(&self, frange: FileRange) -> Cancelable<Option<String>> { | 396 | pub fn type_of(&self, frange: FileRange) -> Cancelable<Option<String>> { |
398 | self.imp.type_of(frange) | 397 | self.db.type_of(frange) |
399 | } | 398 | } |
400 | pub fn rename( | 399 | pub fn rename( |
401 | &self, | 400 | &self, |
402 | position: FilePosition, | 401 | position: FilePosition, |
403 | new_name: &str, | 402 | new_name: &str, |
404 | ) -> Cancelable<Vec<SourceFileEdit>> { | 403 | ) -> Cancelable<Vec<SourceFileEdit>> { |
405 | self.imp.rename(position, new_name) | 404 | self.db.rename(position, new_name) |
406 | } | 405 | } |
407 | } | 406 | } |
408 | 407 | ||