From 9d8089a6a7aff717e95168c26c8181a3185985ec Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Sun, 7 Jan 2024 00:57:45 -0600 Subject: [PATCH] feat(nvim): integrate typst --- .../nvim/after/queries/typst/highlights.scm | 79 +++++++++++++++++++ dots/.config/nvim/lua/plugins/configs/lsp.lua | 1 + .../nvim/lua/plugins/configs/treesitter.lua | 11 +++ .../nvim/lua/plugins/configs/typst.lua | 7 ++ 4 files changed, 98 insertions(+) create mode 100644 dots/.config/nvim/after/queries/typst/highlights.scm create mode 100644 dots/.config/nvim/lua/plugins/configs/typst.lua diff --git a/dots/.config/nvim/after/queries/typst/highlights.scm b/dots/.config/nvim/after/queries/typst/highlights.scm new file mode 100644 index 00000000..ffcbd105 --- /dev/null +++ b/dots/.config/nvim/after/queries/typst/highlights.scm @@ -0,0 +1,79 @@ +;; All scopes: comments +(comment) @comment @spell + +;; Code +;; punctuation +["#"] @punctuation.special +[":" ";" ","] @punctuation.delimiter +["(" ")" "{" "}"] @punctuation.bracket +;; TODO: context blocks? +[ "[" "]" ] @punctuation.bracket +;; operators +[ + "-" + "+" + "*" + "/" + + "==" + "!=" + "<" + "<=" + ">" + ">=" + + "=" + + "in" + "and" + "or" + "not" +] @operator +;; keywords +[ "import" "include" ] @include +[ "let" "set" "show" ] @keyword +;; control flow +[ "for" "while" "break" "continue" ] @repeat +[ "if" "else" ] @conditional +;; special case: #for (ident) in (expr) +(for "in" @repeat) +;; type literals +(number) @number +(string) @string +(bool) @boolean +;; identifiers +(builtin) @namespace +(ident) @identifier +;; name-value pairs +(tagged + field: (ident)) @field +;; function definitions, calls, etc. +;; TODO: support for functions such as #calc.cos, tree view appears as +;; (call) +;; item: (field) +;; (builtin) +; field: (ident) +(call + item: (builtin)) @function.builtin +(call + item: (ident)) @function.call + +;; Text +(heading) @text.title +(text) @text +(strong) @text.strong +(emph) @text.emph +(url) @text.uri +;; code blocks +(raw_span) @text.literal +(raw_span + (blob)) @text.literal +(raw_blck) @text.literal +(raw_blck + (blob)) @text.literal.block +;; refs and labels +(label) @text.reference +(ref) @text.reference + +;; Math +(math) @text.math diff --git a/dots/.config/nvim/lua/plugins/configs/lsp.lua b/dots/.config/nvim/lua/plugins/configs/lsp.lua index 6b6ca392..9a4894dd 100644 --- a/dots/.config/nvim/lua/plugins/configs/lsp.lua +++ b/dots/.config/nvim/lua/plugins/configs/lsp.lua @@ -429,6 +429,7 @@ return { "vimls", "marksman", "asm_lsp", + "typst_lsp" }) do lspconfig[server].setup(server_opts) end diff --git a/dots/.config/nvim/lua/plugins/configs/treesitter.lua b/dots/.config/nvim/lua/plugins/configs/treesitter.lua index eadafa69..27ff57a1 100644 --- a/dots/.config/nvim/lua/plugins/configs/treesitter.lua +++ b/dots/.config/nvim/lua/plugins/configs/treesitter.lua @@ -126,6 +126,17 @@ return { "RRethy/nvim-treesitter-endwise", }, config = function() + local parser_config = require('nvim-treesitter.parsers').get_parser_configs() + parser_config.typst = { + install_info = { + url = "https://github.com/uben0/tree-sitter-typst", + files = { "src/parser.c", "src/scanner.c" }, + branch = "master", + generate_requires_npm = true, + }, + maintainers = { "uben0" }, + experimental = true + } require("nvim-treesitter.configs").setup({ auto_install = true, ignore_install = { "comment" }, diff --git a/dots/.config/nvim/lua/plugins/configs/typst.lua b/dots/.config/nvim/lua/plugins/configs/typst.lua new file mode 100644 index 00000000..986f98ad --- /dev/null +++ b/dots/.config/nvim/lua/plugins/configs/typst.lua @@ -0,0 +1,7 @@ +return { + { + "chomosuke/typst-preview.nvim", + ft = "typst", + build = function() require("typst-preview").update() end, + } +}