aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_analysis/src/imp.rs12
-rw-r--r--crates/ra_analysis/src/lib.rs11
-rw-r--r--crates/ra_analysis/tests/tests.rs2
-rw-r--r--crates/ra_hir/src/module/imp.rs8
-rw-r--r--crates/ra_lsp_server/src/conv.rs32
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs11
-rw-r--r--crates/ra_lsp_server/src/server_world.rs10
-rw-r--r--crates/ra_text_edit/src/text_edit.rs4
8 files changed, 55 insertions, 35 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index cefe5a748..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 {
@@ -520,7 +522,7 @@ 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 = SourceFileEdit { 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 d5725ef2e..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
21use rustc_hash::FxHashMap; 21use rustc_hash::FxHashMap;
22use ra_syntax::{SourceFileNode, TextRange, TextUnit}; 22use ra_syntax::{SourceFileNode, TextRange, TextUnit};
23use ra_text_edit::AtomTextEdit; 23use ra_text_edit::TextEdit;
24use rayon::prelude::*; 24use rayon::prelude::*;
25use relative_path::RelativePathBuf; 25use relative_path::RelativePathBuf;
26 26
@@ -167,18 +167,19 @@ pub struct SourceChange {
167#[derive(Debug)] 167#[derive(Debug)]
168pub struct SourceFileEdit { 168pub 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)]
174pub enum FileSystemEdit { 174pub 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 );
diff --git a/crates/ra_hir/src/module/imp.rs b/crates/ra_hir/src/module/imp.rs
index f3a346152..748fdb64e 100644
--- a/crates/ra_hir/src/module/imp.rs
+++ b/crates/ra_hir/src/module/imp.rs
@@ -4,7 +4,7 @@ use ra_syntax::{
4 ast::{self, NameOwner}, 4 ast::{self, NameOwner},
5 SmolStr, 5 SmolStr,
6}; 6};
7use relative_path::{RelativePathBuf, RelativePath}; 7use relative_path::RelativePathBuf;
8use rustc_hash::{FxHashMap, FxHashSet}; 8use rustc_hash::{FxHashMap, FxHashSet};
9use arrayvec::ArrayVec; 9use arrayvec::ArrayVec;
10use ra_db::{SourceRoot, SourceRootId, Cancelable, FileId}; 10use ra_db::{SourceRoot, SourceRootId, Cancelable, FileId};
@@ -184,11 +184,7 @@ fn resolve_submodule(
184 .collect::<Vec<_>>(); 184 .collect::<Vec<_>>();
185 let problem = if points_to.is_empty() { 185 let problem = if points_to.is_empty() {
186 Some(Problem::UnresolvedModule { 186 Some(Problem::UnresolvedModule {
187 candidate: RelativePath::new("../").join(&if is_dir_owner { 187 candidate: if is_dir_owner { file_mod } else { file_dir_mod },
188 file_mod
189 } else {
190 file_dir_mod
191 }),
192 }) 188 })
193 } else { 189 } else {
194 None 190 None
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs
index 198dbfc49..218ded4ee 100644
--- a/crates/ra_lsp_server/src/conv.rs
+++ b/crates/ra_lsp_server/src/conv.rs
@@ -97,21 +97,21 @@ impl ConvWith for TextEdit {
97 type Output = Vec<languageserver_types::TextEdit>; 97 type Output = Vec<languageserver_types::TextEdit>;
98 98
99 fn conv_with(self, line_index: &LineIndex) -> Vec<languageserver_types::TextEdit> { 99 fn conv_with(self, line_index: &LineIndex) -> Vec<languageserver_types::TextEdit> {
100 self.into_atoms() 100 self.as_atoms()
101 .into_iter() 101 .into_iter()
102 .map_conv_with(line_index) 102 .map_conv_with(line_index)
103 .collect() 103 .collect()
104 } 104 }
105} 105}
106 106
107impl ConvWith for AtomTextEdit { 107impl<'a> ConvWith for &'a AtomTextEdit {
108 type Ctx = LineIndex; 108 type Ctx = LineIndex;
109 type Output = languageserver_types::TextEdit; 109 type Output = languageserver_types::TextEdit;
110 110
111 fn conv_with(self, line_index: &LineIndex) -> languageserver_types::TextEdit { 111 fn conv_with(self, line_index: &LineIndex) -> languageserver_types::TextEdit {
112 languageserver_types::TextEdit { 112 languageserver_types::TextEdit {
113 range: self.delete.conv_with(line_index), 113 range: self.delete.conv_with(line_index),
114 new_text: self.insert, 114 new_text: self.insert.clone(),
115 } 115 }
116 } 116 }
117} 117}
@@ -199,7 +199,7 @@ impl TryConvWith for SourceChange {
199 .source_file_edits 199 .source_file_edits
200 .iter() 200 .iter()
201 .find(|it| it.file_id == pos.file_id) 201 .find(|it| it.file_id == pos.file_id)
202 .map(|it| it.edits.as_slice()) 202 .map(|it| it.edit.as_atoms())
203 .unwrap_or(&[]); 203 .unwrap_or(&[]);
204 let line_col = translate_offset_with_edit(&*line_index, pos.offset, edits); 204 let line_col = translate_offset_with_edit(&*line_index, pos.offset, edits);
205 let position = 205 let position =
@@ -265,7 +265,12 @@ impl TryConvWith for SourceFileEdit {
265 version: None, 265 version: None,
266 }; 266 };
267 let line_index = world.analysis().file_line_index(self.file_id); 267 let line_index = world.analysis().file_line_index(self.file_id);
268 let edits = self.edits.into_iter().map_conv_with(&line_index).collect(); 268 let edits = self
269 .edit
270 .as_atoms()
271 .iter()
272 .map_conv_with(&line_index)
273 .collect();
269 Ok(TextDocumentEdit { 274 Ok(TextDocumentEdit {
270 text_document, 275 text_document,
271 edits, 276 edits,
@@ -278,16 +283,17 @@ impl TryConvWith for FileSystemEdit {
278 type Output = req::FileSystemEdit; 283 type Output = req::FileSystemEdit;
279 fn try_conv_with(self, world: &ServerWorld) -> Result<req::FileSystemEdit> { 284 fn try_conv_with(self, world: &ServerWorld) -> Result<req::FileSystemEdit> {
280 let res = match self { 285 let res = match self {
281 FileSystemEdit::CreateFile { anchor, path } => { 286 FileSystemEdit::CreateFile { source_root, path } => {
282 let uri = world.file_id_to_uri(anchor)?; 287 let uri = world.path_to_uri(source_root, &path)?;
283 let path = &path.as_str()[3..]; // strip `../` b/c url is weird
284 let uri = uri.join(path)?;
285 req::FileSystemEdit::CreateFile { uri } 288 req::FileSystemEdit::CreateFile { uri }
286 } 289 }
287 FileSystemEdit::MoveFile { file, path } => { 290 FileSystemEdit::MoveFile {
288 let src = world.file_id_to_uri(file)?; 291 src,
289 let path = &path.as_str()[3..]; // strip `../` b/c url is weird 292 dst_source_root,
290 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)?;
291 req::FileSystemEdit::MoveFile { src, dst } 297 req::FileSystemEdit::MoveFile { src, dst }
292 } 298 }
293 }; 299 };
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index 801966304..1751d7fa8 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -107,9 +107,16 @@ pub fn handle_on_type_formatting(
107 }; 107 };
108 let edits = match world.analysis().on_eq_typed(position) { 108 let edits = match world.analysis().on_eq_typed(position) {
109 None => return Ok(None), 109 None => return Ok(None),
110 Some(mut action) => action.source_file_edits.pop().unwrap().edits, 110 Some(mut action) => action
111 .source_file_edits
112 .pop()
113 .unwrap()
114 .edit
115 .as_atoms()
116 .iter()
117 .map_conv_with(&line_index)
118 .collect(),
111 }; 119 };
112 let edits = edits.into_iter().map_conv_with(&line_index).collect();
113 Ok(Some(edits)) 120 Ok(Some(edits))
114} 121}
115 122
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}
diff --git a/crates/ra_text_edit/src/text_edit.rs b/crates/ra_text_edit/src/text_edit.rs
index fb46f046d..392968d63 100644
--- a/crates/ra_text_edit/src/text_edit.rs
+++ b/crates/ra_text_edit/src/text_edit.rs
@@ -41,8 +41,8 @@ impl TextEditBuilder {
41} 41}
42 42
43impl TextEdit { 43impl TextEdit {
44 pub fn into_atoms(self) -> Vec<AtomTextEdit> { 44 pub fn as_atoms(&self) -> &[AtomTextEdit] {
45 self.atoms 45 &self.atoms
46 } 46 }
47 47
48 pub fn apply(&self, text: &str) -> String { 48 pub fn apply(&self, text: &str) -> String {