From ecbaecfeacf0e86fa67629119b7d7671337b5766 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Thu, 4 Jul 2024 17:36:07 +0300 Subject: [PATCH 1/4] lib/languages: move `mkEnable` up & add desc comment --- lib/languages.nix | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/languages.nix b/lib/languages.nix index e47202e..9b72d4d 100644 --- a/lib/languages.nix +++ b/lib/languages.nix @@ -5,6 +5,15 @@ inherit (lib.attrsets) listToAttrs; inherit (lib.types) bool; in { + # A wrapper around `mkOption` to create a boolean option that is + # used for Language Server modules. + mkEnable = desc: + mkOption { + description = "Turn on ${desc} for enabled languages by default"; + type = bool; + default = false; + }; + # Converts a boolean to a yes/no string. This is used in lots of # configuration formats. diagnosticsToLua = { @@ -27,11 +36,4 @@ in { value = diagnosticsProviders.${type}.nullConfig package; }) config); - - mkEnable = desc: - mkOption { - description = "Turn on ${desc} for enabled languages by default"; - type = bool; - default = false; - }; } From 0ff9476eae555e79b5d0df9cf10cd64765c9a9e2 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Thu, 26 Sep 2024 17:43:14 +0300 Subject: [PATCH 2/4] add conform.nvim & nvim-lint --- flake.lock | 34 ++++++++++++++++++ flake.nix | 12 +++++++ modules/modules.nix | 1 + modules/plugins/diagnostics/default.nix | 3 ++ .../plugins/diagnostics/nvim-lint/config.nix | 20 +++++++++++ .../plugins/diagnostics/nvim-lint/default.nix | 6 ++++ .../diagnostics/nvim-lint/nvim-lint.nix | 36 +++++++++++++++++++ .../plugins/formatter/conform-nvim/config.nix | 20 +++++++++++ .../formatter/conform-nvim/conform-nvim.nix | 33 +++++++++++++++++ .../formatter/conform-nvim/default.nix | 6 ++++ modules/plugins/formatter/default.nix | 3 ++ 11 files changed, 174 insertions(+) create mode 100644 modules/plugins/diagnostics/default.nix create mode 100644 modules/plugins/diagnostics/nvim-lint/config.nix create mode 100644 modules/plugins/diagnostics/nvim-lint/default.nix create mode 100644 modules/plugins/diagnostics/nvim-lint/nvim-lint.nix create mode 100644 modules/plugins/formatter/conform-nvim/config.nix create mode 100644 modules/plugins/formatter/conform-nvim/conform-nvim.nix create mode 100644 modules/plugins/formatter/conform-nvim/default.nix create mode 100644 modules/plugins/formatter/default.nix diff --git a/flake.lock b/flake.lock index 91fc506..a67a79a 100644 --- a/flake.lock +++ b/flake.lock @@ -396,6 +396,22 @@ "type": "github" } }, + "plugin-conform-nvim": { + "flake": false, + "locked": { + "lastModified": 1726168403, + "narHash": "sha256-AWgG+16Bh/xu50pU78mKIcQy9MKzWF1YKdbEt5jX0WQ=", + "owner": "stevearc", + "repo": "conform.nvim", + "rev": "1a99fdc1d3aa9ccdf3021e67982a679a8c5c740c", + "type": "github" + }, + "original": { + "owner": "stevearc", + "repo": "conform.nvim", + "type": "github" + } + }, "plugin-copilot-cmp": { "flake": false, "locked": { @@ -1133,6 +1149,22 @@ "type": "github" } }, + "plugin-nvim-lint": { + "flake": false, + "locked": { + "lastModified": 1727002360, + "narHash": "sha256-mg3IqNfIeWimasYEHilqv4Yx67hTHBubq19nLTNrjLk=", + "owner": "mfussenegger", + "repo": "nvim-lint", + "rev": "968a35d54b3a4c1ce66609cf80b14d4ae44fe77f", + "type": "github" + }, + "original": { + "owner": "mfussenegger", + "repo": "nvim-lint", + "type": "github" + } + }, "plugin-nvim-lspconfig": { "flake": false, "locked": { @@ -1800,6 +1832,7 @@ "plugin-cmp-vsnip": "plugin-cmp-vsnip", "plugin-codewindow-nvim": "plugin-codewindow-nvim", "plugin-comment-nvim": "plugin-comment-nvim", + "plugin-conform-nvim": "plugin-conform-nvim", "plugin-copilot-cmp": "plugin-copilot-cmp", "plugin-copilot-lua": "plugin-copilot-lua", "plugin-crates-nvim": "plugin-crates-nvim", @@ -1846,6 +1879,7 @@ "plugin-nvim-dap-ui": "plugin-nvim-dap-ui", "plugin-nvim-docs-view": "plugin-nvim-docs-view", "plugin-nvim-lightbulb": "plugin-nvim-lightbulb", + "plugin-nvim-lint": "plugin-nvim-lint", "plugin-nvim-lspconfig": "plugin-nvim-lspconfig", "plugin-nvim-navbuddy": "plugin-nvim-navbuddy", "plugin-nvim-navic": "plugin-nvim-navic", diff --git a/flake.nix b/flake.nix index c4996fc..a506cec 100644 --- a/flake.nix +++ b/flake.nix @@ -187,6 +187,18 @@ flake = false; }; + # Formatters + plugin-conform-nvim = { + url = "github:stevearc/conform.nvim"; + flake = false; + }; + + # Diagnostics + plugin-nvim-lint = { + url = "github:mfussenegger/nvim-lint"; + flake = false; + }; + # Copying/Registers plugin-registers = { url = "github:tversteeg/registers.nvim"; diff --git a/modules/modules.nix b/modules/modules.nix index 1204e43..e736aa6 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -24,6 +24,7 @@ "dashboard" "debugger" "filetree" + "formatter" "git" "languages" "lsp" diff --git a/modules/plugins/diagnostics/default.nix b/modules/plugins/diagnostics/default.nix new file mode 100644 index 0000000..3789640 --- /dev/null +++ b/modules/plugins/diagnostics/default.nix @@ -0,0 +1,3 @@ +{ + imports = [./nvim-lint]; +} diff --git a/modules/plugins/diagnostics/nvim-lint/config.nix b/modules/plugins/diagnostics/nvim-lint/config.nix new file mode 100644 index 0000000..dac2c2f --- /dev/null +++ b/modules/plugins/diagnostics/nvim-lint/config.nix @@ -0,0 +1,20 @@ +{ + config, + lib, + ... +}: let + inherit (lib.modules) mkIf; + inherit (lib.nvim.dag) entryAnywhere; + inherit (lib.nvim.lua) toLuaObject; + + cfg = config.vim.diagnostics.nvim-lint; +in { + config = mkIf cfg.enable { + vim = { + startPlugins = ["nvim-lint"]; + pluginRC.nvim-lint = entryAnywhere '' + require("lint").setup(${toLuaObject cfg.setupOpts}) + ''; + }; + }; +} diff --git a/modules/plugins/diagnostics/nvim-lint/default.nix b/modules/plugins/diagnostics/nvim-lint/default.nix new file mode 100644 index 0000000..00c526f --- /dev/null +++ b/modules/plugins/diagnostics/nvim-lint/default.nix @@ -0,0 +1,6 @@ +{ + imports = [ + ./nvim-lint.nix + ./config.nix + ]; +} diff --git a/modules/plugins/diagnostics/nvim-lint/nvim-lint.nix b/modules/plugins/diagnostics/nvim-lint/nvim-lint.nix new file mode 100644 index 0000000..45674a5 --- /dev/null +++ b/modules/plugins/diagnostics/nvim-lint/nvim-lint.nix @@ -0,0 +1,36 @@ +{ + pkgs, + lib, + ... +}: let + inherit (lib.options) mkOption mkEnableOption literalExpression; + inherit (lib.types) attrs attrsOf listOf str; + inherit (lib.nvim.types) mkPluginSetupOption; +in { + options.vim.diagnostics.nvim-lint = { + enable = mkEnableOption "asynchronous linter plugin for Neovim [nvim-lint]"; + setupOpts = mkPluginSetupOption "conform.nvim" { + linters_by_ft = mkOption { + type = attrsOf (listOf str); + default = {}; + example = { + text = ["vale"]; + markdown = ["vale"]; + }; + description = '' + Map of filetype to formatters. This option takes a set of + `key = value` format where the `value will` be converted + to its Lua equivalent. You are responsible for passing the + correct Nix data types to generate a correct Lua value that + conform is able to accept. + ''; + }; + + default_format_opts = mkOption { + type = attrs; + default = {lsp_format = "fallback";}; + description = "Default values when calling `conform.format()`"; + }; + }; + }; +} diff --git a/modules/plugins/formatter/conform-nvim/config.nix b/modules/plugins/formatter/conform-nvim/config.nix new file mode 100644 index 0000000..0b83d81 --- /dev/null +++ b/modules/plugins/formatter/conform-nvim/config.nix @@ -0,0 +1,20 @@ +{ + config, + lib, + ... +}: let + inherit (lib.modules) mkIf; + inherit (lib.nvim.dag) entryAnywhere; + inherit (lib.nvim.lua) toLuaObject; + + cfg = config.vim.formatter.conform-nvim; +in { + config = mkIf cfg.enable { + vim = { + startPlugins = ["conform-nvim"]; + pluginRC.conform-nvim = entryAnywhere '' + require("conform").setup(${toLuaObject cfg.setupOpts}) + ''; + }; + }; +} diff --git a/modules/plugins/formatter/conform-nvim/conform-nvim.nix b/modules/plugins/formatter/conform-nvim/conform-nvim.nix new file mode 100644 index 0000000..a4e0d31 --- /dev/null +++ b/modules/plugins/formatter/conform-nvim/conform-nvim.nix @@ -0,0 +1,33 @@ +{ + pkgs, + lib, + ... +}: let + inherit (lib.options) mkOption mkEnableOption literalExpression; + inherit (lib.types) attrs; + inherit (lib.nvim.types) mkPluginSetupOption; +in { + options.vim.formatter.conform-nvim = { + enable = mkEnableOption "lightweight yet powerful formatter plugin for Neovim [conform-nvim]"; + setupOpts = mkPluginSetupOption "conform.nvim" { + formatters_by_ft = mkOption { + type = attrs; + default = {}; + example = literalExpression "lua = [\"${pkgs.stylua}/bin/stylua\"]"; + description = '' + Map of filetype to formatters. This option takes a set of + `key = value` format where the `value will` be converted + to its Lua equivalent. You are responsible for passing the + correct Nix data types to generate a correct Lua value that + conform is able to accept. + ''; + }; + + default_format_opts = mkOption { + type = attrs; + default = {lsp_format = "fallback";}; + description = "Default values when calling `conform.format()`"; + }; + }; + }; +} diff --git a/modules/plugins/formatter/conform-nvim/default.nix b/modules/plugins/formatter/conform-nvim/default.nix new file mode 100644 index 0000000..56c90f3 --- /dev/null +++ b/modules/plugins/formatter/conform-nvim/default.nix @@ -0,0 +1,6 @@ +{ + imports = [ + ./conform-nvim.nix + ./config.nix + ]; +} diff --git a/modules/plugins/formatter/default.nix b/modules/plugins/formatter/default.nix new file mode 100644 index 0000000..f57ad66 --- /dev/null +++ b/modules/plugins/formatter/default.nix @@ -0,0 +1,3 @@ +{ + imports = [./conform-nvim]; +} From 72634c2603187f1b66a13f1342ab5c0e63a34bd8 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Thu, 26 Sep 2024 17:58:01 +0300 Subject: [PATCH 3/4] add more setupOpts for conform.nvim --- .../formatter/conform-nvim/conform-nvim.nix | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/modules/plugins/formatter/conform-nvim/conform-nvim.nix b/modules/plugins/formatter/conform-nvim/conform-nvim.nix index a4e0d31..be977e6 100644 --- a/modules/plugins/formatter/conform-nvim/conform-nvim.nix +++ b/modules/plugins/formatter/conform-nvim/conform-nvim.nix @@ -4,7 +4,7 @@ ... }: let inherit (lib.options) mkOption mkEnableOption literalExpression; - inherit (lib.types) attrs; + inherit (lib.types) attrs enum; inherit (lib.nvim.types) mkPluginSetupOption; in { options.vim.formatter.conform-nvim = { @@ -28,6 +28,34 @@ in { default = {lsp_format = "fallback";}; description = "Default values when calling `conform.format()`"; }; + + format_on_save = mkOption { + type = attrs; + default = { + lsp_format = "fallback"; + timeout_ms = 500; + }; + description = '' + Table that will be passed to `conform.format()`. If this + is set, Conform will run the formatter on save. + ''; + }; + + format_after_save = mkOption { + type = attrs; + default = {lsp_format = "fallback";}; + description = '' + Table that will be passed to `conform.format()`. If this + is set, Conform will run the formatter asynchronously after + save. + ''; + }; + + log_level = mkOption { + type = enum ["vim.log.levels.ERROR" "vim.log.levels.WARN" "vim.log.levels.INFO" "vim.log.levels.DEBUG"]; + default = "vim.log.levels.ERROR"; # TODO: make this luaInline + description = "Logging level for conform-nvim"; + }; }; }; } From c4dbf87dee54b915d25083a785597883c6e0859e Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Wed, 16 Oct 2024 04:19:32 +0300 Subject: [PATCH 4/4] languages/html: add HTML LSP --- modules/plugins/languages/html.nix | 48 ++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/modules/plugins/languages/html.nix b/modules/plugins/languages/html.nix index 0bef276..749347c 100644 --- a/modules/plugins/languages/html.nix +++ b/modules/plugins/languages/html.nix @@ -4,17 +4,54 @@ lib, ... }: let - inherit (lib.options) mkEnableOption mkOption; + inherit (builtins) attrNames; + inherit (lib.options) mkOption mkEnableOption; inherit (lib.modules) mkIf mkMerge; - inherit (lib.types) bool; - inherit (lib.lists) optional; + inherit (lib.lists) optional isList; + inherit (lib.types) enum either package listOf str bool; inherit (lib.nvim.types) mkGrammarOption; + inherit (lib.nvim.lua) expToLua; inherit (lib.nvim.dag) entryAnywhere; cfg = config.vim.languages.html; + + defaultServer = "html"; + servers = { + html = { + package = pkgs.vscode-langservers-extracted; + lspConfig = '' + lspconfig.html.setup{ + capabilities = capabilities; + on_attach = default_on_attach; + cmd = ${ + if isList cfg.lsp.package + then expToLua cfg.lsp.package + else ''{"${cfg.lsp.package}/bin/vscode-html-language-server", "--stdio"}'' + }; + } + ''; + }; + }; in { options.vim.languages.html = { enable = mkEnableOption "HTML language support"; + + lsp = { + enable = mkEnableOption "Enable HTML LSP support" // {default = config.vim.languages.enableLSP;}; + + server = mkOption { + type = enum (attrNames servers); + default = defaultServer; + description = "HTML LSP server to use"; + }; + + package = mkOption { + type = either package (listOf str); + default = pkgs.vscode-langservers-extracted; + description = "html-language-server package, or the command to run as a list of strings"; + }; + }; + treesitter = { enable = mkEnableOption "HTML treesitter support" // {default = config.vim.languages.enableTreesitter;}; package = mkGrammarOption pkgs "html"; @@ -27,6 +64,11 @@ in { }; config = mkIf cfg.enable (mkMerge [ + (mkIf cfg.lsp.enable { + vim.lsp.lspconfig.enable = true; + vim.lsp.lspconfig.sources.html-lsp = servers.${cfg.lsp.server}.lspConfig; + }) + (mkIf cfg.treesitter.enable { vim = { startPlugins = optional cfg.treesitter.autotagHtml "nvim-ts-autotag";