diff options
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 10 | ||||
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 7 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/conv.rs | 17 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/server_world.rs | 10 |
4 files changed, 28 insertions, 16 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index a7be56f5a..5701e1ae2 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs | |||
@@ -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 { |
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 2fb11365c..c7e7dc1c0 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs | |||
@@ -173,12 +173,13 @@ pub struct SourceFileEdit { | |||
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_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index 3531b727e..218ded4ee 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs | |||
@@ -283,16 +283,17 @@ impl TryConvWith for FileSystemEdit { | |||
283 | type Output = req::FileSystemEdit; | 283 | type Output = req::FileSystemEdit; |
284 | fn try_conv_with(self, world: &ServerWorld) -> Result<req::FileSystemEdit> { | 284 | fn try_conv_with(self, world: &ServerWorld) -> Result<req::FileSystemEdit> { |
285 | let res = match self { | 285 | let res = match self { |
286 | FileSystemEdit::CreateFile { anchor, path } => { | 286 | FileSystemEdit::CreateFile { source_root, path } => { |
287 | let uri = world.file_id_to_uri(anchor)?; | 287 | let uri = world.path_to_uri(source_root, &path)?; |
288 | let path = &path.as_str()[3..]; // strip `../` b/c url is weird | ||
289 | let uri = uri.join(path)?; | ||
290 | req::FileSystemEdit::CreateFile { uri } | 288 | req::FileSystemEdit::CreateFile { uri } |
291 | } | 289 | } |
292 | FileSystemEdit::MoveFile { file, path } => { | 290 | FileSystemEdit::MoveFile { |
293 | let src = world.file_id_to_uri(file)?; | 291 | src, |
294 | let path = &path.as_str()[3..]; // strip `../` b/c url is weird | 292 | dst_source_root, |
295 | let dst = src.join(path)?; | 293 | dst_path, |
294 | } => { | ||
295 | let src = world.file_id_to_uri(src)?; | ||
296 | let dst = world.path_to_uri(dst_source_root, &dst_path)?; | ||
296 | req::FileSystemEdit::MoveFile { src, dst } | 297 | req::FileSystemEdit::MoveFile { src, dst } |
297 | } | 298 | } |
298 | }; | 299 | }; |
diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs index 785877c4b..73cccc9dd 100644 --- a/crates/ra_lsp_server/src/server_world.rs +++ b/crates/ra_lsp_server/src/server_world.rs | |||
@@ -8,7 +8,7 @@ use ra_analysis::{ | |||
8 | Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, LibraryData, | 8 | Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, LibraryData, |
9 | SourceRootId | 9 | SourceRootId |
10 | }; | 10 | }; |
11 | use ra_vfs::{Vfs, VfsChange, VfsFile}; | 11 | use ra_vfs::{Vfs, VfsChange, VfsFile, VfsRoot}; |
12 | use rustc_hash::FxHashMap; | 12 | use rustc_hash::FxHashMap; |
13 | use relative_path::RelativePathBuf; | 13 | use relative_path::RelativePathBuf; |
14 | use parking_lot::RwLock; | 14 | use parking_lot::RwLock; |
@@ -183,4 +183,12 @@ impl ServerWorld { | |||
183 | .map_err(|_| format_err!("can't convert path to url: {}", path.display()))?; | 183 | .map_err(|_| format_err!("can't convert path to url: {}", path.display()))?; |
184 | Ok(url) | 184 | Ok(url) |
185 | } | 185 | } |
186 | |||
187 | pub fn path_to_uri(&self, root: SourceRootId, path: &RelativePathBuf) -> Result<Url> { | ||
188 | let base = self.vfs.read().root2path(VfsRoot(root.0)); | ||
189 | let path = path.to_path(base); | ||
190 | let url = Url::from_file_path(&path) | ||
191 | .map_err(|_| format_err!("can't convert path to url: {}", path.display()))?; | ||
192 | Ok(url) | ||
193 | } | ||
186 | } | 194 | } |