Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typst language and lsp #7474

Merged
merged 14 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions book/src/generated/lang-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
| tsx | ✓ | ✓ | ✓ | `typescript-language-server` |
| twig | ✓ | | | |
| typescript | ✓ | ✓ | ✓ | `typescript-language-server` |
| typst | ✓ | | | `typst-lsp` |
| ungrammar | ✓ | | | |
| unison | ✓ | | | |
| uxntal | ✓ | | | |
Expand Down
22 changes: 22 additions & 0 deletions languages.toml
AlexanderBrevig marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ wgsl_analyzer = { command = "wgsl_analyzer" }
yaml-language-server = { command = "yaml-language-server", args = ["--stdio"] }
zls = { command = "zls" }
blueprint-compiler = { command = "blueprint-compiler", args = ["lsp"] }
typst-lsp = { command = "typst-lsp" }


[language-server.lua-language-server]
Expand Down Expand Up @@ -2735,6 +2736,27 @@ roots = []
indent = { tab-width = 2, unit = " " }
grammar = "html"

[[language]]
name = "typst"
scope = "source.typst"
injection-regex = "typst"
file-types = ["typst", "typ"]
roots = []
comment-token = "//"
language-servers = ["typst-lsp"]
indent = { tab-width = 2, unit = " " }

[language.auto-pairs]
'(' = ')'
'{' = '}'
'[' = ']'
'$' = '$'
'"' = '"'

[[grammar]]
name = "typst"
source = { git = "https://github.com/uben0/tree-sitter-typst", rev = "7a2bb249fc555dbcba7d440709927614b8802969" }

[[language]]
name = "nunjucks"
scope = "text.html.nunjucks"
Expand Down
79 changes: 79 additions & 0 deletions runtime/queries/typst/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
(call
item: (ident) @function)
(call
item: (field field: (ident) @function.method))
(tagged field: (ident) @tag)
(field field: (ident) @tag)
(comment) @comment

; CONTROL
(let "let" @keyword.storage.type)
(branch ["if" "else"] @keyword.control.conditional)
(while "while" @keyword.control.repeat)
(for ["for" "in"] @keyword.control.repeat)
(import "import" @keyword.control.import)
(as "as" @keyword.operator)
(include "include" @keyword.control.import)
(show "show" @keyword.control)
(set "set" @keyword.control)
(return "return" @keyword.control)
(flow ["break" "continue"] @keyword.control)

; OPERATOR
(in ["in" "not"] @keyword.operator)
(and "and" @keyword.operator)
(or "or" @keyword.operator)
(not "not" @keyword.operator)
(sign ["+" "-"] @operator)
(add "+" @operator)
(sub "-" @operator)
(mul "*" @operator)
(div "/" @operator)
(cmp ["==" "<=" ">=" "!=" "<" ">"] @operator)
(fraction "/" @operator)
(fac "!" @operator)
(attach ["^" "_"] @operator)
(wildcard) @operator

; VALUE
(raw_blck "```" @operator) @markup.raw.block
(raw_span "`" @operator) @markup.raw.block
(raw_blck lang: (ident) @tag)
(label) @tag
(ref) @tag
(number) @constant.numeric
(string) @string
(content ["[" "]"] @operator)
(bool) @constant.builtin.boolean
(builtin) @constant.builtin
(none) @constant.builtin
(auto) @constant.builtin
(ident) @variable
(call
item: (builtin) @function.builtin)

; MARKUP
(item "item" @operator)
AlexanderBrevig marked this conversation as resolved.
Show resolved Hide resolved
(term ["item" ":"] @operator)
(heading) @markup.heading
(url) @tag
(emph "_" @operator) @markup.italic
(strong "*" @operator) @markup.bold
(item) @markup.list
(term) @markup.list
(symbol) @constant.character
(shorthand) @constant.builtin
(quote) @markup.quote
(align) @operator
(letter) @constant.character
(linebreak) @constant.builtin

(math "$" @operator)
"#" @operator
"end" @operator

(escape) @constant.character.escape
["(" ")" "{" "}"] @ponctuation.bracket
["," ";" ".." ":" "sep"] @ponctuation.delimiter
"assign" @ponctuation
(field "." @ponctuation)
AlexanderBrevig marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 6 additions & 0 deletions runtime/queries/typst/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(raw_blck
(blob) @injection.shebang @injection.content)

(raw_blck
lang: (ident) @injection.language
(blob) @injection.content)
Loading