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.rs59
1 files changed, 12 insertions, 47 deletions
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs
index 981385466..20077a48a 100644
--- a/crates/ra_lsp_server/src/conv.rs
+++ b/crates/ra_lsp_server/src/conv.rs
@@ -82,11 +82,8 @@ impl ConvWith for CompletionItem {
82 fn conv_with(mut self, ctx: &LineIndex) -> ::lsp_types::CompletionItem { 82 fn conv_with(mut self, ctx: &LineIndex) -> ::lsp_types::CompletionItem {
83 let atom_text_edit = AtomTextEdit::replace(self.source_range(), self.insert_text()); 83 let atom_text_edit = AtomTextEdit::replace(self.source_range(), self.insert_text());
84 let text_edit = (&atom_text_edit).conv_with(ctx); 84 let text_edit = (&atom_text_edit).conv_with(ctx);
85 let additional_text_edits = if let Some(edit) = self.take_text_edit() { 85 let additional_text_edits =
86 Some(edit.conv_with(ctx)) 86 if let Some(edit) = self.take_text_edit() { Some(edit.conv_with(ctx)) } else { None };
87 } else {
88 None
89 };
90 87
91 let mut res = lsp_types::CompletionItem { 88 let mut res = lsp_types::CompletionItem {
92 label: self.label().to_string(), 89 label: self.label().to_string(),
@@ -112,10 +109,7 @@ impl ConvWith for Position {
112 type Output = TextUnit; 109 type Output = TextUnit;
113 110
114 fn conv_with(self, line_index: &LineIndex) -> TextUnit { 111 fn conv_with(self, line_index: &LineIndex) -> TextUnit {
115 let line_col = LineCol { 112 let line_col = LineCol { line: self.line as u32, col_utf16: self.character as u32 };
116 line: self.line as u32,
117 col_utf16: self.character as u32,
118 };
119 line_index.offset(line_col) 113 line_index.offset(line_col)
120 } 114 }
121} 115}
@@ -135,10 +129,7 @@ impl ConvWith for TextRange {
135 type Output = Range; 129 type Output = Range;
136 130
137 fn conv_with(self, line_index: &LineIndex) -> Range { 131 fn conv_with(self, line_index: &LineIndex) -> Range {
138 Range::new( 132 Range::new(self.start().conv_with(line_index), self.end().conv_with(line_index))
139 self.start().conv_with(line_index),
140 self.end().conv_with(line_index),
141 )
142 } 133 }
143} 134}
144 135
@@ -147,10 +138,7 @@ impl ConvWith for Range {
147 type Output = TextRange; 138 type Output = TextRange;
148 139
149 fn conv_with(self, line_index: &LineIndex) -> TextRange { 140 fn conv_with(self, line_index: &LineIndex) -> TextRange {
150 TextRange::from_to( 141 TextRange::from_to(self.start.conv_with(line_index), self.end.conv_with(line_index))
151 self.start.conv_with(line_index),
152 self.end.conv_with(line_index),
153 )
154 } 142 }
155} 143}
156 144
@@ -303,11 +291,7 @@ impl TryConvWith for SourceChange {
303 changes: None, 291 changes: None,
304 document_changes: Some(DocumentChanges::Operations(document_changes)), 292 document_changes: Some(DocumentChanges::Operations(document_changes)),
305 }; 293 };
306 Ok(req::SourceChange { 294 Ok(req::SourceChange { label: self.label, workspace_edit, cursor_position })
307 label: self.label,
308 workspace_edit,
309 cursor_position,
310 })
311 } 295 }
312} 296}
313 297
@@ -320,16 +304,8 @@ impl TryConvWith for SourceFileEdit {
320 version: None, 304 version: None,
321 }; 305 };
322 let line_index = world.analysis().file_line_index(self.file_id); 306 let line_index = world.analysis().file_line_index(self.file_id);
323 let edits = self 307 let edits = self.edit.as_atoms().iter().map_conv_with(&line_index).collect();
324 .edit 308 Ok(TextDocumentEdit { text_document, edits })
325 .as_atoms()
326 .iter()
327 .map_conv_with(&line_index)
328 .collect();
329 Ok(TextDocumentEdit {
330 text_document,
331 edits,
332 })
333 } 309 }
334} 310}
335 311
@@ -342,18 +318,10 @@ impl TryConvWith for FileSystemEdit {
342 let uri = world.path_to_uri(source_root, &path)?; 318 let uri = world.path_to_uri(source_root, &path)?;
343 ResourceOp::Create(CreateFile { uri, options: None }) 319 ResourceOp::Create(CreateFile { uri, options: None })
344 } 320 }
345 FileSystemEdit::MoveFile { 321 FileSystemEdit::MoveFile { src, dst_source_root, dst_path } => {
346 src,
347 dst_source_root,
348 dst_path,
349 } => {
350 let old_uri = world.file_id_to_uri(src)?; 322 let old_uri = world.file_id_to_uri(src)?;
351 let new_uri = world.path_to_uri(dst_source_root, &dst_path)?; 323 let new_uri = world.path_to_uri(dst_source_root, &dst_path)?;
352 ResourceOp::Rename(RenameFile { 324 ResourceOp::Rename(RenameFile { old_uri, new_uri, options: None })
353 old_uri,
354 new_uri,
355 options: None,
356 })
357 } 325 }
358 }; 326 };
359 Ok(res) 327 Ok(res)
@@ -381,11 +349,8 @@ pub fn to_location_link(
381 349
382 let target_range = target.info.full_range().conv_with(&tgt_line_index); 350 let target_range = target.info.full_range().conv_with(&tgt_line_index);
383 351
384 let target_selection_range = target 352 let target_selection_range =
385 .info 353 target.info.focus_range().map(|it| it.conv_with(&tgt_line_index)).unwrap_or(target_range);
386 .focus_range()
387 .map(|it| it.conv_with(&tgt_line_index))
388 .unwrap_or(target_range);
389 354
390 let res = LocationLink { 355 let res = LocationLink {
391 origin_selection_range: Some(target.range.conv_with(line_index)), 356 origin_selection_range: Some(target.range.conv_with(line_index)),