diff --git a/configuration.nix b/configuration.nix index 15f85480..2159edc8 100644 --- a/configuration.nix +++ b/configuration.nix @@ -80,6 +80,7 @@ isMaximal: { ocaml.enable = false; elixir.enable = false; haskell.enable = false; + ruby.enable = false; tailwind.enable = false; svelte.enable = false; diff --git a/docs/manual/hacking/guidelines.md b/docs/manual/hacking/guidelines.md index 882deea8..a1db27e8 100644 --- a/docs/manual/hacking/guidelines.md +++ b/docs/manual/hacking/guidelines.md @@ -14,14 +14,11 @@ necessarily) before you start developing. ## Adding Documentation {#sec-guidelines-documentation} -Most, if not all, changes warrant changes to the documentation. Module options -should be documented with -[Nixpkgs-flavoured Markdown](https://nixos.org/manual/nixpkgs/unstable/#sec-contributing-markup), -albeit with exceptions. +[Nixpkgs Flavoured Markdown]: https://github.com/NixOS/nixpkgs/blob/master/doc/README.md#syntax -::: {.note} As of **v0.5**, **nvf** is itself documented using full markdown in -both module options and the manual. With **v0.6**, this manual has also been -converted to markdown in full. ::: +Almost all changes warrant updates to the documentation: at the very least, you +must update the changelog. Both the manual and module options use +[Nixpkgs Flavoured Markdown]. The HTML version of this manual containing both the module option descriptions and the documentation of **nvf** (such as this page) can be generated and opened @@ -117,10 +114,11 @@ applies to string literals and module descriptions and documentation. ### Nix {#sec-code-style-nix} -**nvf** is formatted by the -[alejandra](https://github.com/kamadorueda/alejandra) tool and the formatting is -checked in the pull request and push workflows. Run the `nix fmt` command inside -the project repository before submitting your pull request. +[alejandra]: https://github.com/kamadorueda/alejandra + +**nvf** is formatted by the [alejandra] tool and the formatting is checked in +the pull request and push workflows. Run the `nix fmt` command inside the +project repository before submitting your pull request. While Alejandra is mostly opinionated on how code looks after formatting, certain changes are done at the user's discretion based on how the original code @@ -138,10 +136,14 @@ module = { # same as parent modules, unfold submodules subModule = { # this is an option that contains more than one nested value + # Note: try to be careful about the ordering of `mkOption` arguments. + # General rule of thumb is to order from least to most likely to change. + # This is, for most cases, type < default < description. + # Example, if present, would be between default and description someOtherValue = mkOption { type = lib.types.bool; - description = "Some other description"; default = true; + description = "Some other description"; }; }; } diff --git a/docs/release-notes/rl-0.8.md b/docs/release-notes/rl-0.8.md index 5d192df2..c417a4bd 100644 --- a/docs/release-notes/rl-0.8.md +++ b/docs/release-notes/rl-0.8.md @@ -57,4 +57,15 @@ - Remove `vim.notes.obsidian.setupOpts.dir`, which was set by default. Fixes issue with setting the workspace directory. +- Add `vim.snippets.luasnip.setupOpts`, which was previously missing. - Add `"prettierd"` as a formatter option in `vim.languages.markdown.format.type`. + +[kaktu5](https://github.com/kaktu5): + +- Add WGSL support under `vim.languages.wgsl`. + +[tomasguinzburg](https://github.com/tomasguinzburg): + +[solargraph]: https://github.com/castwide/solargraph + +- Add Ruby support under `vim.languages.ruby` using [solargraph]. diff --git a/modules/plugins/languages/default.nix b/modules/plugins/languages/default.nix index ee9f55e1..219e04fb 100644 --- a/modules/plugins/languages/default.nix +++ b/modules/plugins/languages/default.nix @@ -38,6 +38,8 @@ in { ./julia.nix ./nu.nix ./odin.nix + ./wgsl.nix + ./ruby.nix ]; options.vim.languages = { diff --git a/modules/plugins/languages/ruby.nix b/modules/plugins/languages/ruby.nix new file mode 100644 index 00000000..33f11d5d --- /dev/null +++ b/modules/plugins/languages/ruby.nix @@ -0,0 +1,152 @@ +{ + config, + pkgs, + lib, + ... +}: let + inherit (builtins) attrNames; + inherit (lib.options) mkEnableOption mkOption; + inherit (lib.modules) mkIf mkMerge; + inherit (lib.nvim.types) mkGrammarOption diagnostics; + inherit (lib.types) either listOf package str enum; + inherit (lib.nvim.languages) diagnosticsToLua; + + cfg = config.vim.languages.ruby; + + defaultServer = "rubyserver"; + servers = { + rubyserver = { + package = pkgs.rubyPackages.solargraph; + lspConfig = '' + lspconfig.solargraph.setup { + capabilities = capabilities, + on_attach = attach_keymaps, + flags = { + debounce_text_changes = 150, + }, + cmd = { "${pkgs.solargraph}/bin/solargraph", "stdio" } + } + ''; + }; + }; + + # testing + + defaultFormat = "rubocop"; + formats = { + rubocop = { + package = pkgs.rubyPackages.rubocop; + nullConfig = '' + local conditional = function(fn) + local utils = require("null-ls.utils").make_conditional_utils() + return fn(utils) + end + + table.insert( + ls_sources, + null_ls.builtins.formatting.rubocop.with({ + command="${pkgs.bundler}/bin/bundle", + args = vim.list_extend( + {"exec", "rubocop", "-a" }, + null_ls.builtins.formatting.rubocop._opts.args + ), + }) + ) + ''; + }; + }; + + defaultDiagnosticsProvider = ["rubocop"]; + diagnosticsProviders = { + rubocop = { + package = pkgs.rubyPackages.rubocop; + nullConfig = pkg: '' + table.insert( + ls_sources, + null_ls.builtins.diagnostics.rubocop.with({ + command = "${lib.getExe pkg}", + }) + ) + ''; + }; + }; +in { + options.vim.languages.ruby = { + enable = mkEnableOption "Ruby language support"; + + treesitter = { + enable = mkEnableOption "Ruby treesitter" // {default = config.vim.languages.enableTreesitter;}; + package = mkGrammarOption pkgs "ruby"; + }; + + lsp = { + enable = mkEnableOption "Ruby LSP support" // {default = config.vim.languages.enableLSP;}; + + server = mkOption { + type = enum (attrNames servers); + default = defaultServer; + description = "Ruby LSP server to use"; + }; + + package = mkOption { + type = either package (listOf str); + default = servers.${cfg.lsp.server}.package; + description = "Ruby LSP server package, or the command to run as a list of strings"; + }; + }; + + format = { + enable = mkEnableOption "Ruby formatter support" // {default = config.vim.languages.enableFormat;}; + + type = mkOption { + type = enum (attrNames formats); + default = defaultFormat; + description = "Ruby formatter to use"; + }; + + package = mkOption { + type = package; + default = formats.${cfg.format.type}.package; + description = "Ruby formatter package"; + }; + }; + + extraDiagnostics = { + enable = + mkEnableOption "Ruby extra diagnostics support" + // {default = config.vim.languages.enableExtraDiagnostics;}; + + types = diagnostics { + langDesc = "Ruby"; + inherit diagnosticsProviders; + inherit defaultDiagnosticsProvider; + }; + }; + }; + + config = mkIf cfg.enable (mkMerge [ + (mkIf cfg.treesitter.enable { + vim.treesitter.enable = true; + vim.treesitter.grammars = [cfg.treesitter.package]; + }) + + (mkIf cfg.lsp.enable { + vim.lsp.lspconfig.enable = true; + vim.lsp.lspconfig.sources.ruby-lsp = servers.${cfg.lsp.server}.lspConfig; + }) + + (mkIf cfg.format.enable { + vim.lsp.null-ls.enable = true; + vim.lsp.null-ls.sources.ruby-format = formats.${cfg.format.type}.nullConfig; + }) + + (mkIf cfg.extraDiagnostics.enable { + vim.lsp.null-ls.enable = true; + vim.lsp.null-ls.sources = diagnosticsToLua { + lang = "ruby"; + config = cfg.extraDiagnostics.types; + inherit diagnosticsProviders; + }; + }) + ]); +} 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; + }; + }; + }) + ]); +} diff --git a/modules/plugins/snippets/luasnip/config.nix b/modules/plugins/snippets/luasnip/config.nix index 92bcfbec..11be37c1 100644 --- a/modules/plugins/snippets/luasnip/config.nix +++ b/modules/plugins/snippets/luasnip/config.nix @@ -9,12 +9,15 @@ in { config = mkIf cfg.enable { vim = { - lazy.plugins = { - luasnip = { - package = "luasnip"; - lazy = true; - after = cfg.loaders; - }; + lazy.plugins.luasnip = { + package = "luasnip"; + + lazy = true; + + setupModule = "luasnip"; + inherit (cfg) setupOpts; + + after = cfg.loaders; }; startPlugins = cfg.providers; autocomplete.nvim-cmp = mkIf config.vim.autocomplete.nvim-cmp.enable { diff --git a/modules/plugins/snippets/luasnip/luasnip.nix b/modules/plugins/snippets/luasnip/luasnip.nix index d9563a5b..6b189b61 100644 --- a/modules/plugins/snippets/luasnip/luasnip.nix +++ b/modules/plugins/snippets/luasnip/luasnip.nix @@ -1,7 +1,7 @@ {lib, ...}: let inherit (lib.options) mkEnableOption mkOption literalExpression literalMD; inherit (lib.types) listOf lines; - inherit (lib.nvim.types) pluginType; + inherit (lib.nvim.types) pluginType mkPluginSetupOption; in { options.vim.snippets.luasnip = { enable = mkEnableOption "luasnip"; @@ -32,5 +32,9 @@ in { ``` ''; }; + + setupOpts = mkPluginSetupOption "LuaSnip" { + enable_autosnippets = mkEnableOption "autosnippets"; + }; }; }