]> git.lizzy.rs Git - rust.git/commitdiff
edits use source-root API
authorAleksey Kladov <aleksey.kladov@gmail.com>
Fri, 21 Dec 2018 09:18:14 +0000 (12:18 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Fri, 21 Dec 2018 09:18:14 +0000 (12:18 +0300)
crates/ra_analysis/src/imp.rs
crates/ra_analysis/src/lib.rs
crates/ra_lsp_server/src/conv.rs
crates/ra_lsp_server/src/server_world.rs

index a7be56f5a19eafb67c7a2896a23a3814148a2366..5701e1ae233aa35b13d6b19520bbefd53caff12c 100644 (file)
@@ -368,10 +368,11 @@ pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> {
             .collect::<Vec<_>>();
         if let Some(m) = source_binder::module_from_file_id(&*self.db, file_id)? {
             for (name_node, problem) in m.problems(&*self.db) {
+                let source_root = self.db.file_source_root(file_id);
                 let diag = match problem {
                     Problem::UnresolvedModule { candidate } => {
                         let create_file = FileSystemEdit::CreateFile {
-                            anchor: file_id,
+                            source_root,
                             path: candidate.clone(),
                         };
                         let fix = SourceChange {
@@ -388,11 +389,12 @@ pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> {
                     }
                     Problem::NotDirOwner { move_to, candidate } => {
                         let move_file = FileSystemEdit::MoveFile {
-                            file: file_id,
-                            path: move_to.clone(),
+                            src: file_id,
+                            dst_source_root: source_root,
+                            dst_path: move_to.clone(),
                         };
                         let create_file = FileSystemEdit::CreateFile {
-                            anchor: file_id,
+                            source_root,
                             path: move_to.join(candidate),
                         };
                         let fix = SourceChange {
index 2fb11365c3d8427168e5517ce460a504aad0d3e2..c7e7dc1c030acca359c990da30e5d0ac000e8b1f 100644 (file)
@@ -173,12 +173,13 @@ pub struct SourceFileEdit {
 #[derive(Debug)]
 pub enum FileSystemEdit {
     CreateFile {
-        anchor: FileId,
+        source_root: SourceRootId,
         path: RelativePathBuf,
     },
     MoveFile {
-        file: FileId,
-        path: RelativePathBuf,
+        src: FileId,
+        dst_source_root: SourceRootId,
+        dst_path: RelativePathBuf,
     },
 }
 
index 3531b727e98cdd4d86979658632481d3e2430b40..218ded4eecf9138a77ed2be435ea0292e3b65b76 100644 (file)
@@ -283,16 +283,17 @@ impl TryConvWith for FileSystemEdit {
     type Output = req::FileSystemEdit;
     fn try_conv_with(self, world: &ServerWorld) -> Result<req::FileSystemEdit> {
         let res = match self {
-            FileSystemEdit::CreateFile { anchor, path } => {
-                let uri = world.file_id_to_uri(anchor)?;
-                let path = &path.as_str()[3..]; // strip `../` b/c url is weird
-                let uri = uri.join(path)?;
+            FileSystemEdit::CreateFile { source_root, path } => {
+                let uri = world.path_to_uri(source_root, &path)?;
                 req::FileSystemEdit::CreateFile { uri }
             }
-            FileSystemEdit::MoveFile { file, path } => {
-                let src = world.file_id_to_uri(file)?;
-                let path = &path.as_str()[3..]; // strip `../` b/c url is weird
-                let dst = src.join(path)?;
+            FileSystemEdit::MoveFile {
+                src,
+                dst_source_root,
+                dst_path,
+            } => {
+                let src = world.file_id_to_uri(src)?;
+                let dst = world.path_to_uri(dst_source_root, &dst_path)?;
                 req::FileSystemEdit::MoveFile { src, dst }
             }
         };
index 785877c4ba3a9806d0863fa710178fc45c778952..73cccc9dd901650155360791937620aba2a8dddf 100644 (file)
@@ -8,7 +8,7 @@
     Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, LibraryData,
     SourceRootId
 };
-use ra_vfs::{Vfs, VfsChange, VfsFile};
+use ra_vfs::{Vfs, VfsChange, VfsFile, VfsRoot};
 use rustc_hash::FxHashMap;
 use relative_path::RelativePathBuf;
 use parking_lot::RwLock;
@@ -183,4 +183,12 @@ pub fn file_id_to_uri(&self, id: FileId) -> Result<Url> {
             .map_err(|_| format_err!("can't convert path to url: {}", path.display()))?;
         Ok(url)
     }
+
+    pub fn path_to_uri(&self, root: SourceRootId, path: &RelativePathBuf) -> Result<Url> {
+        let base = self.vfs.read().root2path(VfsRoot(root.0));
+        let path = path.to_path(base);
+        let url = Url::from_file_path(&path)
+            .map_err(|_| format_err!("can't convert path to url: {}", path.display()))?;
+        Ok(url)
+    }
 }