on master help sign in
Add typst language and lsp (#7474)

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>

commit290666011971c79e36b5172eea66b315dc52e2c9 authorAlexander Brevig <alexanderbrevig@gmail.com> dateFri 27 Oct 2023, 01:27 (3 years ago) parentef1f4f3
4 files changed+106
book/src/generated/lang-support.md+1 languages.toml+22 runtime/queries/typst/highlights.scm+77 runtime/queries/typst/injections.scm+6
book/src/generated/lang-support.md+1
@@ -163,6 +163,7 @@
163163| tsx | ✓ | ✓ | ✓ | `typescript-language-server` |
164164| twig | ✓ | | | |
165165| typescript | ✓ | ✓ | ✓ | `typescript-language-server` |
166+| typst | ✓ | | | `typst-lsp` |
166167| ungrammar | ✓ | | | |
167168| unison | ✓ | | | |
168169| uxntal | ✓ | | | |
languages.toml+22
@@ -88,6 +88,7 @@ wgsl_analyzer = { command = "wgsl_analyzer" }
8888yaml-language-server = { command = "yaml-language-server", args = ["--stdio"] }
8989zls = { command = "zls" }
9090blueprint-compiler = { command = "blueprint-compiler", args = ["lsp"] }
91+typst-lsp = { command = "typst-lsp" }
9192
9293[language-server.ansible-language-server]
9394command = "ansible-language-server"
@@ -2912,6 +2913,27 @@ roots = []
29122913indent = { tab-width = 2, unit = " " }
29132914grammar = "html"
29142915
2916+[[language]]
2917+name = "typst"
2918+scope = "source.typst"
2919+injection-regex = "typst"
2920+file-types = ["typst", "typ"]
2921+roots = []
2922+comment-token = "//"
2923+language-servers = ["typst-lsp"]
2924+indent = { tab-width = 2, unit = " " }
2925+
2926+[language.auto-pairs]
2927+'(' = ')'
2928+'{' = '}'
2929+'[' = ']'
2930+'$' = '$'
2931+'"' = '"'
2932+
2933+[[grammar]]
2934+name = "typst"
2935+source = { git = "https://github.com/uben0/tree-sitter-typst", rev = "e35aa22395fdde82bbc4b5700c324ce346dfc9e5" }
2936+
29152937[[language]]
29162938name = "nunjucks"
29172939scope = "text.html.nunjucks"
runtime/queries/typst/highlights.scmnew file+77
@@ -0,0 +1,77 @@
1+(call
2+ item: (ident) @function)
3+(call
4+ item: (field field: (ident) @function.method))
5+(tagged field: (ident) @tag)
6+(field field: (ident) @tag)
7+(comment) @comment
8+
9+; CONTROL
10+(let "let" @keyword.storage.type)
11+(branch ["if" "else"] @keyword.control.conditional)
12+(while "while" @keyword.control.repeat)
13+(for ["for" "in"] @keyword.control.repeat)
14+(import "import" @keyword.control.import)
15+(as "as" @keyword.operator)
16+(include "include" @keyword.control.import)
17+(show "show" @keyword.control)
18+(set "set" @keyword.control)
19+(return "return" @keyword.control)
20+(flow ["break" "continue"] @keyword.control)
21+
22+; OPERATOR
23+(in ["in" "not"] @keyword.operator)
24+(and "and" @keyword.operator)
25+(or "or" @keyword.operator)
26+(not "not" @keyword.operator)
27+(sign ["+" "-"] @operator)
28+(add "+" @operator)
29+(sub "-" @operator)
30+(mul "*" @operator)
31+(div "/" @operator)
32+(cmp ["==" "<=" ">=" "!=" "<" ">"] @operator)
33+(fraction "/" @operator)
34+(fac "!" @operator)
35+(attach ["^" "_"] @operator)
36+(wildcard) @operator
37+
38+; VALUE
39+(raw_blck "```" @operator) @markup.raw.block
40+(raw_span "`" @operator) @markup.raw.block
41+(raw_blck lang: (ident) @tag)
42+(label) @tag
43+(ref) @tag
44+(number) @constant.numeric
45+(string) @string
46+(content ["[" "]"] @operator)
47+(bool) @constant.builtin.boolean
48+(builtin) @constant.builtin
49+(none) @constant.builtin
50+(auto) @constant.builtin
51+(ident) @variable
52+(call
53+ item: (builtin) @function.builtin)
54+
55+; MARKUP
56+(item "-" @markup.list)
57+(term ["/" ":"] @markup.list)
58+(heading ["=" "==" "===" "====" "====="] @markup.heading.marker) @markup.heading
59+(url) @tag
60+(emph) @markup.italic
61+(strong) @markup.bold
62+(symbol) @constant.character
63+(shorthand) @constant.builtin
64+(quote) @markup.quote
65+(align) @operator
66+(letter) @constant.character
67+(linebreak) @constant.builtin
68+
69+(math "$" @operator)
70+"#" @operator
71+"end" @operator
72+
73+(escape) @constant.character.escape
74+["(" ")" "{" "}"] @punctuation.bracket
75+["," ";" ".." ":" "sep"] @punctuation.delimiter
76+"assign" @punctuation
77+(field "." @punctuation)
runtime/queries/typst/injections.scmnew file+6
@@ -0,0 +1,6 @@
1+(raw_blck
2+ (blob) @injection.shebang @injection.content)
3+
4+(raw_blck
5+ lang: (ident) @injection.language
6+ (blob) @injection.content)