diff --git a/crates/tinymist-query/src/fixtures/completion/math_bold.typ b/crates/tinymist-query/src/fixtures/completion/math_bold.typ new file mode 100644 index 00000000..9888dd3d --- /dev/null +++ b/crates/tinymist-query/src/fixtures/completion/math_bold.typ @@ -0,0 +1,2 @@ +/// contains: box +#b/* range 0..1 */ \ No newline at end of file diff --git a/crates/tinymist-query/src/fixtures/completion/math_bold2.typ b/crates/tinymist-query/src/fixtures/completion/math_bold2.typ new file mode 100644 index 00000000..fbe126dc --- /dev/null +++ b/crates/tinymist-query/src/fixtures/completion/math_bold2.typ @@ -0,0 +1,2 @@ +/// contains: bold +$ b/* range 0..1 */ $ \ No newline at end of file diff --git a/crates/tinymist-query/src/fixtures/completion/snaps/test@colon_markup.typ.snap b/crates/tinymist-query/src/fixtures/completion/snaps/test@colon_markup.typ.snap index 1d3aa2d5..5f5d6ae6 100644 --- a/crates/tinymist-query/src/fixtures/completion/snaps/test@colon_markup.typ.snap +++ b/crates/tinymist-query/src/fixtures/completion/snaps/test@colon_markup.typ.snap @@ -15,7 +15,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/colon_markup.typ "description": "(content, b: content | none, bl: content | none, br: content | none, t: content | none, tl: content | none, tr: content | none) => attach" }, "textEdit": { - "newText": "attach[${1:}]", + "newText": "attach(${1:})", "range": { "end": { "character": 2, diff --git a/crates/tinymist-query/src/fixtures/completion/snaps/test@colon_math.typ.snap b/crates/tinymist-query/src/fixtures/completion/snaps/test@colon_math.typ.snap index 3e06bb30..81af18bf 100644 --- a/crates/tinymist-query/src/fixtures/completion/snaps/test@colon_math.typ.snap +++ b/crates/tinymist-query/src/fixtures/completion/snaps/test@colon_math.typ.snap @@ -15,7 +15,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/colon_math.typ "description": "(content, b: content | none, bl: content | none, br: content | none, t: content | none, tl: content | none, tr: content | none) => attach" }, "textEdit": { - "newText": "attach[${1:}]", + "newText": "attach(${1:})", "range": { "end": { "character": 2, diff --git a/crates/tinymist-query/src/fixtures/completion/snaps/test@math_bold.typ.snap b/crates/tinymist-query/src/fixtures/completion/snaps/test@math_bold.typ.snap new file mode 100644 index 00000000..338f0c91 --- /dev/null +++ b/crates/tinymist-query/src/fixtures/completion/snaps/test@math_bold.typ.snap @@ -0,0 +1,33 @@ +--- +source: crates/tinymist-query/src/completion.rs +description: Completion on / (20..21) +expression: "JsonRepr::new_pure(results)" +input_file: crates/tinymist-query/src/fixtures/completion/math_bold.typ +--- +[ + { + "isIncomplete": false, + "items": [ + { + "kind": 3, + "label": "box", + "labelDetails": { + "description": "(content | none, baseline: relative, clip: bool, fill: color, height: auto | relative, inset: inset, outset: outset, radius: radius, stroke: stroke, width: auto | fraction | relative) => box" + }, + "textEdit": { + "newText": "box[${1:}]", + "range": { + "end": { + "character": 2, + "line": 1 + }, + "start": { + "character": 1, + "line": 1 + } + } + } + } + ] + } +] diff --git a/crates/tinymist-query/src/fixtures/completion/snaps/test@math_bold2.typ.snap b/crates/tinymist-query/src/fixtures/completion/snaps/test@math_bold2.typ.snap new file mode 100644 index 00000000..10d8eee4 --- /dev/null +++ b/crates/tinymist-query/src/fixtures/completion/snaps/test@math_bold2.typ.snap @@ -0,0 +1,33 @@ +--- +source: crates/tinymist-query/src/completion.rs +description: Completion on / (22..23) +expression: "JsonRepr::new_pure(results)" +input_file: crates/tinymist-query/src/fixtures/completion/math_bold2.typ +--- +[ + { + "isIncomplete": false, + "items": [ + { + "kind": 3, + "label": "bold", + "labelDetails": { + "description": "(content) => content" + }, + "textEdit": { + "newText": "bold(${1:})", + "range": { + "end": { + "character": 3, + "line": 1 + }, + "start": { + "character": 2, + "line": 1 + } + } + } + } + ] + } +] diff --git a/crates/tinymist-query/src/syntax/matcher.rs b/crates/tinymist-query/src/syntax/matcher.rs index 43421ea7..2ef031a4 100644 --- a/crates/tinymist-query/src/syntax/matcher.rs +++ b/crates/tinymist-query/src/syntax/matcher.rs @@ -265,18 +265,16 @@ pub(crate) fn interpret_mode_at_kind(k: SyntaxKind) -> Option { CodeBlock | Code => InterpretMode::Code, ContentBlock | Markup => InterpretMode::Markup, Equation | Math => InterpretMode::Math, - Ident | FieldAccess | Bool | Int | Float | Numeric | Space | Linebreak | Parbreak - | Escape | Shorthand | SmartQuote | RawLang | RawDelim | RawTrimmed | Hash | 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 | Dots - | Arrow | Root | Not | And | Or | None | Auto | As | Named | Keyed | Error | End => { + Label | Text | Ident | FieldAccess | Bool | Int | Float | Numeric | Space | Linebreak + | Parbreak | Escape | Shorthand | SmartQuote | RawLang | RawDelim | RawTrimmed | Hash + | 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 + | Dots | Arrow | Root | Not | And | Or | None | Auto | As | Named | Keyed | Error | End => { return Option::None } - Text | Strong | Emph | Link | Label | Ref | RefMarker | Heading | HeadingMarker - | ListItem | ListMarker | EnumItem | EnumMarker | TermItem | TermMarker => { - InterpretMode::Markup - } + Strong | Emph | Link | Ref | RefMarker | Heading | HeadingMarker | ListItem + | ListMarker | EnumItem | EnumMarker | TermItem | TermMarker => InterpretMode::Markup, MathIdent | MathAlignPoint | MathDelimited | MathAttach | MathPrimes | MathFrac | MathRoot | MathShorthand => InterpretMode::Math, Let | Set | Show | Context | If | Else | For | In | While | Break | Continue | Return diff --git a/crates/tinymist-query/src/upstream/complete/ext.rs b/crates/tinymist-query/src/upstream/complete/ext.rs index fc79c040..e931ce64 100644 --- a/crates/tinymist-query/src/upstream/complete/ext.rs +++ b/crates/tinymist-query/src/upstream/complete/ext.rs @@ -414,6 +414,7 @@ impl<'a> CompletionContext<'a> { let defines = defines.defines; let surrounding_syntax = self.surrounding_syntax(); + let mode = interpret_mode_at(Some(&self.leaf)); let mut kind_checker = CompletionKindChecker { symbols: HashSet::default(), @@ -525,7 +526,8 @@ impl<'a> CompletionContext<'a> { ..base }); } else { - let apply = if fn_feat.next_arg_is_content && !fn_feat.has_rest { + let accept_content_arg = fn_feat.next_arg_is_content && !fn_feat.has_rest; + let apply = if !matches!(mode, InterpretMode::Math) && accept_content_arg { eco_format!("{name}[${{}}]") } else { eco_format!("{name}(${{}})")