aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src/conv.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_lsp_server/src/conv.rs')
-rw-r--r--crates/ra_lsp_server/src/conv.rs30
1 files changed, 19 insertions, 11 deletions
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs
index bbe140b7a..bd1ffd8f5 100644
--- a/crates/ra_lsp_server/src/conv.rs
+++ b/crates/ra_lsp_server/src/conv.rs
@@ -11,6 +11,7 @@ use ra_ide_api::{
11}; 11};
12use ra_syntax::{SyntaxKind, TextRange, TextUnit}; 12use ra_syntax::{SyntaxKind, TextRange, TextUnit};
13use ra_text_edit::{AtomTextEdit, TextEdit}; 13use ra_text_edit::{AtomTextEdit, TextEdit};
14use ra_vfs::LineEndings;
14 15
15use crate::{req, world::WorldSnapshot, Result}; 16use crate::{req, world::WorldSnapshot, Result};
16 17
@@ -88,10 +89,10 @@ impl Conv for Severity {
88 } 89 }
89} 90}
90 91
91impl ConvWith<&'_ LineIndex> for CompletionItem { 92impl ConvWith<(&'_ LineIndex, LineEndings)> for CompletionItem {
92 type Output = ::lsp_types::CompletionItem; 93 type Output = ::lsp_types::CompletionItem;
93 94
94 fn conv_with(self, ctx: &LineIndex) -> ::lsp_types::CompletionItem { 95 fn conv_with(self, ctx: (&LineIndex, LineEndings)) -> ::lsp_types::CompletionItem {
95 let mut additional_text_edits = Vec::new(); 96 let mut additional_text_edits = Vec::new();
96 let mut text_edit = None; 97 let mut text_edit = None;
97 // LSP does not allow arbitrary edits in completion, so we have to do a 98 // LSP does not allow arbitrary edits in completion, so we have to do a
@@ -202,22 +203,27 @@ impl Conv for ra_ide_api::FunctionSignature {
202 } 203 }
203} 204}
204 205
205impl ConvWith<&'_ LineIndex> for TextEdit { 206impl ConvWith<(&'_ LineIndex, LineEndings)> for TextEdit {
206 type Output = Vec<lsp_types::TextEdit>; 207 type Output = Vec<lsp_types::TextEdit>;
207 208
208 fn conv_with(self, line_index: &LineIndex) -> Vec<lsp_types::TextEdit> { 209 fn conv_with(self, ctx: (&LineIndex, LineEndings)) -> Vec<lsp_types::TextEdit> {
209 self.as_atoms().iter().map_conv_with(line_index).collect() 210 self.as_atoms().iter().map_conv_with(ctx).collect()
210 } 211 }
211} 212}
212 213
213impl ConvWith<&'_ LineIndex> for &'_ AtomTextEdit { 214impl ConvWith<(&'_ LineIndex, LineEndings)> for &'_ AtomTextEdit {
214 type Output = lsp_types::TextEdit; 215 type Output = lsp_types::TextEdit;
215 216
216 fn conv_with(self, line_index: &LineIndex) -> lsp_types::TextEdit { 217 fn conv_with(
217 lsp_types::TextEdit { 218 self,
218 range: self.delete.conv_with(line_index), 219 (line_index, line_endings): (&LineIndex, LineEndings),
219 new_text: self.insert.clone(), 220 ) -> lsp_types::TextEdit {
221 eprintln!("line_endings = {:?}", line_endings);
222 let mut new_text = self.insert.clone();
223 if line_endings == LineEndings::Dos {
224 new_text = new_text.replace('\n', "\r\n");
220 } 225 }
226 lsp_types::TextEdit { range: self.delete.conv_with(line_index), new_text }
221 } 227 }
222} 228}
223 229
@@ -352,7 +358,9 @@ impl TryConvWith for SourceFileEdit {
352 version: None, 358 version: None,
353 }; 359 };
354 let line_index = world.analysis().file_line_index(self.file_id)?; 360 let line_index = world.analysis().file_line_index(self.file_id)?;
355 let edits = self.edit.as_atoms().iter().map_conv_with(&line_index).collect(); 361 let line_endings = world.file_line_endings(self.file_id);
362 let edits =
363 self.edit.as_atoms().iter().map_conv_with((&line_index, line_endings)).collect();
356 Ok(TextDocumentEdit { text_document, edits }) 364 Ok(TextDocumentEdit { text_document, edits })
357 } 365 }
358} 366}