feat: add typst support

This commit is contained in:
2026-07-10 18:57:28 +02:00
parent 4732c9002f
commit baa098454b
8 changed files with 188 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
local util = require("util")
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(ev)
local client = vim.lsp.get_client_by_id(ev.data.client_id)
if not client or client.name ~= "tinymist" then
return
end
vim.keymap.set("n", "<leader>lf", function()
vim.lsp.buf.format()
util.format({
buf = ev.buf,
cmd = { "typstyle", "--wrap-text" },
output = "stdout",
})
end, { buffer = ev.buf })
end,
})
---@type vim.lsp.Config
return {}
+1
View File
@@ -100,6 +100,7 @@ require("ts").setup({
{ lang = "tsx", location = "tsx" },
},
},
"https://github.com/uben0/tree-sitter-typst",
{
src = "https://github.com/tree-sitter-grammars/tree-sitter-xml",
parsers = {
+1
View File
@@ -94,6 +94,7 @@ function M.setup()
-- "pyright",
"ruff",
"rust_analyzer",
"tinymist",
"zls",
})
+4
View File
@@ -166,6 +166,10 @@
"rev": "75b3874edb2dc714fb1fd77a32013d0f8699989f",
"src": "https://github.com/tree-sitter/tree-sitter-typescript"
},
"tree-sitter-typst": {
"rev": "46cf4ded12ee974a70bf8457263b67ad7ee0379d",
"src": "https://github.com/uben0/tree-sitter-typst"
},
"tree-sitter-xml": {
"rev": "5000ae8f22d11fbe93939b05c1e37cf21117162d",
"src": "https://github.com/tree-sitter-grammars/tree-sitter-xml"
+2
View File
@@ -24,6 +24,8 @@ require("mason-auto-install").setup({
"ruff",
"pyrefly",
"rust-analyzer",
"tinymist",
"typstyle",
"zls",
},
})
+11
View File
@@ -0,0 +1,11 @@
[
(set)
(let)
(show)
(call)
(section)
(for)
(branch)
(content)
(raw_blck)
] @fold
+141
View File
@@ -0,0 +1,141 @@
; punctuation
"#" @punctuation.special
[
":"
";"
","
] @punctuation.delimiter
; TODO: context blocks for "[" "]"?
[
"("
")"
"{"
"}"
"["
"]"
] @punctuation.bracket
; operators
[
"-"
"+"
"*"
"/"
"=="
"!="
"<"
"<="
">"
">="
"="
"in"
"and"
"or"
"not"
] @operator
; keywords
[
"import"
"include"
] @keyword.import
[
"let"
"set"
"show"
] @keyword
; control flow
[
"for"
"while"
"break"
"continue"
] @keyword.repeat
[
"if"
"else"
] @keyword.conditional
; special case: #for (ident) in (expr)
(for
"in" @keyword.repeat)
; type literals
(number) @number
(string) @string
(bool) @boolean
(ident) @constant
; name-value pairs
(tagged
field: (ident) @variable.member)
(call
item: (ident) @function.call)
; text
(text) @spell
(heading
"=" @markup.heading.1) @markup.heading.1
(heading
"==" @markup.heading.2) @markup.heading.2
(heading
"===" @markup.heading.3) @markup.heading.3
(heading
"====" @markup.heading.4) @markup.heading.4
(heading
"=====" @markup.heading.5) @markup.heading.5
(heading
"======" @markup.heading.6) @markup.heading.6
(strong) @markup.strong
(emph) @markup.italic
((url) @markup.link.url
(#set! @markup.link.url url @markup.link.url))
(call
item: (ident) @_link
(#eq? @_link "link")
(group
.
(string) @markup.link.url
(#offset! @markup.link.url 0 1 0 -1)
(#set! @markup.link.url url @markup.link.url)))
; code blocks
(raw_span) @markup.raw
(raw_blck) @markup.raw
(raw_blck
lang: (ident) @label)
(raw_blck
(blob) @markup.raw.block)
; refs and labels
(label) @markup.link.label
(ref) @markup.link
; math
(math) @markup.math
; comments
(comment) @comment @spell
+6
View File
@@ -0,0 +1,6 @@
((comment) @injection.content
(#set! injection.language "comment"))
(raw_blck
(ident) @injection.language
(blob) @injection.content)