fix: deduplicate value completion correctly (#604)

This commit is contained in:
Myriad-Dreamin 2024-09-20 13:14:07 +08:00 committed by GitHub
parent 6ce6bb8018
commit fcde0efb22
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 94 additions and 3 deletions

View file

@ -0,0 +1,10 @@
// contains:a,ab,ac,ad
#let x = (
a: false,
ab: false,
ac: false,
ad: true,
)
#x.a /* range -1..0 */

View file

@ -0,0 +1,81 @@
---
source: crates/tinymist-query/src/completion.rs
description: Completion on (92..93)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/fp_dict_filter.typ
---
[
{
"isIncomplete": false,
"items": [
{
"kind": 21,
"label": "a",
"textEdit": {
"newText": "a",
"range": {
"end": {
"character": 4,
"line": 9
},
"start": {
"character": 3,
"line": 9
}
}
}
},
{
"kind": 21,
"label": "ab",
"textEdit": {
"newText": "ab",
"range": {
"end": {
"character": 4,
"line": 9
},
"start": {
"character": 3,
"line": 9
}
}
}
},
{
"kind": 21,
"label": "ac",
"textEdit": {
"newText": "ac",
"range": {
"end": {
"character": 4,
"line": 9
},
"start": {
"character": 3,
"line": 9
}
}
}
},
{
"kind": 21,
"label": "ad",
"textEdit": {
"newText": "ad",
"range": {
"end": {
"character": 4,
"line": 9
},
"start": {
"character": 3,
"line": 9
}
}
}
}
]
}
]

View file

@ -10,7 +10,7 @@ use typst::model::Document;
use typst::syntax::ast::AstNode;
use typst::syntax::{ast, is_id_continue, is_id_start, is_ident, LinkedNode, Source, SyntaxKind};
use typst::text::RawElem;
use typst_shim::syntax::LinkedNodeExt;
use typst_shim::{syntax::LinkedNodeExt, utils::hash128};
use unscanny::Scanner;
use super::{plain_docs_sentence, summarize_font_family};
@ -1138,7 +1138,7 @@ impl<'a, 'w> CompletionContext<'a, 'w> {
bib_title,
} in labels.into_iter().skip(skip).take(take)
{
if !self.seen_casts.insert(typst_shim::utils::hash128(&label)) {
if !self.seen_casts.insert(hash128(&label)) {
continue;
}
let label: EcoString = label.as_str().into();
@ -1204,7 +1204,7 @@ impl<'a, 'w> CompletionContext<'a, 'w> {
docs: Option<&str>,
) {
// Prevent duplicate completions from appearing.
if !self.seen_casts.insert(typst_shim::utils::hash128(value)) {
if !self.seen_casts.insert(hash128(&(&label, &value))) {
return;
}