mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-10 15:14:32 +00:00
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:
parent
3ff170d658
commit
95a2755aa8
4 changed files with 27 additions and 15 deletions
|
@ -56,6 +56,7 @@ impl Default for FeatureFlags {
|
|||
("completion.insertion.add-call-parenthesis", true),
|
||||
("completion.insertion.add-argument-sippets", true),
|
||||
("completion.enable-postfix", true),
|
||||
("call-info.full", true),
|
||||
("notifications.workspace-loaded", true),
|
||||
("notifications.cargo-toml-not-found", true),
|
||||
])
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
|
||||
use lsp_types::{
|
||||
self, CreateFile, DiagnosticSeverity, DocumentChangeOperation, DocumentChanges, Documentation,
|
||||
Location, LocationLink, MarkupContent, MarkupKind, Position, Range, RenameFile, ResourceOp,
|
||||
SemanticTokenModifier, SemanticTokenType, SymbolKind, TextDocumentEdit, TextDocumentIdentifier,
|
||||
TextDocumentItem, TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier,
|
||||
WorkspaceEdit,
|
||||
Location, LocationLink, MarkupContent, MarkupKind, ParameterInformation, ParameterLabel,
|
||||
Position, Range, RenameFile, ResourceOp, SemanticTokenModifier, SemanticTokenType,
|
||||
SignatureInformation, SymbolKind, TextDocumentEdit, TextDocumentIdentifier, TextDocumentItem,
|
||||
TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier, WorkspaceEdit,
|
||||
};
|
||||
use ra_ide::{
|
||||
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;
|
||||
fn conv(self) -> Self::Output {
|
||||
use lsp_types::{ParameterInformation, ParameterLabel, SignatureInformation};
|
||||
fn conv_with(self, concise: bool) -> Self::Output {
|
||||
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 documentation = self.doc.map(|it| it.conv());
|
||||
|
||||
let parameters: Vec<ParameterInformation> = self
|
||||
.parameters
|
||||
let parameters: Vec<ParameterInformation> = params
|
||||
.into_iter()
|
||||
.map(|param| ParameterInformation {
|
||||
label: ParameterLabel::Simple(param),
|
||||
|
|
|
@ -459,8 +459,12 @@ pub fn handle_signature_help(
|
|||
let _p = profile("handle_signature_help");
|
||||
let position = params.try_conv_with(&world)?;
|
||||
if let Some(call_info) = world.analysis().call_info(position)? {
|
||||
let active_parameter = call_info.active_parameter.map(|it| it as i64);
|
||||
let sig_info = call_info.signature.conv();
|
||||
let concise = !world.analysis().feature_flags().get("call-info.full");
|
||||
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 {
|
||||
signatures: vec![sig_info],
|
||||
|
|
|
@ -205,6 +205,10 @@
|
|||
"type": "boolean",
|
||||
"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": {
|
||||
"type": "boolean",
|
||||
"description": "Whether to show `workspace loaded` message"
|
||||
|
|
Loading…
Reference in a new issue