feat: trigger parameter hints instead of suggest on pos args (#243)

* dev: disable aggressive positional arguments completion

* feat: trigger parameter hints instead of suggest on pos args

* dev: update snapshot
This commit is contained in:
Myriad-Dreamin 2024-05-05 23:40:29 +08:00 committed by GitHub
parent 64c8be64d3
commit d8c3a97f24
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 17 additions and 16 deletions

View file

@ -1029,7 +1029,9 @@ impl<'a, 'w> CompletionContext<'a, 'w> {
// command on a suggestion to "manually" retrigger suggest after inserting one // command on a suggestion to "manually" retrigger suggest after inserting one
// //
// todo: only vscode and neovim (0.9.1) support this // todo: only vscode and neovim (0.9.1) support this
command: Some("editor.action.triggerSuggest"), command: snippet
.contains("${")
.then_some("editor.action.triggerSuggest"),
..Completion::default() ..Completion::default()
}); });
} }
@ -1181,7 +1183,7 @@ impl<'a, 'w> CompletionContext<'a, 'w> {
let mut command = None; let mut command = None;
if parens && matches!(value, Value::Func(_)) { if parens && matches!(value, Value::Func(_)) {
if let Value::Func(func) = value { if let Value::Func(func) = value {
command = Some("editor.action.triggerSuggest"); command = Some("editor.action.triggerParameterHints");
if func if func
.params() .params()
.is_some_and(|params| params.iter().all(|param| param.name == "self")) .is_some_and(|params| params.iter().all(|param| param.name == "self"))

View file

@ -313,7 +313,7 @@ impl<'a, 'w> CompletionContext<'a, 'w> {
kind: kind.clone(), kind: kind.clone(),
label_detail: ty_detail, label_detail: ty_detail,
// todo: only vscode and neovim (0.9.1) support this // todo: only vscode and neovim (0.9.1) support this
command: Some("editor.action.triggerSuggest"), command: Some("editor.action.triggerParameterHints"),
..Default::default() ..Default::default()
}; };
@ -641,13 +641,7 @@ pub fn param_completions<'a>(
apply: Some(eco_format!("{}: ${{}}", param.name)), apply: Some(eco_format!("{}: ${{}}", param.name)),
detail: Some(plain_docs_sentence(&param.docs)), detail: Some(plain_docs_sentence(&param.docs)),
label_detail: None, label_detail: None,
// todo: only vscode and neovim (0.9.1) support this command: Some("tinymist.triggerNamedCompletion"),
//
// VS Code doesn't do that... Auto triggering suggestion only happens on typing
// (word starts or trigger characters). However, you can use
// editor.action.triggerSuggest as command on a suggestion to
// "manually" retrigger suggest after inserting one
command: Some("editor.action.triggerSuggest"),
..Completion::default() ..Completion::default()
}; };
match param.infer_type { match param.infer_type {
@ -742,8 +736,7 @@ fn type_completion(
label: f.clone(), label: f.clone(),
apply: Some(eco_format!("{}: ${{}}", f)), apply: Some(eco_format!("{}: ${{}}", f)),
detail: docs.map(Into::into), detail: docs.map(Into::into),
// todo: only vscode and neovim (0.9.1) support this command: Some("tinymist.triggerNamedCompletion"),
command: Some("editor.action.triggerSuggest"),
..Completion::default() ..Completion::default()
}); });
} }

View file

@ -434,9 +434,7 @@ impl Init {
// setting. // setting.
trigger_characters: Some(vec![ trigger_characters: Some(vec![
String::from("#"), String::from("#"),
String::from("("),
String::from("."), String::from("."),
String::from(","),
String::from(":"), String::from(":"),
String::from("/"), String::from("/"),
String::from("\""), String::from("\""),

View file

@ -157,6 +157,9 @@ async function startClient(context: ExtensionContext): Promise<void> {
commands.registerCommand("tinymist.showSummary", () => commandShowSummary(context)), commands.registerCommand("tinymist.showSummary", () => commandShowSummary(context)),
commands.registerCommand("tinymist.showSymbolView", () => commandShowSymbolView(context)), commands.registerCommand("tinymist.showSymbolView", () => commandShowSymbolView(context)),
commands.registerCommand("tinymist.profileCurrentFile", () => commandShowTrace(context)), commands.registerCommand("tinymist.profileCurrentFile", () => commandShowTrace(context)),
// We would like to define it at the server side, but it is not possible for now.
// https://github.com/microsoft/language-server-protocol/issues/1117
commands.registerCommand("tinymist.triggerNamedCompletion", triggerNamedCompletion),
commands.registerCommand("tinymist.showLog", () => { commands.registerCommand("tinymist.showLog", () => {
if (client) { if (client) {
client.outputChannel.show(); client.outputChannel.show();
@ -668,6 +671,11 @@ function determineVscodeTheme(): any {
} }
} }
function triggerNamedCompletion() {
vscode.commands.executeCommand("editor.action.triggerSuggest");
vscode.commands.executeCommand("editor.action.triggerParameterHints");
}
// "tinymist.hoverPeriscope": { // "tinymist.hoverPeriscope": {
// "title": "Show preview document in periscope mode on hovering", // "title": "Show preview document in periscope mode on hovering",
// "description": "In VSCode, enable compile status meaning that the extension will show the compilation status in the status bar. Since neovim and helix don't have a such feature, it is disabled by default at the language server lebel.", // "description": "In VSCode, enable compile status meaning that the extension will show the compilation status in the status bar. Since neovim and helix don't have a such feature, it is disabled by default at the language server lebel.",

View file

@ -374,7 +374,7 @@ fn e2e() {
}); });
let hash = replay_log(&tinymist_binary, &root.join("neovim")); let hash = replay_log(&tinymist_binary, &root.join("neovim"));
insta::assert_snapshot!(hash, @"siphash128_13:8a283a742935063715fbc8af6bff2b88"); insta::assert_snapshot!(hash, @"siphash128_13:69e46cf64247dc4715e1bd46b33906df");
} }
{ {
@ -385,7 +385,7 @@ fn e2e() {
}); });
let hash = replay_log(&tinymist_binary, &root.join("vscode")); let hash = replay_log(&tinymist_binary, &root.join("vscode"));
insta::assert_snapshot!(hash, @"siphash128_13:ab459e29e562f52a4594eb784b592341"); insta::assert_snapshot!(hash, @"siphash128_13:f6fc76ff19ea6754c8e8a47cc721c929");
} }
} }