fix: complete hash expression in math mode (#1071)

* fix: complete hash expression in math mode

* fix: `interpret_mode_at_kind` on hash
This commit is contained in:
Myriad-Dreamin 2024-12-26 16:19:46 +08:00 committed by GitHub
parent 98a0e60b20
commit 1dcb034b91
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 64 additions and 10 deletions

View file

@ -8,6 +8,27 @@ snapshot_kind: text
[
{
"isIncomplete": false,
"items": []
"items": [
{
"kind": 3,
"label": "pagebreak",
"labelDetails": {
"description": "(to: \"even\" | \"odd\" | none, weak: bool) => pagebreak"
},
"textEdit": {
"newText": "pagebreak()${1:}",
"range": {
"end": {
"character": 3,
"line": 2
},
"start": {
"character": 3,
"line": 2
}
}
}
}
]
}
]

View file

@ -8,6 +8,27 @@ snapshot_kind: text
[
{
"isIncomplete": false,
"items": []
"items": [
{
"kind": 3,
"label": "pagebreak",
"labelDetails": {
"description": "(to: \"even\" | \"odd\" | none, weak: bool) => pagebreak"
},
"textEdit": {
"newText": "pagebreak()${1:}",
"range": {
"end": {
"character": 5,
"line": 2
},
"start": {
"character": 3,
"line": 2
}
}
}
}
]
}
]

View file

@ -277,6 +277,14 @@ pub fn interpret_mode_at(mut leaf: Option<&LinkedNode>) -> InterpretMode {
break mode;
}
if !t.kind().is_trivia() && {
// Previous leaf is hash
t.prev_leaf()
.map_or(false, |n| n.kind() == SyntaxKind::Hash)
} {
return InterpretMode::Code;
}
leaf = t.parent();
} else {
break InterpretMode::Markup;
@ -294,8 +302,9 @@ pub(crate) fn interpret_mode_at_kind(kind: SyntaxKind) -> Option<InterpretMode>
CodeBlock | Code => InterpretMode::Code,
ContentBlock | Markup => InterpretMode::Markup,
Equation | Math => InterpretMode::Math,
Hash => InterpretMode::Code,
Label | Text | Ident | FieldAccess | Bool | Int | Float | Numeric | Space | Linebreak
| Parbreak | Escape | Shorthand | SmartQuote | RawLang | RawDelim | RawTrimmed | Hash
| Parbreak | Escape | Shorthand | SmartQuote | RawLang | RawDelim | RawTrimmed
| LeftBrace | RightBrace | LeftBracket | RightBracket | LeftParen | RightParen | Comma
| Semicolon | Colon | Star | Underscore | Dollar | Plus | Minus | Slash | Hat | Prime
| Dot | Eq | EqEq | ExclEq | Lt | LtEq | Gt | GtEq | PlusEq | HyphEq | StarEq | SlashEq

View file

@ -273,6 +273,14 @@ fn complete_math(ctx: &mut CompletionContext) -> bool {
if ctx.leaf.kind() == SyntaxKind::Hash {
ctx.from = ctx.cursor;
code_completions(ctx, true);
return true;
}
// Start of an interpolated identifier: "#pa|".
if ctx.leaf.kind() == SyntaxKind::Ident {
ctx.from = ctx.leaf.offset();
code_completions(ctx, true);
return true;
}

View file

@ -106,13 +106,8 @@ impl CompletionContext<'_> {
docs: Default::default(),
};
let in_math = matches!(
self.leaf.parent_kind(),
Some(SyntaxKind::Equation)
| Some(SyntaxKind::Math)
| Some(SyntaxKind::MathFrac)
| Some(SyntaxKind::MathAttach)
);
let mode = interpret_mode_at(Some(&self.leaf));
let in_math = matches!(mode, InterpretMode::Math);
let lib = self.world().library();
let scope = if in_math { &lib.math } else { &lib.global }