mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-07-24 13:13:43 +00:00
dev: don't complete bracket in math context (#860)
This commit is contained in:
parent
698d86f9b0
commit
6c342eb23e
8 changed files with 83 additions and 13 deletions
|
@ -0,0 +1,2 @@
|
|||
/// contains: box
|
||||
#b/* range 0..1 */
|
|
@ -0,0 +1,2 @@
|
|||
/// contains: bold
|
||||
$ b/* range 0..1 */ $
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
|
@ -265,18 +265,16 @@ pub(crate) fn interpret_mode_at_kind(k: SyntaxKind) -> Option<InterpretMode> {
|
|||
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
|
||||
|
|
|
@ -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}(${{}})")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue