From e30d42e8f25da3fe9a5f8a514c0e097c459fa2bb Mon Sep 17 00:00:00 2001 From: prescientmoon Date: Sat, 9 Mar 2024 16:57:38 +0100 Subject: [PATCH] Move lspconfig from lua to nix --- home/features/neovim/config/lazy-lock.json | 5 +- home/features/neovim/default.nix | 177 +++++++++++++----- .../{config/lua/my => }/plugins/lspconfig.lua | 30 +-- modules/common/korora-lua.nix | 2 +- 4 files changed, 137 insertions(+), 77 deletions(-) rename home/features/neovim/{config/lua/my => }/plugins/lspconfig.lua (73%) diff --git a/home/features/neovim/config/lazy-lock.json b/home/features/neovim/config/lazy-lock.json index 0872ed6..c278273 100644 --- a/home/features/neovim/config/lazy-lock.json +++ b/home/features/neovim/config/lazy-lock.json @@ -30,6 +30,7 @@ "lazy.nvim": { "branch": "main", "commit": "aedcd79811d491b60d0a6577a9c1701063c2a609" }, "lean": { "branch": "main", "commit": "1a2a2dfbc7e6775e9ec8b84e5eadaf31fde1894e" }, "live-command": { "branch": "main", "commit": "d460067d47948725a6f25b20f31ea8bbfdfe4622" }, + "lspconfig": { "branch": "master", "commit": "16295b79410f131c4fa7870c663b4ace6a761fb2" }, "lspkind.nvim": { "branch": "master", "commit": "1735dd5a5054c1fb7feaf8e8658dbab925f4f0cf" }, "luasnip": { "branch": "master", "commit": "8ae1dedd988eb56441b7858bd1e8554dfadaa46d" }, "mini.comment": { "branch": "main", "commit": "a4b7e46deb9ad2feb8902cc5dbf087eced112ee5" }, @@ -40,12 +41,12 @@ "mini.surround": { "branch": "main", "commit": "a1b590cc3b676512de507328d6bbab5e43794720" }, "navigator": { "branch": "master", "commit": "91d86506ac2a039504d5205d32a1d4bc7aa57072" }, "neoconf": { "branch": "main", "commit": "4ef6c6c5882e7e16209173fb8c47414202843384" }, - "neodev.nvim": { "branch": "main", "commit": "b0ccf605c952eb0d1efe3692d5b241c52ceee187" }, + "neodev": { "branch": "main", "commit": "84e0290f5600e8b89c0dfcafc864f45496a53400" }, "nui": { "branch": "main", "commit": "c3c7fd618dcb5a89e443a2e1033e7d11fdb0596b" }, "null-ls": { "branch": "main", "commit": "0010ea927ab7c09ef0ce9bf28c2b573fc302f5a7" }, - "nvim-lspconfig": { "branch": "master", "commit": "6b9f4bbe0aa1f351fd4845dc5fd4f3450b010f88" }, "nvim-treesitter-textobjects": { "branch": "master", "commit": "7f00d94543f1fd37cab2afa2e9a6cd54e1c6b9ef" }, "plenary": { "branch": "master", "commit": "4f71c0c4a196ceb656c824a70792f3df3ce6bb6d" }, + "purescript": { "branch": "main", "commit": "82348352e6568fcc0385bd7c99a8ead3a479feea" }, "rust-tools": { "branch": "master", "commit": "676187908a1ce35ffcd727c654ed68d851299d3e" }, "scrap": { "branch": "main", "commit": "cc8453ed613932c744c3d1ec42f379b78bd8b92c" }, "ssr": { "branch": "main", "commit": "bb323ba621ac647b4ac5638b47666e3ef3c279e1" }, diff --git a/home/features/neovim/default.nix b/home/features/neovim/default.nix index 8169da6..9a24788 100644 --- a/home/features/neovim/default.nix +++ b/home/features/neovim/default.nix @@ -1,5 +1,18 @@ { upkgs, pkgs, lib, config, inputs, ... }: let + # Toggles for including tooling related to a given language + packedTargets = { + elm = false; + latex = true; + lua = true; + nix = true; + purescript = false; + python = true; + rust = true; + typst = true; + web = true; + }; + korora = inputs.korora.lib; nlib = import ../../../modules/common/korora-neovim.nix { inherit lib korora; } @@ -283,9 +296,6 @@ let }; } ]; - - # Make neovim aware about the existence of the purescript datatype. - callback = lua ''vim.filetype.add({ extension = { purs = "purescript" } })''; }; # }}} }; @@ -512,10 +522,44 @@ let indent-blankline = { package = "lukas-reineke/indent-blankline.nvim"; main = "ibl"; - config = true; cond = blacklist "vscode"; event = "VeryLazy"; + config = true; + + # {{{{ Keybinds + keys = + let + # {{{ List of fold-related keybinds + foldKeybinds = [ + "zo" + "zO" + "zc" + "zC" + "za" + "zA" + "zv" + "zx" + "zX" + "zm" + "zM" + "zr" + "zR" + ]; + # }}} + in + [ + (nmap + "si" + "IBLToggle" + "Toggle blankline indentation") + ] ++ + (lib.forEach foldKeybinds (from: nmap + from + "${from}IBLToggleIBLToggle" + "Overriden ${from} (fold-related thing)" + )); + # }}}} }; # }}} # {{{ live-command @@ -851,9 +895,60 @@ let # }}} # }}} # {{{ ide + # {{{ lspconfig + lspconfig = { + # {{{ Nix dependencies + dependencies.nix = with lib.lists; with packedTargets; ( + optionals web [ + pkgs.nodePackages.typescript + pkgs.nodePackages_latest.vscode-langservers-extracted + pkgs.nodePackages.typescript-language-server + ] ++ + optionals lua [ + pkgs.lua-language-server + pkgs.lua + ] ++ + optionals nix [ + pkgs.rnix-lsp + pkgs.nil + inputs.nixd.packages.${pkgs.system}.nixd + ] ++ + optionals latex [ + pkgs.texlab + pkgs.texlive.combined.scheme-full + ] ++ + optionals elm [ + pkgs.elmPackages.elm + pkgs.elmPackages.elm-format + pkgs.elmPackages.elm-language-server + ] ++ + optionals purescript [ + pkgs.purescript-language-server + pkgs.nodePackages.purs-tidy + ] + ); + # }}} + dependencies.lua = [ "neoconf" "neodev" ]; + package = "neovim/nvim-lspconfig"; + + cond = blacklist "vscode"; + event = "VeryLazy"; + + config = importFrom ./plugins/lspconfig.lua "config"; + }; + # }}} # {{{ conform conform = { - dependencies.lua = [ "neovim/nvim-lspconfig" ]; + dependencies.lua = [ "lspconfig" ]; + dependencies.nix = with lib.lists; with packedTargets; ( + [ pkgs.codespell ] ++ + optional lua pkgs.stylua ++ + optional python pkgs.ruff ++ + optionals web [ + pkgs.nodePackages_latest.prettier + pkgs.nodePackages_latest.prettier_d_slim + ] + ); package = "stevearc/conform.nvim"; cond = blacklist "vscode"; @@ -862,6 +957,7 @@ let opts.format_on_save.lsp_fallback = true; opts.formatters_by_ft = let prettier = [ [ "prettierd" "prettier" ] ]; in { + "*" = [ "codespell" "trim_whitespace" ]; lua = [ "stylua" ]; python = [ "ruff_format" ]; @@ -875,6 +971,12 @@ let }; }; # }}} + # {{{ neodev + neodev = { + package = "folke/neodev.nvim"; + config = true; + }; + # }}} # {{{ neoconf neoconf = { package = "folke/neoconf.nvim"; @@ -893,7 +995,11 @@ let # {{{ null-ls null-ls = { package = "jose-elias-alvarez/null-ls.nvim"; - dependencies.lua = [ "neovim/nvim-lspconfig" ]; + dependencies.lua = [ "lspconfig" ]; + dependencies.nix = + lib.lists.optional + packedTargets.python + pkgs.ruff; cond = blacklist "vscode"; event = "VeryLazy"; @@ -1073,7 +1179,10 @@ let # {{{ rust-tools rust-tools = { package = "simrat39/rust-tools.nvim"; - dependencies.nix = [ pkgs.rust-analyzer pkgs.rustfmt ]; + dependencies.nix = + lib.lists.optionals + packedTargets.rust + [ pkgs.rust-analyzer pkgs.rustfmt ]; cond = blacklist "vscode"; ft = "rust"; @@ -1168,7 +1277,7 @@ let name = "lean"; dependencies.lua = [ "plenary" - "neovim/nvim-lspconfig" + "lspconfig" ]; cond = blacklist "vscode"; @@ -1181,7 +1290,7 @@ let }; lsp.capabilites = - lua /* lua */ ''require("my.plugins.lspconfig").capabilities''; + importFrom ./plugins/lspconfig.lua "capabilities"; lsp3 = false; # We don't want the lean 3 language server! mappings = true; @@ -1194,7 +1303,7 @@ let name = "idris"; dependencies.lua = [ "nui" - "neovim/nvim-lspconfig" + "lspconfig" ]; cond = blacklist "vscode"; @@ -1236,19 +1345,22 @@ let # {{{ typst support typst = { package = "kaarmu/typst.vim"; - dependencies.nix = [ upkgs.typst upkgs.typst-lsp upkgs.typstfmt ]; + dependencies.nix = + lib.lists.optionals + packedTargets.typst + [ upkgs.typst upkgs.typst-lsp upkgs.typstfmt ]; cond = blacklist "vscode"; ft = "typst"; }; # }}} # {{{ purescript support - # purescript = { - # package = "purescript-contrib/purescript-vim"; - # - # cond = blacklist "vscode"; - # ft = "purescript"; - # }; + purescript = { + package = "purescript-contrib/purescript-vim"; + + cond = blacklist "vscode"; + ft = "purescript"; + }; # }}} # {{{ hyprland support hyprland = { @@ -1378,35 +1490,6 @@ let }; # }}} })); - - # {{{ extraPackages - extraPackages = with pkgs; [ - # Nix - rnix-lsp - nil - inputs.nixd.packages.${system}.nixd - - # Python - ruff # Python linter - - # Web - nodePackages.typescript - nodePackages_latest.prettier - nodePackages_latest.prettier_d_slim - nodePackages_latest.vscode-langservers-extracted - nodePackages.typescript-language-server - - # Latex - texlab - # texlive.combined.scheme-full - - # Lua - lua-language-server - stylua - lua # For repls and whatnot - - ] ++ generated.dependencies; - # }}} # {{{ extraRuntime # Experimental nix module generation generatedConfig = (config.satellite.lib.lua.writeFile @@ -1447,7 +1530,7 @@ let nativeBuildInputs = [ pkgs.makeWrapper ]; postBuild = '' wrapProgram $out/bin/${binName} \ - --prefix PATH : ${lib.makeBinPath extraPackages} \ + --prefix PATH : ${lib.makeBinPath generated.dependencies} \ --add-flags ${extraFlags} \ ${extraArgs} ''; diff --git a/home/features/neovim/config/lua/my/plugins/lspconfig.lua b/home/features/neovim/plugins/lspconfig.lua similarity index 73% rename from home/features/neovim/config/lua/my/plugins/lspconfig.lua rename to home/features/neovim/plugins/lspconfig.lua index 0e25357..0c3e1a9 100644 --- a/home/features/neovim/config/lua/my/plugins/lspconfig.lua +++ b/home/features/neovim/plugins/lspconfig.lua @@ -1,17 +1,5 @@ -local runtime = require("my.tempest") - -local M = { - "neovim/nvim-lspconfig", - event = "VeryLazy", - dependencies = { - "neoconf", - { - "folke/neodev.nvim", - config = true, - }, - }, - cond = runtime.blacklist("vscode"), -} +---@diagnostic disable: missing-fields +local M = {} -- {{{ Capabilities M.capabilities = function() @@ -32,10 +20,8 @@ function M.config() -- {{{ General server config ---@type lspconfig.options - ---@diagnostic disable-next-line: missing-fields local servers = { -- {{{ Typescript - ---@diagnostic disable-next-line: missing-fields tsserver = { on_attach = function(client) -- We handle formatting using null-ls and prettierd @@ -47,7 +33,6 @@ function M.config() purescriptls = { root_dir = lspconfig.util.root_pattern("spago.yaml"), settings = { - ---@diagnostic disable-next-line: missing-fields purescript = { censorWarnings = { "UnusedName", @@ -61,14 +46,8 @@ function M.config() -- }}} -- {{{ Lua lua_ls = { - cmd = { - "lua-language-server", - "--logpath=/home/adrielus/.local/share/lua-language-server/log", - }, settings = { - ---@diagnostic disable-next-line: missing-fields Lua = { - ---@diagnostic disable-next-line: missing-fields format = { enable = true, }, @@ -91,7 +70,7 @@ function M.config() "-interaction=nonstopmode", "-synctex=1", "%f", - -- Required for syntax highlighting inside the generated pdf aparently + -- Required for syntax highlighting inside the generated pdf apparently "-shell-escape", }, executable = "latexmk", @@ -111,15 +90,12 @@ function M.config() -- nil_ls = {}, nixd = {}, -- }}} - ---@diagnostic disable-next-line: missing-fields cssls = {}, - ---@diagnostic disable-next-line: missing-fields jsonls = {}, dhall_lsp_server = {}, typst_lsp = { exportPdf = "onType", }, - ---@diagnostic disable-next-line: missing-fields elmls = {}, } -- }}} diff --git a/modules/common/korora-lua.nix b/modules/common/korora-lua.nix index 8a95dd8..a20f699 100644 --- a/modules/common/korora-lua.nix +++ b/modules/common/korora-lua.nix @@ -86,7 +86,7 @@ let mkAttrName = s: let # These list *are* incomplete - forbiddenChars = lib.stringToCharacters "<>[]{}()'\".,:;\\/"; + forbiddenChars = lib.stringToCharacters "<>[]{}()'\".,:;\\/*_"; keywords = [ "if" "then" "else" "do" "for" "local" "" ]; in if lib.any (c: lib.hasInfix c s) forbiddenChars || lib.elem s keywords then