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.rs40
-rw-r--r--crates/ra_lsp_server/src/main_loop/mod.rs1
2 files changed, 41 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};
8use ra_analysis::{FileId, FoldKind, JobToken, Query, RunnableKind}; 9use ra_analysis::{FileId, FoldKind, JobToken, Query, RunnableKind};
9use ra_syntax::text_utils::contains_offset_nonstrict; 10use ra_syntax::text_utils::contains_offset_nonstrict;
@@ -17,6 +18,8 @@ use crate::{
17 Result, 18 Result,
18}; 19};
19 20
21use std::collections::HashMap;
22
20pub fn handle_syntax_tree( 23pub 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
466pub 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
463pub fn handle_references( 503pub fn handle_references(
464 world: ServerWorld, 504 world: ServerWorld,
465 params: req::ReferenceParams, 505 params: req::ReferenceParams,
diff --git a/crates/ra_lsp_server/src/main_loop/mod.rs b/crates/ra_lsp_server/src/main_loop/mod.rs
index 7efec8a7a..236746447 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::Rename>(handlers::handle_rename)?
251 .on::<req::References>(handlers::handle_references)? 252 .on::<req::References>(handlers::handle_references)?
252 .finish(); 253 .finish();
253 match req { 254 match req {