From e473cb93a157aa62d576fc70ac278783a47990fa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20Av=C3=A9?= <email@thomasave.be>
Date: Mon, 26 Feb 2024 23:25:15 +0100
Subject: [PATCH] Add Typst

---
 nvim/init.lua                        |  2 --
 nvim/lua/plugins/mason.lua           |  2 +-
 nvim/lua/plugins/nvim-cmp.lua        | 11 ++++++++---
 nvim/lua/plugins/treesitter.lua      | 16 ++++++++++++++--
 nvim/spell/ltex.dictionary.en-GB.txt |  2 ++
 5 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/nvim/init.lua b/nvim/init.lua
index 5767cde..b19b291 100644
--- a/nvim/init.lua
+++ b/nvim/init.lua
@@ -4,7 +4,5 @@ require('mappings')
 require('teaching')
 
 vim.api.nvim_create_autocmd("FileType", { pattern = "make", command = [[set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab]] })
-vim.api.nvim_create_autocmd("FileType", { pattern = "vimwiki", command = [[setlocal shiftwidth=2 softtabstop=2 expandtab]] })
-vim.api.nvim_create_autocmd("FileType", { pattern = "vimwiki", command = [[setlocal filetype=markdown]] })
 vim.api.nvim_create_autocmd("FileType", { pattern = "javascript", command = [[setlocal shiftwidth=2 softtabstop=2 expandtab]] })
 vim.api.nvim_create_autocmd("FileType", { pattern = "vue", command = [[setlocal shiftwidth=2 softtabstop=2 expandtab]] })
diff --git a/nvim/lua/plugins/mason.lua b/nvim/lua/plugins/mason.lua
index b3f8679..97bd7ba 100644
--- a/nvim/lua/plugins/mason.lua
+++ b/nvim/lua/plugins/mason.lua
@@ -11,6 +11,6 @@ return {
         'neovim/nvim-lspconfig'
     },
     opts = {
-        ensure_installed = { "pyright", "texlab", "clangd", "bashls", "cmake", "jsonls", "tsserver", "vuels", "dockerls", "vimls", "html", "yamlls", "cssls", "lua_ls", "ltex", "gopls", "rust_analyzer", "jdtls", "emmet_ls", "ruff_lsp", "csharp_ls" },
+        ensure_installed = { "pyright", "texlab", "clangd", "bashls", "cmake", "jsonls", "tsserver", "vuels", "dockerls", "vimls", "html", "yamlls", "cssls", "lua_ls", "ltex", "gopls", "rust_analyzer", "jdtls", "emmet_ls", "ruff_lsp", "csharp_ls", "typst_lsp" },
     }
 }
diff --git a/nvim/lua/plugins/nvim-cmp.lua b/nvim/lua/plugins/nvim-cmp.lua
index 71e871e..b78d389 100644
--- a/nvim/lua/plugins/nvim-cmp.lua
+++ b/nvim/lua/plugins/nvim-cmp.lua
@@ -151,6 +151,10 @@ return {
             capabilities = capabilities
         }
 
+        require('lspconfig').typst_lsp.setup {
+            capabilities = capabilities
+        }
+
         require('lspconfig').cmake.setup {
             capabilities = capabilities
         }
@@ -256,10 +260,11 @@ return {
             end,
             settings = {
                 ltex = {
-                    enabled = true,
+                    enabled = { "bibtex", "gitcommit", "markdown", "org", "tex", "restructuredtext", "rsweave", "latex", "quarto", "rmd", "context", "html", "xhtml", "typst" },
                     language = "en-GB"
-                }
-            }
+                },
+            },
+            filetypes = { "bib", "gitcommit", "markdown", "org", "plaintex", "rst", "rnoweb", "tex", "pandoc", "quarto", "rmd", "context", "html", "xhtml" , "typst"}
         }
 
         vim.diagnostic.config({
diff --git a/nvim/lua/plugins/treesitter.lua b/nvim/lua/plugins/treesitter.lua
index 04397f4..12684a7 100644
--- a/nvim/lua/plugins/treesitter.lua
+++ b/nvim/lua/plugins/treesitter.lua
@@ -1,6 +1,9 @@
 return {
     'nvim-treesitter/nvim-treesitter',
-    dependencies = {"luckasRanarison/tree-sitter-hyprlang"},
+    dependencies = {
+        "https://github.com/TheZoq2/tree-sitter-typst",
+        "luckasRanarison/tree-sitter-hyprlang"
+    },
     build = ":TSUpdate",
     opts = {
         ensure_installed = { "cpp", "c", "lua", "vim", "dockerfile", "python", "java", "cmake", "diff", "gitcommit", "html", "css", "javascript", "json", "rust", "sql", "yaml", "markdown", "markdown_inline" },
@@ -25,8 +28,17 @@ return {
     },
     config = function (_, opts)
         require("nvim-treesitter.configs").setup(opts)
+        local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
+        require'nvim-treesitter.install'.prefer_git = true
+        parser_config.typst = {
+            install_info = {
+                url = "https://github.com/frozolotl/tree-sitter-typst.git", -- local path or git repo
+                files = {"src/parser.c", "src/scanner.cc"},
+            },
+            filetype = "typst", -- if filetype does not match the parser name
+        }
         vim.filetype.add({
-            pattern = { [".*/hyprland%.conf"] = "hyprlang" },
+            pattern = { [".*.typ"] = "typst" },
         })
     end
 }
diff --git a/nvim/spell/ltex.dictionary.en-GB.txt b/nvim/spell/ltex.dictionary.en-GB.txt
index 51c1d9e..3286e6b 100644
--- a/nvim/spell/ltex.dictionary.en-GB.txt
+++ b/nvim/spell/ltex.dictionary.en-GB.txt
@@ -4,3 +4,5 @@ OpenSwarm
 Lumentis
 stochasticity
 Feywild
+ECML
+theshold-based