aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src/main_loop
diff options
context:
space:
mode:
authorJeremy A. Kolb <[email protected]>2018-10-09 15:08:17 +0100
committerJeremy A. Kolb <[email protected]>2018-10-11 21:40:46 +0100
commitf8a2b533045757c42c206b2596448baf4737f1f0 (patch)
tree587e681ec5323d8deabcc6d533de033e7aa79be7 /crates/ra_lsp_server/src/main_loop
parent2ba6f18586d02a6dbc32e0bea88f7b4236277ea1 (diff)
Language Server: textDocument/signatureHelp
Implements a pretty barebones function signature help mechanism in the language server. Users can use `Analysis::resolve_callback()` to get basic information about a call site. Fixes #102
Diffstat (limited to 'crates/ra_lsp_server/src/main_loop')
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs36
-rw-r--r--crates/ra_lsp_server/src/main_loop/mod.rs1
2 files changed, 37 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 ab8be15e9..f65e2a889 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -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,
diff --git a/crates/ra_lsp_server/src/main_loop/mod.rs b/crates/ra_lsp_server/src/main_loop/mod.rs
index 402615e42..f4e7cfc33 100644
--- a/crates/ra_lsp_server/src/main_loop/mod.rs
+++ b/crates/ra_lsp_server/src/main_loop/mod.rs
@@ -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)) => {