mirror of
https://github.com/typst/typst
synced 2025-07-11 14:42:53 +08:00
Fix regression in reference autocomplete (#6586)
This commit is contained in:
parent
70710deb2b
commit
0264534928
@ -130,7 +130,14 @@ fn complete_markup(ctx: &mut CompletionContext) -> bool {
|
|||||||
return true;
|
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 {
|
if ctx.leaf.kind() == SyntaxKind::RefMarker {
|
||||||
ctx.from = ctx.leaf.offset() + 1;
|
ctx.from = ctx.leaf.offset() + 1;
|
||||||
ctx.label_completions();
|
ctx.label_completions();
|
||||||
@ -1644,6 +1651,19 @@ mod tests {
|
|||||||
test_with_doc(world, pos, doc.as_ref())
|
test_with_doc(world, pos, doc.as_ref())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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]
|
#[track_caller]
|
||||||
fn test_with_doc(
|
fn test_with_doc(
|
||||||
world: impl WorldLike,
|
world: impl WorldLike,
|
||||||
@ -1709,15 +1729,24 @@ mod tests {
|
|||||||
.must_exclude(["bib"]);
|
.must_exclude(["bib"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_autocomplete_ref_function() {
|
||||||
|
test_with_addition("x<test>", " #ref(<)", -2).must_include(["test"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_autocomplete_ref_shorthand() {
|
||||||
|
test_with_addition("x<test>", " @", -1).must_include(["test"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_autocomplete_ref_shorthand_with_partial_identifier() {
|
||||||
|
test_with_addition("x<test>", " @te", -1).must_include(["test"]);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_autocomplete_ref_identical_labels_returns_single_completion() {
|
fn test_autocomplete_ref_identical_labels_returns_single_completion() {
|
||||||
let mut world = TestWorld::new("x<test> y<test>");
|
let result = test_with_addition("x<test> y<test>", " @t", -1);
|
||||||
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 completions = result.completions();
|
||||||
let label_count =
|
let label_count =
|
||||||
completions.iter().filter(|c| c.kind == CompletionKind::Label).count();
|
completions.iter().filter(|c| c.kind == CompletionKind::Label).count();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user