aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-12-21 09:18:14 +0000
committerAleksey Kladov <[email protected]>2018-12-21 09:18:14 +0000
commitb5b44659a42cf982590519317ede9ead354f9c4e (patch)
tree460d82184faa07256e77cf8b353e135f2b935d1e /crates/ra_lsp_server/src
parent0063f03e86f4222a5027720142eb20db4adc485d (diff)
edits use source-root API
Diffstat (limited to 'crates/ra_lsp_server/src')
-rw-r--r--crates/ra_lsp_server/src/conv.rs17
-rw-r--r--crates/ra_lsp_server/src/server_world.rs10
2 files changed, 18 insertions, 9 deletions
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};
11use ra_vfs::{Vfs, VfsChange, VfsFile}; 11use ra_vfs::{Vfs, VfsChange, VfsFile, VfsRoot};
12use rustc_hash::FxHashMap; 12use rustc_hash::FxHashMap;
13use relative_path::RelativePathBuf; 13use relative_path::RelativePathBuf;
14use parking_lot::RwLock; 14use 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}