mirror of
https://github.com/typst/typst
synced 2025-06-15 16:46:24 +08:00
Autocomplete fixes for math mode (#6415)
This commit is contained in:
parent
832fab58b3
commit
df4c08f852
@ -298,13 +298,20 @@ fn complete_math(ctx: &mut CompletionContext) -> bool {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start of an interpolated identifier: "#|".
|
// Start of an interpolated identifier: "$#|$".
|
||||||
if ctx.leaf.kind() == SyntaxKind::Hash {
|
if ctx.leaf.kind() == SyntaxKind::Hash {
|
||||||
ctx.from = ctx.cursor;
|
ctx.from = ctx.cursor;
|
||||||
code_completions(ctx, true);
|
code_completions(ctx, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Behind existing interpolated identifier: "$#pa|$".
|
||||||
|
if ctx.leaf.kind() == SyntaxKind::Ident {
|
||||||
|
ctx.from = ctx.leaf.offset();
|
||||||
|
code_completions(ctx, true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Behind existing atom or identifier: "$a|$" or "$abc|$".
|
// Behind existing atom or identifier: "$a|$" or "$abc|$".
|
||||||
if matches!(
|
if matches!(
|
||||||
ctx.leaf.kind(),
|
ctx.leaf.kind(),
|
||||||
@ -1666,6 +1673,13 @@ mod tests {
|
|||||||
test("#{() .a}", -2).must_include(["at", "any", "all"]);
|
test("#{() .a}", -2).must_include(["at", "any", "all"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Test that autocomplete in math uses the correct global scope.
|
||||||
|
#[test]
|
||||||
|
fn test_autocomplete_math_scope() {
|
||||||
|
test("$#col$", -2).must_include(["colbreak"]).must_exclude(["colon"]);
|
||||||
|
test("$col$", -2).must_include(["colon"]).must_exclude(["colbreak"]);
|
||||||
|
}
|
||||||
|
|
||||||
/// Test that the `before_window` doesn't slice into invalid byte
|
/// Test that the `before_window` doesn't slice into invalid byte
|
||||||
/// boundaries.
|
/// boundaries.
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -114,7 +114,9 @@ pub fn globals<'a>(world: &'a dyn IdeWorld, leaf: &LinkedNode) -> &'a Scope {
|
|||||||
| Some(SyntaxKind::Math)
|
| Some(SyntaxKind::Math)
|
||||||
| Some(SyntaxKind::MathFrac)
|
| Some(SyntaxKind::MathFrac)
|
||||||
| Some(SyntaxKind::MathAttach)
|
| Some(SyntaxKind::MathAttach)
|
||||||
);
|
) && leaf
|
||||||
|
.prev_leaf()
|
||||||
|
.is_none_or(|prev| !matches!(prev.kind(), SyntaxKind::Hash));
|
||||||
|
|
||||||
let library = world.library();
|
let library = world.library();
|
||||||
if in_math {
|
if in_math {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user