Trigger parameter info automatically

See https://github.com/Microsoft/vscode/issues/64023
This commit is contained in:
Aleksey Kladov 2020-03-06 17:56:51 +01:00
parent 4e7f6c2354
commit 3ff170d658
3 changed files with 26 additions and 0 deletions

View file

@ -47,6 +47,10 @@ pub struct CompletionItem {
/// Whether this item is marked as deprecated
deprecated: bool,
/// If completing a function call, ask the editor to show parameter popup
/// after completion.
trigger_call_info: bool,
}
// We use custom debug for CompletionItem to make `insta`'s diffs more readable.
@ -139,6 +143,7 @@ impl CompletionItem {
kind: None,
text_edit: None,
deprecated: None,
trigger_call_info: None,
}
}
/// What user sees in pop-up in the UI.
@ -177,6 +182,10 @@ impl CompletionItem {
pub fn deprecated(&self) -> bool {
self.deprecated
}
pub fn trigger_call_info(&self) -> bool {
self.trigger_call_info
}
}
/// A helper to make `CompletionItem`s.
@ -193,6 +202,7 @@ pub(crate) struct Builder {
kind: Option<CompletionItemKind>,
text_edit: Option<TextEdit>,
deprecated: Option<bool>,
trigger_call_info: Option<bool>,
}
impl Builder {
@ -221,6 +231,7 @@ impl Builder {
kind: self.kind,
completion_kind: self.completion_kind,
deprecated: self.deprecated.unwrap_or(false),
trigger_call_info: self.trigger_call_info.unwrap_or(false),
}
}
pub(crate) fn lookup_by(mut self, lookup: impl Into<String>) -> Builder {
@ -271,6 +282,10 @@ impl Builder {
self.deprecated = Some(deprecated);
self
}
pub(crate) fn trigger_call_info(mut self) -> Builder {
self.trigger_call_info = Some(true);
self
}
}
impl<'a> Into<CompletionItem> for Builder {

View file

@ -221,6 +221,7 @@ impl Completions {
let (snippet, label) = if params.is_empty() || has_self_param && params.len() == 1 {
(format!("{}()$0", name), format!("{}()", name))
} else {
builder = builder.trigger_call_info();
let snippet = if ctx
.db
.feature_flags

View file

@ -150,6 +150,16 @@ impl ConvWith<(&LineIndex, LineEndings)> for CompletionItem {
additional_text_edits: Some(additional_text_edits),
documentation: self.documentation().map(|it| it.conv()),
deprecated: Some(self.deprecated()),
command: if self.trigger_call_info() {
let cmd = lsp_types::Command {
title: "triggerParameterHints".into(),
command: "editor.action.triggerParameterHints".into(),
arguments: None,
};
Some(cmd)
} else {
None
},
..Default::default()
};