From 42dc74ae7b84edf041c4bb4a4ee343873f67a358 Mon Sep 17 00:00:00 2001 From: Liyua Date: Tue, 1 Jul 2025 20:41:54 +0200 Subject: [PATCH] Removed old code --- modules/plugins/languages/nix.nix | 129 ++++++++++++++---------------- 1 file changed, 59 insertions(+), 70 deletions(-) diff --git a/modules/plugins/languages/nix.nix b/modules/plugins/languages/nix.nix index 74881638..9aabd24a 100644 --- a/modules/plugins/languages/nix.nix +++ b/modules/plugins/languages/nix.nix @@ -4,8 +4,7 @@ lib, inputs, ... -}: -let +}: let inherit (builtins) attrNames; inherit (lib) concatStringsSep mkLuaInline; inherit (lib.meta) getExe; @@ -13,7 +12,8 @@ let inherit (lib.modules) mkIf mkMerge; inherit (lib.lists) isList; inherit (lib.strings) optionalString; - inherit (lib.types) + inherit + (lib.types) anything attrsOf enum @@ -32,60 +32,37 @@ let noFormat = "on_attach = attach_keymaps"; defaultServer = "nil"; - packageToCmd = - package: defaultCmd: - if isList package then expToLua package else ''{"${package}/bin/${defaultCmd}"}''; + packageToCmd = package: defaultCmd: + if isList package + then expToLua package + else ''{"${package}/bin/${defaultCmd}"}''; servers = { nil = { package = inputs.nil.packages.${pkgs.stdenv.system}.nil; internalFormatter = true; lspConfig = ''lspconfig.nil_ls.setup ${ - toLuaObject { - capabilities = mkLuaInline "capabilities"; - on_attach = if cfg.format.enable then mkLuaInline "default_on_attach" else "attach_keymaps"; - cmd = mkLuaInline (packageToCmd cfg.lsp.package "nil"); - settings.nil = { - formatting.command = - if cfg.format.enable then - if cfg.format.type == "alejandra" then - mkLuaInline ''{"${cfg.format.package}/bin/alejandra", "--quiet"}'' - else if cfg.format.type == "nixfmt" then - mkLuaInline ''{"${cfg.format.package}/bin/nixfmt"}'' - else - null - else - null; - } // cfg.lsp.options; - } - }''; - # lspConfig = '' - # lspconfig.nil_ls.setup{ - # capabilities = capabilities, - # ${ - # if cfg.format.enable - # then useFormat - # else noFormat - # }, - # cmd = ${packageToCmd cfg.lsp.package "nil"}, - # ${optionalString cfg.format.enable '' - # settings = { - # ["nil"] = { - # ${optionalString (cfg.format.type == "alejandra") '' - # formatting = { - # command = {"${cfg.format.package}/bin/alejandra", "--quiet"}, - # }, - # ''} - # ${optionalString (cfg.format.type == "nixfmt") '' - # formatting = { - # command = {"${cfg.format.package}/bin/nixfmt"}, - # }, - # ''} - # nix = ${toLuaObject cfg.lsp.options}, - # }, - # }, - # ''} - # } - # ''; + toLuaObject { + capabilities = mkLuaInline "capabilities"; + on_attach = + if cfg.format.enable + then mkLuaInline "default_on_attach" + else "attach_keymaps"; + cmd = mkLuaInline (packageToCmd cfg.lsp.package "nil"); + settings.nil = + { + formatting.command = + if cfg.format.enable + then + if cfg.format.type == "alejandra" + then mkLuaInline ''{"${cfg.format.package}/bin/alejandra", "--quiet"}'' + else if cfg.format.type == "nixfmt" + then mkLuaInline ''{"${cfg.format.package}/bin/nixfmt"}'' + else null + else null; + } + // cfg.lsp.options; + } + }''; }; nixd = { @@ -94,7 +71,11 @@ let lspConfig = '' lspconfig.nixd.setup{ capabilities = capabilities, - ${if cfg.format.enable then useFormat else noFormat}, + ${ + if cfg.format.enable + then useFormat + else noFormat + }, cmd = ${packageToCmd cfg.lsp.package "nixd"}, ${optionalString cfg.format.enable '' settings = { @@ -158,22 +139,25 @@ let ''; }; }; -in -{ +in { options.vim.languages.nix = { enable = mkEnableOption "Nix language support"; treesitter = { - enable = mkEnableOption "Nix treesitter" // { - default = config.vim.languages.enableTreesitter; - }; + enable = + mkEnableOption "Nix treesitter" + // { + default = config.vim.languages.enableTreesitter; + }; package = mkGrammarOption pkgs "nix"; }; lsp = { - enable = mkEnableOption "Nix LSP support" // { - default = config.vim.lsp.enable; - }; + enable = + mkEnableOption "Nix LSP support" + // { + default = config.vim.lsp.enable; + }; server = mkOption { description = "Nix LSP server to use"; type = enum (attrNames servers); @@ -195,9 +179,11 @@ in }; format = { - enable = mkEnableOption "Nix formatting" // { - default = config.vim.languages.enableFormat; - }; + enable = + mkEnableOption "Nix formatting" + // { + default = config.vim.languages.enableFormat; + }; type = mkOption { description = "Nix formatter to use"; @@ -213,9 +199,11 @@ in }; extraDiagnostics = { - enable = mkEnableOption "extra Nix diagnostics" // { - default = config.vim.languages.enableExtraDiagnostics; - }; + enable = + mkEnableOption "extra Nix diagnostics" + // { + default = config.vim.languages.enableExtraDiagnostics; + }; types = diagnostics { langDesc = "Nix"; @@ -247,7 +235,7 @@ in (mkIf cfg.treesitter.enable { vim.treesitter.enable = true; - vim.treesitter.grammars = [ cfg.treesitter.package ]; + vim.treesitter.grammars = [cfg.treesitter.package]; }) (mkIf cfg.lsp.enable { @@ -258,7 +246,7 @@ in (mkIf (cfg.format.enable && (!cfg.lsp.enable || !servers.${cfg.lsp.server}.internalFormatter)) { vim.formatter.conform-nvim = { enable = true; - setupOpts.formatters_by_ft.nix = [ cfg.format.type ]; + setupOpts.formatters_by_ft.nix = [cfg.format.type]; setupOpts.formatters.${cfg.format.type} = { command = getExe cfg.format.package; }; @@ -272,7 +260,8 @@ in linters = mkMerge ( map (name: { ${name}.cmd = getExe diagnosticsProviders.${name}.package; - }) cfg.extraDiagnostics.types + }) + cfg.extraDiagnostics.types ); }; })