summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaid A. <47973576+Daaiid@users.noreply.github.com>2025-07-10 17:02:23 +0200
committerGitHub <noreply@github.com>2025-07-10 15:02:23 +0000
commit0264534928864c7aed0466d670824ac0ce5ca1a8 (patch)
tree53725428fc8aed9f6144348d9980b22ec58f85f8
parent70710deb2b813eacc79d57436f5bd4c15c215f2e (diff)
Fix regression in reference autocomplete (#6586)HEADmain
-rw-r--r--crates/typst-ide/src/complete.rs43
1 files changed, 36 insertions, 7 deletions
diff --git a/crates/typst-ide/src/complete.rs b/crates/typst-ide/src/complete.rs
index 0a560eb5..5b6d6fd9 100644
--- a/crates/typst-ide/src/complete.rs
+++ b/crates/typst-ide/src/complete.rs
@@ -130,7 +130,14 @@ fn complete_markup(ctx: &mut CompletionContext) -> bool {
return true;
}
- // Start of a reference: "@|" or "@he|".
+ // Start of a reference: "@|".
+ if ctx.leaf.kind() == SyntaxKind::Text && ctx.before.ends_with("@") {
+ ctx.from = ctx.cursor;
+ ctx.label_completions();
+ return true;
+ }
+
+ // An existing reference: "@he|".
if ctx.leaf.kind() == SyntaxKind::RefMarker {
ctx.from = ctx.leaf.offset() + 1;
ctx.label_completions();
@@ -1645,6 +1652,19 @@ mod tests {
}
#[track_caller]
+ fn test_with_addition(
+ initial_text: &str,
+ addition: &str,
+ pos: impl FilePos,
+ ) -> Response {
+ let mut world = TestWorld::new(initial_text);
+ let doc = typst::compile(&world).output.ok();
+ let end = world.main.text().len();
+ world.main.edit(end..end, addition);
+ test_with_doc(&world, pos, doc.as_ref())
+ }
+
+ #[track_caller]
fn test_with_doc(
world: impl WorldLike,
pos: impl FilePos,
@@ -1710,14 +1730,23 @@ mod tests {
}
#[test]
- fn test_autocomplete_ref_identical_labels_returns_single_completion() {
- let mut world = TestWorld::new("x<test> y<test>");
- let doc = typst::compile(&world).output.ok();
+ fn test_autocomplete_ref_function() {
+ test_with_addition("x<test>", " #ref(<)", -2).must_include(["test"]);
+ }
- let end = world.main.text().len();
- world.main.edit(end..end, " @t");
+ #[test]
+ fn test_autocomplete_ref_shorthand() {
+ test_with_addition("x<test>", " @", -1).must_include(["test"]);
+ }
- let result = test_with_doc(&world, -1, doc.as_ref());
+ #[test]
+ fn test_autocomplete_ref_shorthand_with_partial_identifier() {
+ test_with_addition("x<test>", " @te", -1).must_include(["test"]);
+ }
+
+ #[test]
+ fn test_autocomplete_ref_identical_labels_returns_single_completion() {
+ let result = test_with_addition("x<test> y<test>", " @t", -1);
let completions = result.completions();
let label_count =
completions.iter().filter(|c| c.kind == CompletionKind::Label).count();