From f8a2b533045757c42c206b2596448baf4737f1f0 Mon Sep 17 00:00:00 2001 From: "Jeremy A. Kolb" Date: Tue, 9 Oct 2018 10:08:17 -0400 Subject: 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 --- crates/ra_lsp_server/src/main_loop/handlers.rs | 36 ++++++++++++++++++++++++++ crates/ra_lsp_server/src/main_loop/mod.rs | 1 + 2 files changed, 37 insertions(+) (limited to 'crates/ra_lsp_server/src/main_loop') 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( Ok(res) } +pub fn handle_signature_help( + world: ServerWorld, + params: req::TextDocumentPositionParams, + token: JobToken, +) -> Result> { + use languageserver_types::{ParameterInformation, SignatureInformation}; + + let file_id = params.text_document.try_conv_with(&world)?; + let line_index = world.analysis().file_line_index(file_id); + let offset = params.position.conv_with(&line_index); + + if let Some((descriptor, active_param)) = world.analysis().resolve_callable(file_id, offset, &token) { + let parameters : Vec = + descriptor.params.iter().map(|param| + ParameterInformation { + label: param.clone(), + documentation: None + } + ).collect(); + + let sig_info = SignatureInformation { + label: descriptor.label, + documentation: None, + parameters: Some(parameters) + }; + + Ok(Some(req::SignatureHelp { + signatures: vec![sig_info], + active_signature: Some(0), + active_parameter: active_param.map(|a| a as u64) + })) + } else { + Ok(None) + } +} + pub fn handle_code_action( world: ServerWorld, 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( .on::(handlers::handle_completion)? .on::(handlers::handle_code_action)? .on::(handlers::handle_folding_range)? + .on::(handlers::handle_signature_help)? .finish(); match req { Ok((id, handle)) => { -- cgit v1.2.3