From bc76ced636feadbb195ff1dceb809e4e6fbddd9c Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Fri, 28 Mar 2025 12:05:17 +0100 Subject: [PATCH] language/svelte: migrate to conform/nvim-lint --- modules/plugins/languages/svelte.nix | 80 +++++++++++++--------------- 1 file changed, 36 insertions(+), 44 deletions(-) diff --git a/modules/plugins/languages/svelte.nix b/modules/plugins/languages/svelte.nix index 4d96c20a..67f11bc2 100644 --- a/modules/plugins/languages/svelte.nix +++ b/modules/plugins/languages/svelte.nix @@ -9,9 +9,9 @@ inherit (lib.modules) mkIf mkMerge; inherit (lib.lists) isList; inherit (lib.meta) getExe; + inherit (lib.generators) mkLuaInline; inherit (lib.types) enum either listOf package str; inherit (lib.nvim.lua) expToLua; - inherit (lib.nvim.languages) diagnosticsToLua; inherit (lib.nvim.types) mkGrammarOption diagnostics; cfg = config.vim.languages.svelte; @@ -39,52 +39,38 @@ formats = { prettier = { package = pkgs.nodePackages.prettier; - nullConfig = '' - table.insert( - ls_sources, - null_ls.builtins.formatting.prettier.with({ - command = "${cfg.format.package}/bin/prettier", - }) - ) - ''; }; biome = { package = pkgs.biome; - nullConfig = '' - table.insert( - ls_sources, - null_ls.builtins.formatting.biome.with({ - command = "${cfg.format.package}/bin/biome", - }) - ) - ''; }; }; # TODO: specify packages defaultDiagnosticsProvider = ["eslint_d"]; diagnosticsProviders = { - eslint_d = { - package = pkgs.eslint_d; - nullConfig = pkg: '' - table.insert( - ls_sources, - null_ls.builtins.diagnostics.eslint_d.with({ - command = "${getExe pkg}", - condition = function(utils) - return utils.root_has_file({ - "eslint.config.js", - "eslint.config.mjs", - ".eslintrc", - ".eslintrc.json", - ".eslintrc.js", - ".eslintrc.yml", - }) - end, - }) - ) - ''; + eslint_d = let + pkg = pkgs.eslint_d; + in { + package = pkg; + config = { + cmd = getExe pkg; + # HACK: change if nvim-lint gets a dynamic enable thing + parser = mkLuaInline '' + function(output, bufnr, cwd) + local markers = { "eslint.config.js", "eslint.config.mjs", + ".eslintrc", ".eslintrc.json", ".eslintrc.js", ".eslintrc.yml", } + for _, filename in ipairs(markers) do + local path = vim.fs.join(cwd, filename) + if vim.loop.fs_stat(path) then + return require("lint.linters.eslint_d").parser(output, bufnr, cwd) + end + end + + return {} + end + ''; + }; }; }; in { @@ -153,16 +139,22 @@ in { }) (mkIf cfg.format.enable { - vim.lsp.null-ls.enable = true; - vim.lsp.null-ls.sources.svelte-format = formats.${cfg.format.type}.nullConfig; + vim.formatter.conform-nvim = { + enable = true; + setupOpts.formatters_by_ft.svelte = [cfg.format.type]; + setupOpts.formatters.${cfg.format.type} = { + command = getExe cfg.format.package; + }; + }; }) (mkIf cfg.extraDiagnostics.enable { - vim.lsp.null-ls.enable = true; - vim.lsp.null-ls.sources = diagnosticsToLua { - lang = "svelte"; - config = cfg.extraDiagnostics.types; - inherit diagnosticsProviders; + vim.diagnostics.nvim-lint = { + enable = true; + linters_by_ft.svelte = cfg.extraDiagnostics.types; + linters = + mkMerge (map (name: {${name} = diagnosticsProviders.${name}.config;}) + cfg.extraDiagnostics.types); }; }) ]);