From 842e8001b287b0e3d77215235ae96a3bd8944207 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 8 Feb 2019 11:52:18 +0300 Subject: move changes to a separate file --- crates/ra_ide_api/src/lib.rs | 159 ++----------------------------------------- 1 file changed, 4 insertions(+), 155 deletions(-) (limited to 'crates/ra_ide_api/src/lib.rs') 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; pub mod mock_analysis; mod symbol_index; mod navigation_target; +mod change; mod status; mod completion; @@ -35,7 +36,7 @@ mod assists; #[cfg(test)] mod marks; -use std::{fmt, sync::Arc}; +use std::sync::Arc; use ra_syntax::{SourceFile, TreeArc, TextRange, TextUnit}; use ra_text_edit::TextEdit; @@ -43,12 +44,10 @@ use ra_db::{ SourceDatabase, CheckCanceled, salsa::{self, ParallelDatabase}, }; -use rayon::prelude::*; use relative_path::RelativePathBuf; -use rustc_hash::FxHashMap; use crate::{ - symbol_index::{FileSymbol, SymbolIndex}, + symbol_index::FileSymbol, db::LineIndexDatabase, }; @@ -56,6 +55,7 @@ pub use crate::{ completion::{CompletionItem, CompletionItemKind, InsertTextFormat}, runnables::{Runnable, RunnableKind}, navigation_target::NavigationTarget, + change::{AnalysisChange, LibraryData}, }; pub use ra_ide_api_light::{ Fold, FoldKind, HighlightedRange, Severity, StructureNode, @@ -74,115 +74,6 @@ static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; pub type Cancelable = Result; -#[derive(Default)] -pub struct AnalysisChange { - new_roots: Vec<(SourceRootId, bool)>, - roots_changed: FxHashMap, - files_changed: Vec<(FileId, Arc)>, - libraries_added: Vec, - crate_graph: Option, -} - -#[derive(Default)] -struct RootChange { - added: Vec, - removed: Vec, -} - -#[derive(Debug)] -struct AddFile { - file_id: FileId, - path: RelativePathBuf, - text: Arc, -} - -#[derive(Debug)] -struct RemoveFile { - file_id: FileId, - path: RelativePathBuf, -} - -impl fmt::Debug for AnalysisChange { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - let mut d = fmt.debug_struct("AnalysisChange"); - if !self.new_roots.is_empty() { - d.field("new_roots", &self.new_roots); - } - if !self.roots_changed.is_empty() { - d.field("roots_changed", &self.roots_changed); - } - if !self.files_changed.is_empty() { - d.field("files_changed", &self.files_changed.len()); - } - if !self.libraries_added.is_empty() { - d.field("libraries_added", &self.libraries_added.len()); - } - if self.crate_graph.is_none() { - d.field("crate_graph", &self.crate_graph); - } - d.finish() - } -} - -impl fmt::Debug for RootChange { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - fmt.debug_struct("AnalysisChange") - .field("added", &self.added.len()) - .field("removed", &self.removed.len()) - .finish() - } -} - -impl AnalysisChange { - pub fn new() -> AnalysisChange { - AnalysisChange::default() - } - - pub fn add_root(&mut self, root_id: SourceRootId, is_local: bool) { - self.new_roots.push((root_id, is_local)); - } - - pub fn add_file( - &mut self, - root_id: SourceRootId, - file_id: FileId, - path: RelativePathBuf, - text: Arc, - ) { - let file = AddFile { - file_id, - path, - text, - }; - self.roots_changed - .entry(root_id) - .or_default() - .added - .push(file); - } - - pub fn change_file(&mut self, file_id: FileId, new_text: Arc) { - self.files_changed.push((file_id, new_text)) - } - - pub fn remove_file(&mut self, root_id: SourceRootId, file_id: FileId, path: RelativePathBuf) { - let file = RemoveFile { file_id, path }; - self.roots_changed - .entry(root_id) - .or_default() - .removed - .push(file); - } - - pub fn add_library(&mut self, data: LibraryData) { - self.libraries_added.push(data) - } - - pub fn set_crate_graph(&mut self, graph: CrateGraph) { - self.crate_graph = Some(graph); - } -} - #[derive(Debug)] pub struct SourceChange { pub label: String, @@ -508,48 +399,6 @@ impl Analysis { } } -pub struct LibraryData { - root_id: SourceRootId, - root_change: RootChange, - symbol_index: SymbolIndex, -} - -impl fmt::Debug for LibraryData { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.debug_struct("LibraryData") - .field("root_id", &self.root_id) - .field("root_change", &self.root_change) - .field("n_symbols", &self.symbol_index.len()) - .finish() - } -} - -impl LibraryData { - pub fn prepare( - root_id: SourceRootId, - files: Vec<(FileId, RelativePathBuf, Arc)>, - ) -> LibraryData { - let symbol_index = SymbolIndex::for_files(files.par_iter().map(|(file_id, _, text)| { - let file = SourceFile::parse(text); - (*file_id, file) - })); - let mut root_change = RootChange::default(); - root_change.added = files - .into_iter() - .map(|(file_id, path, text)| AddFile { - file_id, - path, - text, - }) - .collect(); - LibraryData { - root_id, - root_change, - symbol_index, - } - } -} - #[test] fn analysis_is_send() { fn is_send() {} -- cgit v1.2.3 From bddd1242986f3155bdb1ca65495bc0623e3d211d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 8 Feb 2019 13:50:18 +0300 Subject: move crate for --- crates/ra_ide_api/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_ide_api/src/lib.rs') diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 22a601ec8..bb60e8d40 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -342,7 +342,7 @@ impl Analysis { /// Returns crates this file belongs too. pub fn crate_for(&self, file_id: FileId) -> Cancelable> { - self.with_db(|db| db.crate_for(file_id)) + self.with_db(|db| parent_module::crate_for(db, file_id)) } /// Returns the root file of the given crate. -- cgit v1.2.3 From 4d0e58afef1722d5f5bf5970bed44594c27ecf34 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 8 Feb 2019 13:51:22 +0300 Subject: rename rename to references --- crates/ra_ide_api/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide_api/src/lib.rs') diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index bb60e8d40..0bb21245d 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -29,7 +29,7 @@ mod hover; mod call_info; mod syntax_highlighting; mod parent_module; -mod rename; +mod references; mod impls; mod assists; @@ -388,7 +388,7 @@ impl Analysis { position: FilePosition, new_name: &str, ) -> Cancelable> { - self.with_db(|db| rename::rename(db, position, new_name)) + self.with_db(|db| references::rename(db, position, new_name)) } fn with_db T + std::panic::UnwindSafe, T>( -- cgit v1.2.3 From 5173c6295b9c48e6990d6fb6467fc35cd0dfc902 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 8 Feb 2019 14:06:26 +0300 Subject: move find_references to references --- crates/ra_ide_api/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_ide_api/src/lib.rs') diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 0bb21245d..f5c1aa036 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -322,7 +322,7 @@ impl Analysis { /// Finds all usages of the reference at point. pub fn find_all_refs(&self, position: FilePosition) -> Cancelable> { - self.with_db(|db| db.find_all_refs(position)) + self.with_db(|db| references::find_all_refs(db, position)) } /// Returns a short text descrbing element at position. -- cgit v1.2.3 From 8328e196dd093f85e51420fa27d9d9bcdf65e866 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 8 Feb 2019 14:24:39 +0300 Subject: move diagnostics to a separate file --- crates/ra_ide_api/src/lib.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide_api/src/lib.rs') diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index f5c1aa036..312b11a82 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -14,7 +14,6 @@ #![recursion_limit = "128"] mod db; -mod imp; pub mod mock_analysis; mod symbol_index; mod navigation_target; @@ -32,6 +31,7 @@ mod parent_module; mod references; mod impls; mod assists; +mod diagnostics; #[cfg(test)] mod marks; @@ -58,7 +58,7 @@ pub use crate::{ change::{AnalysisChange, LibraryData}, }; pub use ra_ide_api_light::{ - Fold, FoldKind, HighlightedRange, Severity, StructureNode, + Fold, FoldKind, HighlightedRange, Severity, StructureNode, LocalEdit, LineIndex, LineCol, translate_offset_with_edit, }; pub use ra_db::{ @@ -399,6 +399,23 @@ impl Analysis { } } +impl SourceChange { + pub(crate) fn from_local_edit(file_id: FileId, edit: LocalEdit) -> SourceChange { + let file_edit = SourceFileEdit { + file_id, + edit: edit.edit, + }; + SourceChange { + label: edit.label, + source_file_edits: vec![file_edit], + file_system_edits: vec![], + cursor_position: edit + .cursor_position + .map(|offset| FilePosition { offset, file_id }), + } + } +} + #[test] fn analysis_is_send() { fn is_send() {} -- cgit v1.2.3 From 884f04670aea239f06fe5b6ff7a9f2073034f8bc Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 8 Feb 2019 14:30:21 +0300 Subject: diagnostics is now a function --- crates/ra_ide_api/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide_api/src/lib.rs') diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 312b11a82..1f43b7623 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -52,10 +52,10 @@ use crate::{ }; pub use crate::{ + change::{AnalysisChange, LibraryData}, completion::{CompletionItem, CompletionItemKind, InsertTextFormat}, runnables::{Runnable, RunnableKind}, navigation_target::NavigationTarget, - change::{AnalysisChange, LibraryData}, }; pub use ra_ide_api_light::{ Fold, FoldKind, HighlightedRange, Severity, StructureNode, LocalEdit, @@ -373,7 +373,7 @@ impl Analysis { /// Computes the set of diagnostics for the given file. pub fn diagnostics(&self, file_id: FileId) -> Cancelable> { - self.with_db(|db| db.diagnostics(file_id)) + self.with_db(|db| diagnostics::diagnostics(db, file_id)) } /// Computes the type of the expression at the given position. -- cgit v1.2.3