From 1bd0ae5f7e795376e2f262dd8e2886e7fd4083c2 Mon Sep 17 00:00:00 2001 From: Soliprem <73885403+Soliprem@users.noreply.github.com> Date: Fri, 8 Nov 2024 16:10:40 +0100 Subject: [PATCH] typst: added tinymist and activated formatters (#444) * typst: added tinymist and activated formatters * docs: added tinymist release notes * typst: formatting * docs: complying with standards * typst: formatting --- docs/release-notes/rl-0.7.md | 1 + modules/plugins/languages/typst.nix | 57 +++++++++++++++++++++++------ 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/docs/release-notes/rl-0.7.md b/docs/release-notes/rl-0.7.md index 00cfdac..c20793a 100644 --- a/docs/release-notes/rl-0.7.md +++ b/docs/release-notes/rl-0.7.md @@ -302,6 +302,7 @@ To migrate to `nixfmt`, simply change `vim.languages.nix.format.type` to `vim.languages.kotlin` - changed default keybinds for leap.nvim to avoid altering expected behavior - Add LSP, formatter and Treesitter support for Vala under `vim.languages.vala` +- Add [Tinymist](https://github.com/Myriad-Dreamin/tinymist] as a formatter for the Typst language module. [Bloxx12](https://github.com/Bloxx12) diff --git a/modules/plugins/languages/typst.nix b/modules/plugins/languages/typst.nix index da63c54..c2ba710 100644 --- a/modules/plugins/languages/typst.nix +++ b/modules/plugins/languages/typst.nix @@ -14,6 +14,38 @@ cfg = config.vim.languages.typst; + defaultServer = "tinymist"; + servers = { + typst-lsp = { + package = pkgs.typst-lsp; + lspConfig = '' + lspconfig.typst_lsp.setup { + capabilities = capabilities, + on_attach = default_on_attach, + cmd = ${ + if isList cfg.lsp.package + then expToLua cfg.lsp.package + else ''{"${cfg.lsp.package}/bin/typst-lsp"}'' + }, + } + ''; + }; + tinymist = { + package = pkgs.tinymist; + lspConfig = '' + lspconfig.tinymist.setup { + capabilities = capabilities, + on_attach = default_on_attach, + cmd = ${ + if isList cfg.lsp.package + then expToLua cfg.lsp.package + else ''{"${cfg.lsp.package}/bin/tinymist"}'' + }, + } + ''; + }; + }; + defaultFormat = "typstfmt"; formats = { typstfmt = { @@ -52,11 +84,17 @@ in { lsp = { enable = mkEnableOption "Typst LSP support (typst-lsp)" // {default = config.vim.languages.enableLSP;}; + server = mkOption { + description = "Typst LSP server to use"; + type = enum (attrNames servers); + default = defaultServer; + }; + package = mkOption { description = "typst-lsp package, or the command to run as a list of strings"; example = ''[lib.getExe pkgs.jdt-language-server "-data" "~/.cache/jdtls/workspace"]''; type = either package (listOf str); - default = pkgs.typst-lsp; + default = servers.${cfg.lsp.server}.package; }; }; @@ -82,19 +120,14 @@ in { vim.treesitter.grammars = [cfg.treesitter.package]; }) + (mkIf cfg.format.enable { + vim.lsp.null-ls.enable = true; + vim.lsp.null-ls.sources.typst-format = formats.${cfg.format.type}.nullConfig; + }) + (mkIf cfg.lsp.enable { vim.lsp.lspconfig.enable = true; - vim.lsp.lspconfig.sources.typst-lsp = '' - lspconfig.typst_lsp.setup { - capabilities = capabilities, - on_attach=default_on_attach, - cmd = ${ - if isList cfg.lsp.package - then expToLua cfg.lsp.package - else ''{"${cfg.lsp.package}/bin/typst-lsp"}'' - }, - } - ''; + vim.lsp.lspconfig.sources.typst-lsp = servers.${cfg.lsp.server}.lspConfig; }) ]); }