From 2df7292ecff04838fb4c7e5da3a534d566a6dd74 Mon Sep 17 00:00:00 2001 From: Said Aroua Date: Thu, 10 Jul 2025 14:40:48 +0200 Subject: [PATCH] Add test for label deduplication --- crates/typst-ide/src/complete.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/crates/typst-ide/src/complete.rs b/crates/typst-ide/src/complete.rs index bc5b3e10e..0a560eb53 100644 --- a/crates/typst-ide/src/complete.rs +++ b/crates/typst-ide/src/complete.rs @@ -76,7 +76,7 @@ pub struct Completion { } /// A kind of item that can be completed. -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "kebab-case")] pub enum CompletionKind { /// A syntactical structure. @@ -1564,7 +1564,7 @@ mod tests { use typst::layout::PagedDocument; - use super::{autocomplete, Completion}; + use super::{autocomplete, Completion, CompletionKind}; use crate::tests::{FilePos, TestWorld, WorldLike}; /// Quote a string. @@ -1709,6 +1709,21 @@ mod tests { .must_exclude(["bib"]); } + #[test] + fn test_autocomplete_ref_identical_labels_returns_single_completion() { + let mut world = TestWorld::new("x y"); + let doc = typst::compile(&world).output.ok(); + + let end = world.main.text().len(); + world.main.edit(end..end, " @t"); + + let result = test_with_doc(&world, -1, doc.as_ref()); + let completions = result.completions(); + let label_count = + completions.iter().filter(|c| c.kind == CompletionKind::Label).count(); + assert_eq!(label_count, 1); + } + /// Test what kind of brackets we autocomplete for function calls depending /// on the function and existing parens. #[test]