From fb717ef4d553e714810f6435c8b45ce16576287c Mon Sep 17 00:00:00 2001 From: Myriad-Dreamin <35292584+Myriad-Dreamin@users.noreply.github.com> Date: Thu, 9 Jan 2025 21:42:45 +0800 Subject: [PATCH] test: add completion tests about nodes in math calls (#1139) --- .../tinymist-query/src/analysis/completion.rs | 2 + .../fixtures/completion/math_call_in_call.typ | 3 ++ .../completion/math_call_in_call2.typ | 3 ++ .../completion/math_call_in_call3.typ | 3 ++ .../completion/math_call_in_call4.typ | 3 ++ .../completion/math_ident_in_call.typ | 3 ++ .../completion/math_ident_in_call2.typ | 3 ++ .../snaps/test@math_call_in_call.typ.snap | 53 +++++++++++++++++++ .../snaps/test@math_call_in_call2.typ.snap | 35 ++++++++++++ .../snaps/test@math_call_in_call3.typ.snap | 35 ++++++++++++ .../snaps/test@math_call_in_call4.typ.snap | 35 ++++++++++++ .../snaps/test@math_ident_in_call.typ.snap | 35 ++++++++++++ .../snaps/test@math_ident_in_call2.typ.snap | 35 ++++++++++++ 13 files changed, 248 insertions(+) create mode 100644 crates/tinymist-query/src/fixtures/completion/math_call_in_call.typ create mode 100644 crates/tinymist-query/src/fixtures/completion/math_call_in_call2.typ create mode 100644 crates/tinymist-query/src/fixtures/completion/math_call_in_call3.typ create mode 100644 crates/tinymist-query/src/fixtures/completion/math_call_in_call4.typ create mode 100644 crates/tinymist-query/src/fixtures/completion/math_ident_in_call.typ create mode 100644 crates/tinymist-query/src/fixtures/completion/math_ident_in_call2.typ create mode 100644 crates/tinymist-query/src/fixtures/completion/snaps/test@math_call_in_call.typ.snap create mode 100644 crates/tinymist-query/src/fixtures/completion/snaps/test@math_call_in_call2.typ.snap create mode 100644 crates/tinymist-query/src/fixtures/completion/snaps/test@math_call_in_call3.typ.snap create mode 100644 crates/tinymist-query/src/fixtures/completion/snaps/test@math_call_in_call4.typ.snap create mode 100644 crates/tinymist-query/src/fixtures/completion/snaps/test@math_ident_in_call.typ.snap create mode 100644 crates/tinymist-query/src/fixtures/completion/snaps/test@math_ident_in_call2.typ.snap diff --git a/crates/tinymist-query/src/analysis/completion.rs b/crates/tinymist-query/src/analysis/completion.rs index 01bc88d5..1fc7f67c 100644 --- a/crates/tinymist-query/src/analysis/completion.rs +++ b/crates/tinymist-query/src/analysis/completion.rs @@ -173,7 +173,9 @@ impl<'a> CompletionCursor<'a> { let syntax_context = classify_context(leaf.clone(), Some(cursor)); let surrounding_syntax = surrounding_syntax(&leaf); + crate::log_debug_ct!("CompletionCursor: syntax {leaf:?} -> {syntax:#?}"); crate::log_debug_ct!("CompletionCursor: context {leaf:?} -> {syntax_context:#?}"); + crate::log_debug_ct!("CompletionCursor: surrounding {leaf:?} -> {surrounding_syntax:#?}"); Some(Self { ctx, text, diff --git a/crates/tinymist-query/src/fixtures/completion/math_call_in_call.typ b/crates/tinymist-query/src/fixtures/completion/math_call_in_call.typ new file mode 100644 index 00000000..ec285522 --- /dev/null +++ b/crates/tinymist-query/src/fixtures/completion/math_call_in_call.typ @@ -0,0 +1,3 @@ +/// contains: abs + +$ abs(abs/* range 0..1 */) $ diff --git a/crates/tinymist-query/src/fixtures/completion/math_call_in_call2.typ b/crates/tinymist-query/src/fixtures/completion/math_call_in_call2.typ new file mode 100644 index 00000000..2fb23898 --- /dev/null +++ b/crates/tinymist-query/src/fixtures/completion/math_call_in_call2.typ @@ -0,0 +1,3 @@ +/// contains: abs + +$ abs(ab/* range 0..1 */) $ diff --git a/crates/tinymist-query/src/fixtures/completion/math_call_in_call3.typ b/crates/tinymist-query/src/fixtures/completion/math_call_in_call3.typ new file mode 100644 index 00000000..577758d2 --- /dev/null +++ b/crates/tinymist-query/src/fixtures/completion/math_call_in_call3.typ @@ -0,0 +1,3 @@ +/// contains: abs + +$ abs(1 a/* range 0..1 */) $ diff --git a/crates/tinymist-query/src/fixtures/completion/math_call_in_call4.typ b/crates/tinymist-query/src/fixtures/completion/math_call_in_call4.typ new file mode 100644 index 00000000..94a8342d --- /dev/null +++ b/crates/tinymist-query/src/fixtures/completion/math_call_in_call4.typ @@ -0,0 +1,3 @@ +/// contains: abs + +$ abs(1 ab/* range 0..1 */) $ diff --git a/crates/tinymist-query/src/fixtures/completion/math_ident_in_call.typ b/crates/tinymist-query/src/fixtures/completion/math_ident_in_call.typ new file mode 100644 index 00000000..a7ebff3f --- /dev/null +++ b/crates/tinymist-query/src/fixtures/completion/math_ident_in_call.typ @@ -0,0 +1,3 @@ +/// contains: norm + +$ abs(n/* range 0..1 */) $ diff --git a/crates/tinymist-query/src/fixtures/completion/math_ident_in_call2.typ b/crates/tinymist-query/src/fixtures/completion/math_ident_in_call2.typ new file mode 100644 index 00000000..74659510 --- /dev/null +++ b/crates/tinymist-query/src/fixtures/completion/math_ident_in_call2.typ @@ -0,0 +1,3 @@ +/// contains: norm + +$ abs(no/* range 0..1 */) $ diff --git a/crates/tinymist-query/src/fixtures/completion/snaps/test@math_call_in_call.typ.snap b/crates/tinymist-query/src/fixtures/completion/snaps/test@math_call_in_call.typ.snap new file mode 100644 index 00000000..88e7de9d --- /dev/null +++ b/crates/tinymist-query/src/fixtures/completion/snaps/test@math_call_in_call.typ.snap @@ -0,0 +1,53 @@ +--- +source: crates/tinymist-query/src/completion.rs +description: Completion on / (28..29) +expression: "JsonRepr::new_pure(results)" +input_file: crates/tinymist-query/src/fixtures/completion/math_call_in_call.typ +snapshot_kind: text +--- +[ + { + "isIncomplete": false, + "items": [ + { + "kind": 3, + "label": "abs", + "sortText": "000", + "textEdit": { + "newText": "abs(${1:})", + "range": { + "end": { + "character": 9, + "line": 2 + }, + "start": { + "character": 6, + "line": 2 + } + } + } + }, + { + "kind": 3, + "label": "abs", + "labelDetails": { + "description": "(content, size: auto | relative) => content" + }, + "sortText": "058", + "textEdit": { + "newText": "abs(${1:})", + "range": { + "end": { + "character": 9, + "line": 2 + }, + "start": { + "character": 6, + "line": 2 + } + } + } + } + ] + } +] diff --git a/crates/tinymist-query/src/fixtures/completion/snaps/test@math_call_in_call2.typ.snap b/crates/tinymist-query/src/fixtures/completion/snaps/test@math_call_in_call2.typ.snap new file mode 100644 index 00000000..fce3a784 --- /dev/null +++ b/crates/tinymist-query/src/fixtures/completion/snaps/test@math_call_in_call2.typ.snap @@ -0,0 +1,35 @@ +--- +source: crates/tinymist-query/src/completion.rs +description: Completion on / (27..28) +expression: "JsonRepr::new_pure(results)" +input_file: crates/tinymist-query/src/fixtures/completion/math_call_in_call2.typ +snapshot_kind: text +--- +[ + { + "isIncomplete": false, + "items": [ + { + "kind": 3, + "label": "abs", + "labelDetails": { + "description": "(content, size: auto | relative) => content" + }, + "sortText": "057", + "textEdit": { + "newText": "abs(${1:})", + "range": { + "end": { + "character": 8, + "line": 2 + }, + "start": { + "character": 6, + "line": 2 + } + } + } + } + ] + } +] diff --git a/crates/tinymist-query/src/fixtures/completion/snaps/test@math_call_in_call3.typ.snap b/crates/tinymist-query/src/fixtures/completion/snaps/test@math_call_in_call3.typ.snap new file mode 100644 index 00000000..189ad2e0 --- /dev/null +++ b/crates/tinymist-query/src/fixtures/completion/snaps/test@math_call_in_call3.typ.snap @@ -0,0 +1,35 @@ +--- +source: crates/tinymist-query/src/completion.rs +description: Completion on / (28..29) +expression: "JsonRepr::new_pure(results)" +input_file: crates/tinymist-query/src/fixtures/completion/math_call_in_call3.typ +snapshot_kind: text +--- +[ + { + "isIncomplete": false, + "items": [ + { + "kind": 3, + "label": "abs", + "labelDetails": { + "description": "(content, size: auto | relative) => content" + }, + "sortText": "055", + "textEdit": { + "newText": "abs(${1:})", + "range": { + "end": { + "character": 9, + "line": 2 + }, + "start": { + "character": 8, + "line": 2 + } + } + } + } + ] + } +] diff --git a/crates/tinymist-query/src/fixtures/completion/snaps/test@math_call_in_call4.typ.snap b/crates/tinymist-query/src/fixtures/completion/snaps/test@math_call_in_call4.typ.snap new file mode 100644 index 00000000..e5edf1a3 --- /dev/null +++ b/crates/tinymist-query/src/fixtures/completion/snaps/test@math_call_in_call4.typ.snap @@ -0,0 +1,35 @@ +--- +source: crates/tinymist-query/src/completion.rs +description: Completion on / (29..30) +expression: "JsonRepr::new_pure(results)" +input_file: crates/tinymist-query/src/fixtures/completion/math_call_in_call4.typ +snapshot_kind: text +--- +[ + { + "isIncomplete": false, + "items": [ + { + "kind": 3, + "label": "abs", + "labelDetails": { + "description": "(content, size: auto | relative) => content" + }, + "sortText": "055", + "textEdit": { + "newText": "abs(${1:})", + "range": { + "end": { + "character": 10, + "line": 2 + }, + "start": { + "character": 8, + "line": 2 + } + } + } + } + ] + } +] diff --git a/crates/tinymist-query/src/fixtures/completion/snaps/test@math_ident_in_call.typ.snap b/crates/tinymist-query/src/fixtures/completion/snaps/test@math_ident_in_call.typ.snap new file mode 100644 index 00000000..b07ba8e0 --- /dev/null +++ b/crates/tinymist-query/src/fixtures/completion/snaps/test@math_ident_in_call.typ.snap @@ -0,0 +1,35 @@ +--- +source: crates/tinymist-query/src/completion.rs +description: Completion on / (27..28) +expression: "JsonRepr::new_pure(results)" +input_file: crates/tinymist-query/src/fixtures/completion/math_ident_in_call.typ +snapshot_kind: text +--- +[ + { + "isIncomplete": false, + "items": [ + { + "kind": 3, + "label": "norm", + "labelDetails": { + "description": "(content, size: auto | relative) => content" + }, + "sortText": "221", + "textEdit": { + "newText": "norm(${1:})", + "range": { + "end": { + "character": 7, + "line": 2 + }, + "start": { + "character": 6, + "line": 2 + } + } + } + } + ] + } +] diff --git a/crates/tinymist-query/src/fixtures/completion/snaps/test@math_ident_in_call2.typ.snap b/crates/tinymist-query/src/fixtures/completion/snaps/test@math_ident_in_call2.typ.snap new file mode 100644 index 00000000..5406c4ec --- /dev/null +++ b/crates/tinymist-query/src/fixtures/completion/snaps/test@math_ident_in_call2.typ.snap @@ -0,0 +1,35 @@ +--- +source: crates/tinymist-query/src/completion.rs +description: Completion on / (28..29) +expression: "JsonRepr::new_pure(results)" +input_file: crates/tinymist-query/src/fixtures/completion/math_ident_in_call2.typ +snapshot_kind: text +--- +[ + { + "isIncomplete": false, + "items": [ + { + "kind": 3, + "label": "norm", + "labelDetails": { + "description": "(content, size: auto | relative) => content" + }, + "sortText": "223", + "textEdit": { + "newText": "norm(${1:})", + "range": { + "end": { + "character": 8, + "line": 2 + }, + "start": { + "character": 6, + "line": 2 + } + } + } + } + ] + } +]