Skip to content

Commit

Permalink
languages/wgsl: init module
Browse files Browse the repository at this point in the history
Adds Treesitter and LSP support for WebGPU Shading Language
  • Loading branch information
kaktu5 committed Jan 12, 2025
1 parent a5a5aba commit a7c7851
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/release-notes/rl-0.8.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
1 change: 1 addition & 0 deletions modules/plugins/languages/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ in {
./julia.nix
./nu.nix
./odin.nix
./wgsl.nix
];

options.vim.languages = {
Expand Down
78 changes: 78 additions & 0 deletions modules/plugins/languages/wgsl.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
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) 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";
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;
};
};
})
]);
}

0 comments on commit a7c7851

Please sign in to comment.