Concise mode for parameter hints

This works around VS Code bug where it tries to cram everything in a
tiny popup, and brings experience closer to Intellij.
This commit is contained in:
Aleksey Kladov 2020-03-06 18:32:40 +01:00
parent 3ff170d658
commit 95a2755aa8
4 changed files with 27 additions and 15 deletions

View file

@ -56,6 +56,7 @@ impl Default for FeatureFlags {
("completion.insertion.add-call-parenthesis", true), ("completion.insertion.add-call-parenthesis", true),
("completion.insertion.add-argument-sippets", true), ("completion.insertion.add-argument-sippets", true),
("completion.enable-postfix", true), ("completion.enable-postfix", true),
("call-info.full", true),
("notifications.workspace-loaded", true), ("notifications.workspace-loaded", true),
("notifications.cargo-toml-not-found", true), ("notifications.cargo-toml-not-found", true),
]) ])

View file

@ -3,10 +3,10 @@
use lsp_types::{ use lsp_types::{
self, CreateFile, DiagnosticSeverity, DocumentChangeOperation, DocumentChanges, Documentation, self, CreateFile, DiagnosticSeverity, DocumentChangeOperation, DocumentChanges, Documentation,
Location, LocationLink, MarkupContent, MarkupKind, Position, Range, RenameFile, ResourceOp, Location, LocationLink, MarkupContent, MarkupKind, ParameterInformation, ParameterLabel,
SemanticTokenModifier, SemanticTokenType, SymbolKind, TextDocumentEdit, TextDocumentIdentifier, Position, Range, RenameFile, ResourceOp, SemanticTokenModifier, SemanticTokenType,
TextDocumentItem, TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier, SignatureInformation, SymbolKind, TextDocumentEdit, TextDocumentIdentifier, TextDocumentItem,
WorkspaceEdit, TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier, WorkspaceEdit,
}; };
use ra_ide::{ use ra_ide::{
translate_offset_with_edit, CompletionItem, CompletionItemKind, FileId, FilePosition, translate_offset_with_edit, CompletionItem, CompletionItemKind, FileId, FilePosition,
@ -220,17 +220,20 @@ impl Conv for ra_ide::Documentation {
} }
} }
impl Conv for ra_ide::FunctionSignature { impl ConvWith<bool> for ra_ide::FunctionSignature {
type Output = lsp_types::SignatureInformation; type Output = lsp_types::SignatureInformation;
fn conv(self) -> Self::Output { fn conv_with(self, concise: bool) -> Self::Output {
use lsp_types::{ParameterInformation, ParameterLabel, SignatureInformation}; let (label, documentation, params) = if concise {
let mut params = self.parameters;
if self.has_self_param {
params.remove(0);
}
(params.join(", "), None, params)
} else {
(self.to_string(), self.doc.map(|it| it.conv()), self.parameters)
};
let label = self.to_string(); let parameters: Vec<ParameterInformation> = params
let documentation = self.doc.map(|it| it.conv());
let parameters: Vec<ParameterInformation> = self
.parameters
.into_iter() .into_iter()
.map(|param| ParameterInformation { .map(|param| ParameterInformation {
label: ParameterLabel::Simple(param), label: ParameterLabel::Simple(param),

View file

@ -459,8 +459,12 @@ pub fn handle_signature_help(
let _p = profile("handle_signature_help"); let _p = profile("handle_signature_help");
let position = params.try_conv_with(&world)?; let position = params.try_conv_with(&world)?;
if let Some(call_info) = world.analysis().call_info(position)? { if let Some(call_info) = world.analysis().call_info(position)? {
let active_parameter = call_info.active_parameter.map(|it| it as i64); let concise = !world.analysis().feature_flags().get("call-info.full");
let sig_info = call_info.signature.conv(); let mut active_parameter = call_info.active_parameter.map(|it| it as i64);
if concise && call_info.signature.has_self_param {
active_parameter = active_parameter.map(|it| it.saturating_sub(1));
}
let sig_info = call_info.signature.conv_with(concise);
Ok(Some(req::SignatureHelp { Ok(Some(req::SignatureHelp {
signatures: vec![sig_info], signatures: vec![sig_info],

View file

@ -205,6 +205,10 @@
"type": "boolean", "type": "boolean",
"description": "Whether to show postfix snippets like `dbg`, `if`, `not`, etc." "description": "Whether to show postfix snippets like `dbg`, `if`, `not`, etc."
}, },
"call-info.full": {
"type": "boolean",
"description": "Show function name and docs in parameter hints"
},
"notifications.workspace-loaded": { "notifications.workspace-loaded": {
"type": "boolean", "type": "boolean",
"description": "Whether to show `workspace loaded` message" "description": "Whether to show `workspace loaded` message"