3.5 KiB
tinymist-query
analyzer library
Documentation
The documentation can be generated locally by running:
yarn docs:rs --open # You can also copy-run the command if you don't have a yarn.
Name Convention
The names of analyzers are all have suffix Worker
. To get a full list of analyzers, please search "struct: tinymist_query worker" in Cargo Docs.
tinymist_query::analysis::bib::BibWorker
tinymist_query::syntax::expr::ExprWorker
tinymist_query::syntax::index::IndexWorker
tinymist_query::analysis::link_expr::LinkStrWorker
tinymist_query::analysis::OnEnterWorker
tinymist_query::analysis::color_expr::ColorExprWorker
tinymist_query::analysis::InlayHintWorker
...
Testing analyzers
To run analyzer tests for tinymist:
cargo insta test -p tinymist-query --accept
Tip
Check Cargo Insta to learn and install the
insta
command.
To add a test, for example for the textDocument/completion
function, please follow the steps:
- Check the first argument of
snapshot_testing
function calls in the source file. We know that it uses fixtures fromfixtures/completion/
. - Add a typst file in the
fixtures/completion/
directory. - Rerun the
cargo insta
command to update snapshot.
At the step 2, we have special syntax to write the typst file.
-
Cursor range to request completion:
/* range -1..0 */
or/* range after 1..2 */
that relative to the comment node.Example:
$: /* range -1..0 */$
It test completion when the cursor is after a colon in the equation context.
-
Completion result filter:
/// contains: comma separated list
Example:
/// contains: body, fill #set text(/* range 0..1 */ )
Description: The snapshot result must contains
fill
and must not containsbody
, so we add both of them to thecontains
list. -
Fixture of some multiple-files project:
/// path: file name
Example:
/// path: base.typ #let table-prefix() = 1; ----- /// contains: base,table,table-prefix #import "base.typ": table/* range -1..1 */
Description: the files are separated by
-----
, and the first file is namedbase.typ
. The snapshot result must not containbase
,table
, and must containtable-prefix
, so we add them to thecontains
list. -
Whether to compile the file:
/// compile: true
Example:
/// compile: true #let test1(body) = figure(body) #test1([Test1]) <fig:test1> /* position after */ @fig:test1
Description: The file will be compiled before the test, to get the content reference by
typst::trace
for completion. -
Compile which the file:
/// compile: base.typ
Example:
/// compile: true /// path: base.typ #set heading(numbering: "1.1") = H <t> == H2 <test> aba aba ----- /// contains: test /// compile: base.typ #<t /* range -2..-1 */
Description: Another file named
base.typ
will be compiled before the test, since a half-editing file causes the completion to fail.
Analyzer playground
A special fixture folder playground
is provided for testing analyzers. You can change argument of the snapshot_testing
to "playground"
or ""
to use the playground fixtures.