diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-21 09:33:45 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-21 09:33:45 +0000 |
commit | 4f7ec0170353e61c148909d2716c915578392a7b (patch) | |
tree | c4a7a0dae2ccbc6b6d987faca8002a22d0253382 /crates/ra_lsp_server/src/conv.rs | |
parent | 164d53b22f345e50c67781af545310d2193e8a5c (diff) | |
parent | fd927ea3a9ea687ba11b01e56579f0287221f55c (diff) |
Merge #309
309: Fix edits r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_lsp_server/src/conv.rs')
-rw-r--r-- | crates/ra_lsp_server/src/conv.rs | 32 |
1 files changed, 19 insertions, 13 deletions
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 | ||
107 | impl ConvWith for AtomTextEdit { | 107 | impl<'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 | }; |