aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src/main_loop
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_lsp_server/src/main_loop')
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs47
1 files changed, 31 insertions, 16 deletions
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index 11a705200..c010a6ddf 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -1,5 +1,3 @@
1use std::collections::HashMap;
2
3use gen_lsp_server::ErrorCode; 1use gen_lsp_server::ErrorCode;
4use lsp_types::{ 2use lsp_types::{
5 CodeActionResponse, CodeLens, Command, Diagnostic, DiagnosticSeverity, 3 CodeActionResponse, CodeLens, Command, Diagnostic, DiagnosticSeverity,
@@ -7,7 +5,7 @@ use lsp_types::{
7 FoldingRangeKind, FoldingRangeParams, Hover, HoverContents, Location, MarkupContent, 5 FoldingRangeKind, FoldingRangeParams, Hover, HoverContents, Location, MarkupContent,
8 MarkupKind, ParameterInformation, ParameterLabel, Position, PrepareRenameResponse, Range, 6 MarkupKind, ParameterInformation, ParameterLabel, Position, PrepareRenameResponse, Range,
9 RenameParams, SignatureInformation, SymbolInformation, TextDocumentIdentifier, TextEdit, 7 RenameParams, SignatureInformation, SymbolInformation, TextDocumentIdentifier, TextEdit,
10 WorkspaceEdit, 8 WorkspaceEdit, DocumentChanges, TextDocumentEdit, DocumentChangeOperation, ResourceOp
11}; 9};
12use ra_ide_api::{ 10use ra_ide_api::{
13 FileId, FilePosition, FileRange, FoldKind, Query, RangeInfo, RunnableKind, Severity, 11 FileId, FilePosition, FileRange, FoldKind, Query, RangeInfo, RunnableKind, Severity,
@@ -467,26 +465,43 @@ pub fn handle_rename(world: ServerWorld, params: RenameParams) -> Result<Option<
467 .into()); 465 .into());
468 } 466 }
469 467
470 let renames = world 468 let change = world
471 .analysis() 469 .analysis()
472 .rename(FilePosition { file_id, offset }, &*params.new_name)?; 470 .rename(FilePosition { file_id, offset }, &*params.new_name)?;
473 if renames.is_empty() { 471 if change.is_none() {
474 return Ok(None); 472 return Ok(None);
475 } 473 }
476 474
477 let mut changes = HashMap::new(); 475 let mut source_change = change.unwrap();
478 for edit in renames { 476 let text_document_edits = source_change
479 changes 477 .source_file_edits
480 .entry(file_id.try_conv_with(&world)?) 478 .drain(..)
481 .or_insert_with(Vec::new) 479 .into_iter()
482 .extend(edit.edit.conv_with(&line_index)); 480 .map(|e| e.try_conv_with(&world))
483 } 481 .collect::<Result<Vec<TextDocumentEdit>>>();
484 482
485 Ok(Some(WorkspaceEdit { 483 let text_document_ops = source_change
486 changes: Some(changes), 484 .file_system_edits
485 .drain(..)
486 .into_iter()
487 .map(|e| e.try_conv_with(&world))
488 .collect::<Result<Vec<ResourceOp>>>();
487 489
488 // TODO: return this instead if client/server support it. See #144 490 let mut document_changes = Vec::new();
489 document_changes: None, 491 document_changes.extend(
492 text_document_edits?
493 .into_iter()
494 .map(DocumentChangeOperation::Edit),
495 );
496 document_changes.extend(
497 text_document_ops?
498 .into_iter()
499 .map(DocumentChangeOperation::Op),
500 );
501
502 Ok(Some(WorkspaceEdit {
503 changes: None,
504 document_changes: Some(DocumentChanges::Operations(document_changes)),
490 })) 505 }))
491} 506}
492 507