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.rs42
-rw-r--r--crates/ra_lsp_server/src/main_loop/mod.rs7
2 files changed, 43 insertions, 6 deletions
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index ab8be15e9..5acb39b60 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -13,7 +13,7 @@ use ra_syntax::{
13 text_utils::contains_offset_nonstrict 13 text_utils::contains_offset_nonstrict
14}; 14};
15 15
16use ::{ 16use crate::{
17 req::{self, Decoration}, Result, 17 req::{self, Decoration}, Result,
18 conv::{Conv, ConvWith, TryConvWith, MapConvWith, to_location}, 18 conv::{Conv, ConvWith, TryConvWith, MapConvWith, to_location},
19 server_world::ServerWorld, 19 server_world::ServerWorld,
@@ -411,6 +411,42 @@ pub fn handle_folding_range(
411 Ok(res) 411 Ok(res)
412} 412}
413 413
414pub fn handle_signature_help(
415 world: ServerWorld,
416 params: req::TextDocumentPositionParams,
417 token: JobToken,
418) -> Result<Option<req::SignatureHelp>> {
419 use languageserver_types::{ParameterInformation, SignatureInformation};
420
421 let file_id = params.text_document.try_conv_with(&world)?;
422 let line_index = world.analysis().file_line_index(file_id);
423 let offset = params.position.conv_with(&line_index);
424
425 if let Some((descriptor, active_param)) = world.analysis().resolve_callable(file_id, offset, &token) {
426 let parameters : Vec<ParameterInformation> =
427 descriptor.params.iter().map(|param|
428 ParameterInformation {
429 label: param.clone(),
430 documentation: None
431 }
432 ).collect();
433
434 let sig_info = SignatureInformation {
435 label: descriptor.label,
436 documentation: None,
437 parameters: Some(parameters)
438 };
439
440 Ok(Some(req::SignatureHelp {
441 signatures: vec![sig_info],
442 active_signature: Some(0),
443 active_parameter: active_param.map(|a| a as u64)
444 }))
445 } else {
446 Ok(None)
447 }
448}
449
414pub fn handle_code_action( 450pub fn handle_code_action(
415 world: ServerWorld, 451 world: ServerWorld,
416 params: req::CodeActionParams, 452 params: req::CodeActionParams,
@@ -442,7 +478,7 @@ pub fn handle_code_action(
442} 478}
443 479
444pub fn publish_diagnostics( 480pub fn publish_diagnostics(
445 world: ServerWorld, 481 world: &ServerWorld,
446 file_id: FileId, 482 file_id: FileId,
447) -> Result<req::PublishDiagnosticsParams> { 483) -> Result<req::PublishDiagnosticsParams> {
448 let uri = world.file_id_to_uri(file_id)?; 484 let uri = world.file_id_to_uri(file_id)?;
@@ -461,7 +497,7 @@ pub fn publish_diagnostics(
461} 497}
462 498
463pub fn publish_decorations( 499pub fn publish_decorations(
464 world: ServerWorld, 500 world: &ServerWorld,
465 file_id: FileId, 501 file_id: FileId,
466) -> Result<req::PublishDecorationsParams> { 502) -> Result<req::PublishDecorationsParams> {
467 let uri = world.file_id_to_uri(file_id)?; 503 let uri = world.file_id_to_uri(file_id)?;
diff --git a/crates/ra_lsp_server/src/main_loop/mod.rs b/crates/ra_lsp_server/src/main_loop/mod.rs
index 402615e42..cf2477cb5 100644
--- a/crates/ra_lsp_server/src/main_loop/mod.rs
+++ b/crates/ra_lsp_server/src/main_loop/mod.rs
@@ -16,7 +16,7 @@ use gen_lsp_server::{
16}; 16};
17use rustc_hash::FxHashMap; 17use rustc_hash::FxHashMap;
18 18
19use { 19use crate::{
20 req, 20 req,
21 Result, 21 Result,
22 vfs::{self, FileEvent}, 22 vfs::{self, FileEvent},
@@ -255,6 +255,7 @@ fn on_request(
255 .on::<req::Completion>(handlers::handle_completion)? 255 .on::<req::Completion>(handlers::handle_completion)?
256 .on::<req::CodeActionRequest>(handlers::handle_code_action)? 256 .on::<req::CodeActionRequest>(handlers::handle_code_action)?
257 .on::<req::FoldingRangeRequest>(handlers::handle_folding_range)? 257 .on::<req::FoldingRangeRequest>(handlers::handle_folding_range)?
258 .on::<req::SignatureHelpRequest>(handlers::handle_signature_help)?
258 .finish(); 259 .finish();
259 match req { 260 match req {
260 Ok((id, handle)) => { 261 Ok((id, handle)) => {
@@ -390,7 +391,7 @@ fn update_file_notifications_on_threadpool(
390) { 391) {
391 pool.spawn(move || { 392 pool.spawn(move || {
392 for file_id in subscriptions { 393 for file_id in subscriptions {
393 match handlers::publish_diagnostics(world.clone(), file_id) { 394 match handlers::publish_diagnostics(&world, file_id) {
394 Err(e) => { 395 Err(e) => {
395 error!("failed to compute diagnostics: {:?}", e) 396 error!("failed to compute diagnostics: {:?}", e)
396 } 397 }
@@ -399,7 +400,7 @@ fn update_file_notifications_on_threadpool(
399 sender.send(Task::Notify(not)); 400 sender.send(Task::Notify(not));
400 } 401 }
401 } 402 }
402 match handlers::publish_decorations(world.clone(), file_id) { 403 match handlers::publish_decorations(&world, file_id) {
403 Err(e) => { 404 Err(e) => {
404 error!("failed to compute decorations: {:?}", e) 405 error!("failed to compute decorations: {:?}", e)
405 } 406 }