diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 24 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/mod.rs | 1 |
2 files changed, 24 insertions, 1 deletions
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 3de440e1f..639fe4553 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -4,7 +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 | RenameParams, WorkspaceEdit, PrepareRenameResponse |
8 | }; | 8 | }; |
9 | use ra_analysis::{FileId, FoldKind, JobToken, Query, RunnableKind}; | 9 | use ra_analysis::{FileId, FoldKind, JobToken, Query, RunnableKind}; |
10 | use ra_syntax::text_utils::contains_offset_nonstrict; | 10 | use ra_syntax::text_utils::contains_offset_nonstrict; |
@@ -463,6 +463,28 @@ pub fn handle_signature_help( | |||
463 | } | 463 | } |
464 | } | 464 | } |
465 | 465 | ||
466 | pub fn handle_prepare_rename( | ||
467 | world: ServerWorld, | ||
468 | params: req::TextDocumentPositionParams, | ||
469 | token: JobToken, | ||
470 | ) -> Result<Option<PrepareRenameResponse>> { | ||
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 | // We support renaming references like handle_rename does. | ||
476 | // In the future we may want to reject the renaming of things like keywords here too. | ||
477 | let refs = world.analysis().find_all_refs(file_id, offset, &token); | ||
478 | if refs.is_empty() { | ||
479 | return Ok(None); | ||
480 | } | ||
481 | |||
482 | let r = refs.first().unwrap(); | ||
483 | let loc = to_location(r.0, r.1, &world, &line_index)?; | ||
484 | |||
485 | Ok(Some(PrepareRenameResponse::Range(loc.range))) | ||
486 | } | ||
487 | |||
466 | pub fn handle_rename( | 488 | pub fn handle_rename( |
467 | world: ServerWorld, | 489 | world: ServerWorld, |
468 | params: RenameParams, | 490 | params: RenameParams, |
diff --git a/crates/ra_lsp_server/src/main_loop/mod.rs b/crates/ra_lsp_server/src/main_loop/mod.rs index 236746447..165f2e78f 100644 --- a/crates/ra_lsp_server/src/main_loop/mod.rs +++ b/crates/ra_lsp_server/src/main_loop/mod.rs | |||
@@ -248,6 +248,7 @@ fn on_request( | |||
248 | .on::<req::CodeActionRequest>(handlers::handle_code_action)? | 248 | .on::<req::CodeActionRequest>(handlers::handle_code_action)? |
249 | .on::<req::FoldingRangeRequest>(handlers::handle_folding_range)? | 249 | .on::<req::FoldingRangeRequest>(handlers::handle_folding_range)? |
250 | .on::<req::SignatureHelpRequest>(handlers::handle_signature_help)? | 250 | .on::<req::SignatureHelpRequest>(handlers::handle_signature_help)? |
251 | .on::<req::PrepareRenameRequest>(handlers::handle_prepare_rename)? | ||
251 | .on::<req::Rename>(handlers::handle_rename)? | 252 | .on::<req::Rename>(handlers::handle_rename)? |
252 | .on::<req::References>(handlers::handle_references)? | 253 | .on::<req::References>(handlers::handle_references)? |
253 | .finish(); | 254 | .finish(); |