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/caps.rs | 5 +++- crates/ra_lsp_server/src/main_loop/handlers.rs | 36 ++++++++++++++++++++++++++ crates/ra_lsp_server/src/main_loop/mod.rs | 1 + crates/ra_lsp_server/src/req.rs | 1 + 4 files changed, 42 insertions(+), 1 deletion(-) (limited to 'crates/ra_lsp_server') diff --git a/crates/ra_lsp_server/src/caps.rs b/crates/ra_lsp_server/src/caps.rs index 3c628f29c..5598ec75f 100644 --- a/crates/ra_lsp_server/src/caps.rs +++ b/crates/ra_lsp_server/src/caps.rs @@ -7,6 +7,7 @@ use languageserver_types::{ TextDocumentSyncKind, ExecuteCommandOptions, CompletionOptions, + SignatureHelpOptions, DocumentOnTypeFormattingOptions, }; @@ -26,7 +27,9 @@ pub fn server_capabilities() -> ServerCapabilities { resolve_provider: None, trigger_characters: None, }), - signature_help_provider: None, + signature_help_provider: Some(SignatureHelpOptions { + trigger_characters: Some(vec!["(".to_string(), ",".to_string()]) + }), definition_provider: Some(true), type_definition_provider: None, implementation_provider: None, 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)) => { diff --git a/crates/ra_lsp_server/src/req.rs b/crates/ra_lsp_server/src/req.rs index f80957589..1630edf7f 100644 --- a/crates/ra_lsp_server/src/req.rs +++ b/crates/ra_lsp_server/src/req.rs @@ -14,6 +14,7 @@ pub use languageserver_types::{ CompletionParams, CompletionResponse, DocumentOnTypeFormattingParams, TextDocumentEdit, + SignatureHelp, Hover }; pub enum SyntaxTree {} -- cgit v1.2.3