From bbca939cedd09b423820e20d387fc42e85589a5d Mon Sep 17 00:00:00 2001 From: kaktu5 <108426150+kaktu5@users.noreply.github.com> Date: Sat, 11 Jan 2025 21:57:18 +0100 Subject: [PATCH] languages/wgsl: init module Adds Treesitter and LSP support for WebGPU Shading Language --- docs/release-notes/rl-0.8.md | 4 ++ modules/plugins/languages/default.nix | 1 + modules/plugins/languages/wgsl.nix | 79 +++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 modules/plugins/languages/wgsl.nix diff --git a/docs/release-notes/rl-0.8.md b/docs/release-notes/rl-0.8.md index 62e83a0e..93f6c1da 100644 --- a/docs/release-notes/rl-0.8.md +++ b/docs/release-notes/rl-0.8.md @@ -52,3 +52,7 @@ - Remove `vim.notes.obsidian.setupOpts.dir`, which was set by default. Fixes issue with setting the workspace directory. - Add `"prettierd"` as a formatter option in `vim.languages.markdown.format.type`. + +[kaktu5](https://github.com/kaktu5): + +- Add WGSL support under `vim.languages.wgsl`. diff --git a/modules/plugins/languages/default.nix b/modules/plugins/languages/default.nix index ee9f55e1..bf9194f2 100644 --- a/modules/plugins/languages/default.nix +++ b/modules/plugins/languages/default.nix @@ -38,6 +38,7 @@ in { ./julia.nix ./nu.nix ./odin.nix + ./wgsl.nix ]; options.vim.languages = { diff --git a/modules/plugins/languages/wgsl.nix b/modules/plugins/languages/wgsl.nix new file mode 100644 index 00000000..7c8a1016 --- /dev/null +++ b/modules/plugins/languages/wgsl.nix @@ -0,0 +1,79 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (builtins) attrNames; + inherit (lib.lists) isList; + inherit (lib.modules) mkIf mkMerge; + inherit (lib.nvim.lua) expToLua; + inherit (lib.nvim.types) mkGrammarOption; + inherit (lib.options) literalExpression mkEnableOption mkOption; + inherit (lib.types) either enum listOf package str; + + cfg = config.vim.languages.wgsl; + + defaultServer = "wgsl-analyzer"; + servers = { + wgsl-analyzer = { + package = pkgs.wgsl-analyzer; + internalFormatter = true; + lspConfig = '' + lspconfig.wgsl_analyzer.setup { + capabilities = capabilities, + on_attach = default_on_attach, + cmd = ${ + if isList cfg.lsp.package + then expToLua cfg.lsp.package + else "{'${cfg.lsp.package}/bin/wgsl_analyzer'}" + } + } + ''; + }; + }; +in { + options.vim.languages.wgsl = { + enable = mkEnableOption "WGSL language support"; + + treesitter = { + enable = mkEnableOption "WGSL treesitter" // {default = config.vim.languages.enableTreesitter;}; + package = mkGrammarOption pkgs "wgsl"; + }; + + lsp = { + enable = mkEnableOption "WGSL LSP support" // {default = config.vim.languages.enableLSP;}; + + server = mkOption { + type = enum (attrNames servers); + default = defaultServer; + description = "WGSL LSP server to use"; + }; + + package = mkOption { + description = "wgsl-analyzer package, or the command to run as a list of strings"; + example = literalExpression "[(lib.getExe pkgs.wgsl-analyzer)]"; + type = either package (listOf str); + default = pkgs.wgsl-analyzer; + }; + }; + }; + + config = mkIf cfg.enable (mkMerge [ + (mkIf cfg.treesitter.enable { + vim.treesitter = { + enable = true; + grammars = [cfg.treesitter.package]; + }; + }) + + (mkIf cfg.lsp.enable { + vim = { + lsp.lspconfig = { + enable = true; + sources.wgsl_analyzer = servers.${cfg.lsp.server}.lspConfig; + }; + }; + }) + ]); +}