mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-08-03 17:58:17 +00:00
feat: provide both bracket and paren completion (#867)
* feat: provide both bracket and paren completion * test: update snapshot
This commit is contained in:
parent
9885c45fb2
commit
6f4b916598
17 changed files with 95 additions and 53 deletions
|
@ -1,2 +1,2 @@
|
|||
/// contains: box
|
||||
/// contains: box, box[]
|
||||
#b/* range 0..1 */
|
|
@ -1,2 +1,2 @@
|
|||
/// contains: bold
|
||||
/// contains: bold, bold[]
|
||||
$ b/* range 0..1 */ $
|
|
@ -14,6 +14,26 @@ input_file: crates/tinymist-query/src/fixtures/completion/bracket_strong.typ
|
|||
"labelDetails": {
|
||||
"description": "(content, delta: int) => strong"
|
||||
},
|
||||
"textEdit": {
|
||||
"newText": "strong(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 26,
|
||||
"line": 2
|
||||
},
|
||||
"start": {
|
||||
"character": 24,
|
||||
"line": 2
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "strong[]",
|
||||
"labelDetails": {
|
||||
"description": "(content, delta: int) => strong"
|
||||
},
|
||||
"textEdit": {
|
||||
"newText": "strong[${1:}]",
|
||||
"range": {
|
||||
|
|
|
@ -77,7 +77,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/func_args.typ
|
|||
"labelDetails": {
|
||||
"description": "type"
|
||||
},
|
||||
"sortText": "031",
|
||||
"sortText": "034",
|
||||
"textEdit": {
|
||||
"newText": "content",
|
||||
"range": {
|
||||
|
|
|
@ -35,7 +35,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/func_builtin_args.typ
|
|||
"labelDetails": {
|
||||
"description": "(int, content, gutter: relative) => columns"
|
||||
},
|
||||
"sortText": "037",
|
||||
"sortText": "040",
|
||||
"textEdit": {
|
||||
"newText": "columns(${1:})",
|
||||
"range": {
|
||||
|
|
|
@ -77,7 +77,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/func_with_args.typ
|
|||
"labelDetails": {
|
||||
"description": "type"
|
||||
},
|
||||
"sortText": "031",
|
||||
"sortText": "034",
|
||||
"textEdit": {
|
||||
"newText": "content",
|
||||
"range": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: Completion on / (20..21)
|
||||
description: Completion on / (27..28)
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion/math_bold.typ
|
||||
---
|
||||
|
@ -14,6 +14,26 @@ input_file: crates/tinymist-query/src/fixtures/completion/math_bold.typ
|
|||
"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
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"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": {
|
||||
|
|
|
@ -14,7 +14,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show_transform.typ
|
|||
"labelDetails": {
|
||||
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
|
||||
},
|
||||
"sortText": "154",
|
||||
"sortText": "173",
|
||||
"textEdit": {
|
||||
"newText": "raw(${1:})",
|
||||
"range": {
|
||||
|
@ -35,7 +35,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show_transform.typ
|
|||
"labelDetails": {
|
||||
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
|
||||
},
|
||||
"sortText": "155",
|
||||
"sortText": "174",
|
||||
"textEdit": {
|
||||
"newText": "raw.with(${1:})",
|
||||
"range": {
|
||||
|
@ -56,7 +56,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show_transform.typ
|
|||
"labelDetails": {
|
||||
"description": "([any], encoding: \"utf8\" | none) => bytes | str"
|
||||
},
|
||||
"sortText": "156",
|
||||
"sortText": "175",
|
||||
"textEdit": {
|
||||
"newText": "read(${1:})",
|
||||
"range": {
|
||||
|
@ -77,7 +77,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show_transform.typ
|
|||
"labelDetails": {
|
||||
"description": "([any], encoding: \"utf8\" | none) => bytes | str"
|
||||
},
|
||||
"sortText": "157",
|
||||
"sortText": "176",
|
||||
"textEdit": {
|
||||
"newText": "read.with(${1:})",
|
||||
"range": {
|
||||
|
@ -95,7 +95,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show_transform.typ
|
|||
{
|
||||
"kind": 15,
|
||||
"label": "replacement",
|
||||
"sortText": "166",
|
||||
"sortText": "187",
|
||||
"textEdit": {
|
||||
"newText": "[${1:content}]",
|
||||
"range": {
|
||||
|
|
|
@ -14,7 +14,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show_transform2.typ
|
|||
"labelDetails": {
|
||||
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
|
||||
},
|
||||
"sortText": "154",
|
||||
"sortText": "173",
|
||||
"textEdit": {
|
||||
"newText": "raw(${1:})",
|
||||
"range": {
|
||||
|
@ -35,7 +35,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show_transform2.typ
|
|||
"labelDetails": {
|
||||
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
|
||||
},
|
||||
"sortText": "155",
|
||||
"sortText": "174",
|
||||
"textEdit": {
|
||||
"newText": "raw.with(${1:})",
|
||||
"range": {
|
||||
|
@ -56,7 +56,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show_transform2.typ
|
|||
"labelDetails": {
|
||||
"description": "([any], encoding: \"utf8\" | none) => bytes | str"
|
||||
},
|
||||
"sortText": "156",
|
||||
"sortText": "175",
|
||||
"textEdit": {
|
||||
"newText": "read(${1:})",
|
||||
"range": {
|
||||
|
@ -77,7 +77,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show_transform2.typ
|
|||
"labelDetails": {
|
||||
"description": "([any], encoding: \"utf8\" | none) => bytes | str"
|
||||
},
|
||||
"sortText": "157",
|
||||
"sortText": "176",
|
||||
"textEdit": {
|
||||
"newText": "read.with(${1:})",
|
||||
"range": {
|
||||
|
@ -95,7 +95,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show_transform2.typ
|
|||
{
|
||||
"kind": 15,
|
||||
"label": "replacement",
|
||||
"sortText": "166",
|
||||
"sortText": "187",
|
||||
"textEdit": {
|
||||
"newText": "[${1:content}]",
|
||||
"range": {
|
||||
|
|
|
@ -14,7 +14,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show_transform3.typ
|
|||
"labelDetails": {
|
||||
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
|
||||
},
|
||||
"sortText": "154",
|
||||
"sortText": "173",
|
||||
"textEdit": {
|
||||
"newText": "raw(${1:})",
|
||||
"range": {
|
||||
|
@ -35,7 +35,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show_transform3.typ
|
|||
"labelDetails": {
|
||||
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
|
||||
},
|
||||
"sortText": "155",
|
||||
"sortText": "174",
|
||||
"textEdit": {
|
||||
"newText": "raw.with(${1:})",
|
||||
"range": {
|
||||
|
@ -56,7 +56,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show_transform3.typ
|
|||
"labelDetails": {
|
||||
"description": "([any], encoding: \"utf8\" | none) => bytes | str"
|
||||
},
|
||||
"sortText": "156",
|
||||
"sortText": "175",
|
||||
"textEdit": {
|
||||
"newText": "read(${1:})",
|
||||
"range": {
|
||||
|
@ -77,7 +77,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show_transform3.typ
|
|||
"labelDetails": {
|
||||
"description": "([any], encoding: \"utf8\" | none) => bytes | str"
|
||||
},
|
||||
"sortText": "157",
|
||||
"sortText": "176",
|
||||
"textEdit": {
|
||||
"newText": "read.with(${1:})",
|
||||
"range": {
|
||||
|
@ -95,7 +95,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show_transform3.typ
|
|||
{
|
||||
"kind": 15,
|
||||
"label": "replacement",
|
||||
"sortText": "166",
|
||||
"sortText": "187",
|
||||
"textEdit": {
|
||||
"newText": "[${1:content}]",
|
||||
"range": {
|
||||
|
|
|
@ -14,7 +14,7 @@ input_file: crates/tinymist-query/src/fixtures/pkgs/touying-core-slides.typ
|
|||
"labelDetails": {
|
||||
"description": "() => any"
|
||||
},
|
||||
"sortText": "029",
|
||||
"sortText": "032",
|
||||
"textEdit": {
|
||||
"newText": "config-xxx()${1:}",
|
||||
"range": {
|
||||
|
|
|
@ -56,9 +56,9 @@ input_file: crates/tinymist-query/src/fixtures/pkgs/touying-core-slides.typ
|
|||
"labelDetails": {
|
||||
"description": "(content, gap: length, justify: bool) => repeat"
|
||||
},
|
||||
"sortText": "139",
|
||||
"sortText": "159",
|
||||
"textEdit": {
|
||||
"newText": "repeat[${1:}]",
|
||||
"newText": "repeat(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 7,
|
||||
|
|
|
@ -35,7 +35,7 @@ input_file: crates/tinymist-query/src/fixtures/pkgs/touying-utils-cover-with-rec
|
|||
"labelDetails": {
|
||||
"description": "type"
|
||||
},
|
||||
"sortText": "161",
|
||||
"sortText": "186",
|
||||
"textEdit": {
|
||||
"newText": "stroke(${1:})",
|
||||
"range": {
|
||||
|
|
|
@ -32,7 +32,7 @@ input_file: crates/tinymist-query/src/fixtures/pkgs/touying-utils-current-headin
|
|||
"labelDetails": {
|
||||
"description": "type"
|
||||
},
|
||||
"sortText": "079",
|
||||
"sortText": "089",
|
||||
"textEdit": {
|
||||
"newText": "int(${1:})",
|
||||
"range": {
|
||||
|
|
|
@ -68,7 +68,7 @@ input_file: crates/tinymist-query/src/fixtures/pkgs/touying-utils-markup-text.ty
|
|||
"labelDetails": {
|
||||
"description": "type"
|
||||
},
|
||||
"sortText": "156",
|
||||
"sortText": "180",
|
||||
"textEdit": {
|
||||
"newText": "str(${1:})",
|
||||
"range": {
|
||||
|
|
|
@ -523,16 +523,18 @@ impl<'a> CompletionContext<'a> {
|
|||
surrounding_syntax,
|
||||
SurroundingSyntax::Selector | SurroundingSyntax::SetRule
|
||||
);
|
||||
let apply = if !scope_reject_content && accept_content_arg {
|
||||
eco_format!("{name}[${{}}]")
|
||||
} else {
|
||||
eco_format!("{name}(${{}})")
|
||||
};
|
||||
self.completions.push(Completion {
|
||||
apply: Some(apply),
|
||||
label: name,
|
||||
..base
|
||||
apply: Some(eco_format!("{name}(${{}})")),
|
||||
label: name.clone(),
|
||||
..base.clone()
|
||||
});
|
||||
if !scope_reject_content && accept_content_arg {
|
||||
self.completions.push(Completion {
|
||||
apply: Some(eco_format!("{name}[${{}}]")),
|
||||
label: eco_format!("{name}[]"),
|
||||
..base
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
continue;
|
||||
|
@ -1378,21 +1380,6 @@ pub(crate) fn complete_type(ctx: &mut CompletionContext) -> Option<()> {
|
|||
ctx.enrich(" ", "");
|
||||
}
|
||||
|
||||
if let Some(c) = args_node {
|
||||
log::debug!("content block compl: args {c:?}");
|
||||
let is_unclosed = matches!(c.kind(), SyntaxKind::Args)
|
||||
&& c.children().fold(0i32, |acc, node| match node.kind() {
|
||||
SyntaxKind::LeftParen => acc + 1,
|
||||
SyntaxKind::RightParen => acc - 1,
|
||||
SyntaxKind::Error if node.text() == "(" => acc + 1,
|
||||
SyntaxKind::Error if node.text() == ")" => acc - 1,
|
||||
_ => acc,
|
||||
}) > 0;
|
||||
if is_unclosed {
|
||||
ctx.enrich("", ")");
|
||||
}
|
||||
}
|
||||
|
||||
let mut completions = std::mem::take(&mut ctx.completions);
|
||||
let explict = ctx.explicit;
|
||||
ctx.explicit = true;
|
||||
|
@ -1487,7 +1474,20 @@ pub(crate) fn complete_type(ctx: &mut CompletionContext) -> Option<()> {
|
|||
|
||||
ctx.completions.append(&mut completions);
|
||||
|
||||
log::debug!("sort_and_explicit_code_completion: {:?}", ctx.completions);
|
||||
if let Some(c) = args_node {
|
||||
log::debug!("content block compl: args {c:?}");
|
||||
let is_unclosed = matches!(c.kind(), SyntaxKind::Args)
|
||||
&& c.children().fold(0i32, |acc, node| match node.kind() {
|
||||
SyntaxKind::LeftParen => acc + 1,
|
||||
SyntaxKind::RightParen => acc - 1,
|
||||
SyntaxKind::Error if node.text() == "(" => acc + 1,
|
||||
SyntaxKind::Error if node.text() == ")" => acc - 1,
|
||||
_ => acc,
|
||||
}) > 0;
|
||||
if is_unclosed {
|
||||
ctx.enrich("", ")");
|
||||
}
|
||||
}
|
||||
|
||||
match scope {
|
||||
SurroundingSyntax::Regular => {}
|
||||
|
@ -1498,6 +1498,8 @@ pub(crate) fn complete_type(ctx: &mut CompletionContext) -> Option<()> {
|
|||
SurroundingSyntax::SetRule => {}
|
||||
}
|
||||
|
||||
log::debug!("sort_and_explicit_code_completion: {:?}", ctx.completions);
|
||||
|
||||
Some(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue