feat: complete both open and closed labels (#302)

* feat: complete both open and closed labels

* QAQ
This commit is contained in:
Myriad-Dreamin 2024-05-18 12:36:42 +08:00 committed by GitHub
parent 071d9072e1
commit 8f5725f51a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 7 deletions

View file

@ -40,10 +40,10 @@ pub fn autocomplete(
mut ctx: CompletionContext,
) -> Option<(usize, bool, Vec<Completion>, Vec<lsp_types::CompletionItem>)> {
let _ = complete_comments(&mut ctx)
|| complete_labels(&mut ctx)
|| complete_type(&mut ctx).is_none() && {
log::info!("continue after completing type");
complete_field_accesses(&mut ctx)
|| complete_open_labels(&mut ctx)
|| complete_imports(&mut ctx)
|| complete_rules(&mut ctx)
|| complete_params(&mut ctx)
@ -480,10 +480,12 @@ fn field_access_completions(ctx: &mut CompletionContext, value: &Value, styles:
}
}
/// Complete half-finished labels.
fn complete_open_labels(ctx: &mut CompletionContext) -> bool {
/// Complete labels.
fn complete_labels(ctx: &mut CompletionContext) -> bool {
// A label anywhere in code: "(<la|".
if ctx.leaf.kind().is_error() && ctx.leaf.text().starts_with('<') {
if (ctx.leaf.kind().is_error() && ctx.leaf.text().starts_with('<'))
|| ctx.leaf.kind() == SyntaxKind::Label
{
ctx.from = ctx.leaf.offset() + 1;
ctx.label_completions();
return true;

View file

@ -368,11 +368,12 @@ impl Init {
definition_provider: Some(OneOf::Left(true)),
references_provider: Some(OneOf::Left(true)),
completion_provider: Some(CompletionOptions {
// Please update the language-configurations.json if you are changing this
// Please update the language-configuration.json if you are changing this
// setting.
trigger_characters: Some(vec![
String::from("#"),
String::from("("),
String::from("<"),
String::from(","),
String::from("."),
String::from(":"),

View file

@ -374,7 +374,7 @@ fn e2e() {
});
let hash = replay_log(&tinymist_binary, &root.join("neovim"));
insta::assert_snapshot!(hash, @"siphash128_13:6169526fa530f5a2d7907ffd23d67466");
insta::assert_snapshot!(hash, @"siphash128_13:d2a8dcc163ddbb5e204818aeb4c21b66");
}
{
@ -385,7 +385,7 @@ fn e2e() {
});
let hash = replay_log(&tinymist_binary, &root.join("vscode"));
insta::assert_snapshot!(hash, @"siphash128_13:48f876724231ca7cdbadce094856da60");
insta::assert_snapshot!(hash, @"siphash128_13:32c954951f57dc40af56d3557fb15e5e");
}
}