diff options
Diffstat (limited to 'crates/ra_lsp_server/src/main_loop/handlers.rs')
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 9b8d40eaa..3de440e1f 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -4,6 +4,7 @@ use languageserver_types::{ | |||
4 | CodeActionResponse, Command, CompletionItem, CompletionItemKind, Diagnostic, | 4 | CodeActionResponse, Command, CompletionItem, CompletionItemKind, Diagnostic, |
5 | DiagnosticSeverity, DocumentSymbol, FoldingRange, FoldingRangeKind, FoldingRangeParams, | 5 | DiagnosticSeverity, DocumentSymbol, FoldingRange, FoldingRangeKind, FoldingRangeParams, |
6 | InsertTextFormat, Location, Position, SymbolInformation, TextDocumentIdentifier, TextEdit, | 6 | InsertTextFormat, Location, Position, SymbolInformation, TextDocumentIdentifier, TextEdit, |
7 | RenameParams, WorkspaceEdit | ||
7 | }; | 8 | }; |
8 | use ra_analysis::{FileId, FoldKind, JobToken, Query, RunnableKind}; | 9 | use ra_analysis::{FileId, FoldKind, JobToken, Query, RunnableKind}; |
9 | use ra_syntax::text_utils::contains_offset_nonstrict; | 10 | use ra_syntax::text_utils::contains_offset_nonstrict; |
@@ -17,6 +18,8 @@ use crate::{ | |||
17 | Result, | 18 | Result, |
18 | }; | 19 | }; |
19 | 20 | ||
21 | use std::collections::HashMap; | ||
22 | |||
20 | pub fn handle_syntax_tree( | 23 | pub fn handle_syntax_tree( |
21 | world: ServerWorld, | 24 | world: ServerWorld, |
22 | params: req::SyntaxTreeParams, | 25 | params: req::SyntaxTreeParams, |
@@ -460,6 +463,43 @@ pub fn handle_signature_help( | |||
460 | } | 463 | } |
461 | } | 464 | } |
462 | 465 | ||
466 | pub fn handle_rename( | ||
467 | world: ServerWorld, | ||
468 | params: RenameParams, | ||
469 | token: JobToken, | ||
470 | ) -> Result<Option<WorkspaceEdit>> { | ||
471 | let file_id = params.text_document.try_conv_with(&world)?; | ||
472 | let line_index = world.analysis().file_line_index(file_id); | ||
473 | let offset = params.position.conv_with(&line_index); | ||
474 | |||
475 | if params.new_name.is_empty() { | ||
476 | return Ok(None); | ||
477 | } | ||
478 | |||
479 | let refs = world.analysis().find_all_refs(file_id, offset, &token); | ||
480 | if refs.is_empty() { | ||
481 | return Ok(None); | ||
482 | } | ||
483 | |||
484 | let mut changes = HashMap::new(); | ||
485 | for r in refs { | ||
486 | if let Ok(loc) = to_location(r.0, r.1, &world, &line_index) { | ||
487 | changes.entry(loc.uri).or_insert(Vec::new()).push( | ||
488 | TextEdit { | ||
489 | range: loc.range, | ||
490 | new_text: params.new_name.clone() | ||
491 | }); | ||
492 | } | ||
493 | } | ||
494 | |||
495 | Ok(Some(WorkspaceEdit { | ||
496 | changes: Some(changes), | ||
497 | |||
498 | // TODO: return this instead if client/server support it. See #144 | ||
499 | document_changes : None, | ||
500 | })) | ||
501 | } | ||
502 | |||
463 | pub fn handle_references( | 503 | pub fn handle_references( |
464 | world: ServerWorld, | 504 | world: ServerWorld, |
465 | params: req::ReferenceParams, | 505 | params: req::ReferenceParams, |