diff options
Diffstat (limited to 'crates/ra_analysis')
-rw-r--r-- | crates/ra_analysis/src/db.rs | 12 | ||||
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 16 | ||||
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 15 | ||||
-rw-r--r-- | crates/ra_analysis/tests/tests.rs | 2 |
4 files changed, 28 insertions, 17 deletions
diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs index 3d0f13f34..94729d296 100644 --- a/crates/ra_analysis/src/db.rs +++ b/crates/ra_analysis/src/db.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use std::sync::Arc; | 1 | use std::{fmt, sync::Arc}; |
2 | use salsa::{self, Database}; | 2 | use salsa::{self, Database}; |
3 | use ra_db::{LocationIntener, BaseDatabase}; | 3 | use ra_db::{LocationIntener, BaseDatabase}; |
4 | use hir::{self, DefId, DefLoc}; | 4 | use hir::{self, DefId, DefLoc}; |
@@ -13,11 +13,19 @@ pub(crate) struct RootDatabase { | |||
13 | id_maps: Arc<IdMaps>, | 13 | id_maps: Arc<IdMaps>, |
14 | } | 14 | } |
15 | 15 | ||
16 | #[derive(Debug, Default)] | 16 | #[derive(Default)] |
17 | struct IdMaps { | 17 | struct IdMaps { |
18 | defs: LocationIntener<DefLoc, DefId>, | 18 | defs: LocationIntener<DefLoc, DefId>, |
19 | } | 19 | } |
20 | 20 | ||
21 | impl fmt::Debug for IdMaps { | ||
22 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
23 | f.debug_struct("IdMaps") | ||
24 | .field("n_defs", &self.defs.len()) | ||
25 | .finish() | ||
26 | } | ||
27 | } | ||
28 | |||
21 | impl salsa::Database for RootDatabase { | 29 | impl salsa::Database for RootDatabase { |
22 | fn salsa_runtime(&self) -> &salsa::Runtime<RootDatabase> { | 30 | fn salsa_runtime(&self) -> &salsa::Runtime<RootDatabase> { |
23 | &self.runtime | 31 | &self.runtime |
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index b44d9297a..5701e1ae2 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs | |||
@@ -25,7 +25,7 @@ use crate::{ | |||
25 | db, | 25 | db, |
26 | symbol_index::{SymbolIndex, SymbolsDatabase, LibrarySymbolsQuery}, | 26 | symbol_index::{SymbolIndex, SymbolsDatabase, LibrarySymbolsQuery}, |
27 | AnalysisChange, RootChange, Cancelable, CrateId, Diagnostic, FileId, | 27 | AnalysisChange, RootChange, Cancelable, CrateId, Diagnostic, FileId, |
28 | FileSystemEdit, FilePosition, Query, SourceChange, SourceFileNodeEdit, | 28 | FileSystemEdit, FilePosition, Query, SourceChange, SourceFileEdit, |
29 | ReferenceResolution, | 29 | ReferenceResolution, |
30 | }; | 30 | }; |
31 | 31 | ||
@@ -368,10 +368,11 @@ impl AnalysisImpl { | |||
368 | .collect::<Vec<_>>(); | 368 | .collect::<Vec<_>>(); |
369 | if let Some(m) = source_binder::module_from_file_id(&*self.db, file_id)? { | 369 | if let Some(m) = source_binder::module_from_file_id(&*self.db, file_id)? { |
370 | for (name_node, problem) in m.problems(&*self.db) { | 370 | for (name_node, problem) in m.problems(&*self.db) { |
371 | let source_root = self.db.file_source_root(file_id); | ||
371 | let diag = match problem { | 372 | let diag = match problem { |
372 | Problem::UnresolvedModule { candidate } => { | 373 | Problem::UnresolvedModule { candidate } => { |
373 | let create_file = FileSystemEdit::CreateFile { | 374 | let create_file = FileSystemEdit::CreateFile { |
374 | anchor: file_id, | 375 | source_root, |
375 | path: candidate.clone(), | 376 | path: candidate.clone(), |
376 | }; | 377 | }; |
377 | let fix = SourceChange { | 378 | let fix = SourceChange { |
@@ -388,11 +389,12 @@ impl AnalysisImpl { | |||
388 | } | 389 | } |
389 | Problem::NotDirOwner { move_to, candidate } => { | 390 | Problem::NotDirOwner { move_to, candidate } => { |
390 | let move_file = FileSystemEdit::MoveFile { | 391 | let move_file = FileSystemEdit::MoveFile { |
391 | file: file_id, | 392 | src: file_id, |
392 | path: move_to.clone(), | 393 | dst_source_root: source_root, |
394 | dst_path: move_to.clone(), | ||
393 | }; | 395 | }; |
394 | let create_file = FileSystemEdit::CreateFile { | 396 | let create_file = FileSystemEdit::CreateFile { |
395 | anchor: file_id, | 397 | source_root, |
396 | path: move_to.join(candidate), | 398 | path: move_to.join(candidate), |
397 | }; | 399 | }; |
398 | let fix = SourceChange { | 400 | let fix = SourceChange { |
@@ -518,9 +520,9 @@ impl AnalysisImpl { | |||
518 | 520 | ||
519 | impl SourceChange { | 521 | impl SourceChange { |
520 | pub(crate) fn from_local_edit(file_id: FileId, label: &str, edit: LocalEdit) -> SourceChange { | 522 | pub(crate) fn from_local_edit(file_id: FileId, label: &str, edit: LocalEdit) -> SourceChange { |
521 | let file_edit = SourceFileNodeEdit { | 523 | let file_edit = SourceFileEdit { |
522 | file_id, | 524 | file_id, |
523 | edits: edit.edit.into_atoms(), | 525 | edit: edit.edit, |
524 | }; | 526 | }; |
525 | SourceChange { | 527 | SourceChange { |
526 | label: label.to_string(), | 528 | label: label.to_string(), |
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index a1d462528..c7e7dc1c0 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs | |||
@@ -20,7 +20,7 @@ use std::{fmt, sync::Arc}; | |||
20 | 20 | ||
21 | use rustc_hash::FxHashMap; | 21 | use rustc_hash::FxHashMap; |
22 | use ra_syntax::{SourceFileNode, TextRange, TextUnit}; | 22 | use ra_syntax::{SourceFileNode, TextRange, TextUnit}; |
23 | use ra_text_edit::AtomTextEdit; | 23 | use ra_text_edit::TextEdit; |
24 | use rayon::prelude::*; | 24 | use rayon::prelude::*; |
25 | use relative_path::RelativePathBuf; | 25 | use relative_path::RelativePathBuf; |
26 | 26 | ||
@@ -159,26 +159,27 @@ impl AnalysisHost { | |||
159 | #[derive(Debug)] | 159 | #[derive(Debug)] |
160 | pub struct SourceChange { | 160 | pub struct SourceChange { |
161 | pub label: String, | 161 | pub label: String, |
162 | pub source_file_edits: Vec<SourceFileNodeEdit>, | 162 | pub source_file_edits: Vec<SourceFileEdit>, |
163 | pub file_system_edits: Vec<FileSystemEdit>, | 163 | pub file_system_edits: Vec<FileSystemEdit>, |
164 | pub cursor_position: Option<FilePosition>, | 164 | pub cursor_position: Option<FilePosition>, |
165 | } | 165 | } |
166 | 166 | ||
167 | #[derive(Debug)] | 167 | #[derive(Debug)] |
168 | pub struct SourceFileNodeEdit { | 168 | pub struct SourceFileEdit { |
169 | pub file_id: FileId, | 169 | pub file_id: FileId, |
170 | pub edits: Vec<AtomTextEdit>, | 170 | pub edit: TextEdit, |
171 | } | 171 | } |
172 | 172 | ||
173 | #[derive(Debug)] | 173 | #[derive(Debug)] |
174 | pub enum FileSystemEdit { | 174 | pub enum FileSystemEdit { |
175 | CreateFile { | 175 | CreateFile { |
176 | anchor: FileId, | 176 | source_root: SourceRootId, |
177 | path: RelativePathBuf, | 177 | path: RelativePathBuf, |
178 | }, | 178 | }, |
179 | MoveFile { | 179 | MoveFile { |
180 | file: FileId, | 180 | src: FileId, |
181 | path: RelativePathBuf, | 181 | dst_source_root: SourceRootId, |
182 | dst_path: RelativePathBuf, | ||
182 | }, | 183 | }, |
183 | } | 184 | } |
184 | 185 | ||
diff --git a/crates/ra_analysis/tests/tests.rs b/crates/ra_analysis/tests/tests.rs index 889b568b9..67738da48 100644 --- a/crates/ra_analysis/tests/tests.rs +++ b/crates/ra_analysis/tests/tests.rs | |||
@@ -81,7 +81,7 @@ fn test_unresolved_module_diagnostic() { | |||
81 | fix: Some(SourceChange { | 81 | fix: Some(SourceChange { |
82 | label: "create module", | 82 | label: "create module", |
83 | source_file_edits: [], | 83 | source_file_edits: [], |
84 | file_system_edits: [CreateFile { anchor: FileId(1), path: "../foo.rs" }], | 84 | file_system_edits: [CreateFile { source_root: SourceRootId(0), path: "foo.rs" }], |
85 | cursor_position: None }) }]"#, | 85 | cursor_position: None }) }]"#, |
86 | &diagnostics, | 86 | &diagnostics, |
87 | ); | 87 | ); |