diff --git a/docs/release-notes/rl-0.8.md b/docs/release-notes/rl-0.8.md index b7ead61e..1d7ce102 100644 --- a/docs/release-notes/rl-0.8.md +++ b/docs/release-notes/rl-0.8.md @@ -28,10 +28,6 @@ align with the "hunks" themed mapping and avoid conflict with the new [neogit] group. -- LSP keybinds and related plugin integrations are now attached in an LspAttach - autocmd event. If you were calling `default_on_attach()` in your LSP setup you - can remove them now. - [NotAShelf](https://github.com/notashelf): [typst-preview.nvim]: https://github.com/chomosuke/typst-preview.nvim @@ -139,8 +135,6 @@ - Moved code setting `additionalRuntimePaths` and `enableLuaLoader` out of `luaConfigPre`'s default to prevent being overridden - Use conform over custom autocmds for LSP format on save -- Move LSP keybinds and other related plugin integrations into an LspAttach - event. [diniamo](https://github.com/diniamo): diff --git a/lib/dag.nix b/lib/dag.nix index db5d53b7..cbf52083 100644 --- a/lib/dag.nix +++ b/lib/dag.nix @@ -8,7 +8,7 @@ # - the addition of the function `entryBefore` indicating a "wanted # by" relationship. {lib}: let - inherit (builtins) isAttrs attrValues attrNames elem all head tail length toJSON isString removeAttrs; + inherit (builtins) isAttrs attrValues attrNames elem all head tail length toJSON isString; inherit (lib.attrsets) filterAttrs mapAttrs; inherit (lib.lists) toposort; inherit (lib.nvim.dag) empty isEntry entryBetween entryAfter entriesBetween entryAnywhere topoSort; @@ -169,11 +169,10 @@ in { else value) dag; sortedDag = topoSort finalDag; - loopDetail = map (loops: removeAttrs loops ["data"]) sortedDag.loops; result = if sortedDag ? result then mapResult sortedDag.result - else abort ("Dependency cycle in ${name}: " + toJSON loopDetail); + else abort ("Dependency cycle in ${name}: " + toJSON sortedDag); in result; } diff --git a/modules/neovim/init/autocmds.nix b/modules/neovim/init/autocmds.nix index 579a211e..07656134 100644 --- a/modules/neovim/init/autocmds.nix +++ b/modules/neovim/init/autocmds.nix @@ -9,7 +9,7 @@ inherit (lib.types) nullOr submodule listOf str bool; inherit (lib.nvim.types) luaInline; inherit (lib.nvim.lua) toLuaObject; - inherit (lib.nvim.dag) entryAfter entryBetween; + inherit (lib.nvim.dag) entryAfter; autocommandType = submodule { options = { @@ -144,7 +144,7 @@ in { enabledAutogroups = filter (au: au.enable) cfg.augroups; in { luaConfigRC = { - augroups = entryBetween ["autocmds"] ["pluginConfigs"] (optionalString (enabledAutogroups != []) '' + augroups = entryAfter ["pluginConfigs"] (optionalString (enabledAutogroups != []) '' local nvf_autogroups = {} for _, group in ipairs(${toLuaObject enabledAutogroups}) do if group.name then diff --git a/modules/neovim/init/lsp.nix b/modules/neovim/init/lsp.nix index b17c5554..6c18b98e 100644 --- a/modules/neovim/init/lsp.nix +++ b/modules/neovim/init/lsp.nix @@ -77,6 +77,7 @@ in { { vim.lsp.servers."*" = { capabilities = mkDefault (mkLuaInline "capabilities"); + on_attach = mkDefault (mkLuaInline "default_on_attach"); }; } diff --git a/modules/plugins/languages/clang.nix b/modules/plugins/languages/clang.nix index 20e4fab1..487bc151 100644 --- a/modules/plugins/languages/clang.nix +++ b/modules/plugins/languages/clang.nix @@ -26,6 +26,8 @@ workspace_required = true; on_attach = mkLuaInline '' function(client, bufnr) + default_on_attach(client, bufnr) + local function switch_source_header(bufnr) local method_name = "textDocument/switchSourceHeader" local params = vim.lsp.util.make_text_document_params(bufnr) @@ -75,6 +77,8 @@ }; on_attach = mkLuaInline '' function(client, bufnr) + default_on_attach(client, bufnr) + local function switch_source_header(bufnr) local method_name = "textDocument/switchSourceHeader" local client = vim.lsp.get_clients({ bufnr = bufnr, name = "clangd", })[1] diff --git a/modules/plugins/languages/csharp.nix b/modules/plugins/languages/csharp.nix index bbfff251..9e13a5ef 100644 --- a/modules/plugins/languages/csharp.nix +++ b/modules/plugins/languages/csharp.nix @@ -63,11 +63,12 @@ }; on_attach = mkLuaInline '' function(client, bufnr) - local oe = require("omnisharp_extended") - ${mkLspBinding "goToDefinition" "oe.lsp_definition"} - ${mkLspBinding "goToType" "oe.lsp_type_definition"} - ${mkLspBinding "listReferences" "oe.lsp_references"} - ${mkLspBinding "listImplementations" "oe.lsp_implementation"} + default_on_attach(client, bufnr) + local oe = require("omnisharp_extended") + ${mkLspBinding "goToDefinition" "oe.lsp_definition"} + ${mkLspBinding "goToType" "oe.lsp_type_definition"} + ${mkLspBinding "listReferences" "oe.lsp_references"} + ${mkLspBinding "listImplementations" "oe.lsp_implementation"} end ''; settings = { diff --git a/modules/plugins/languages/dart.nix b/modules/plugins/languages/dart.nix index ff665e7d..52dcd560 100644 --- a/modules/plugins/languages/dart.nix +++ b/modules/plugins/languages/dart.nix @@ -161,6 +161,7 @@ in { }, capabilities = capabilities, + on_attach = default_on_attach; }, ${optionalString cfg.dap.enable '' debugger = { diff --git a/modules/plugins/languages/haskell.nix b/modules/plugins/languages/haskell.nix index 2b26640a..e73140f4 100644 --- a/modules/plugins/languages/haskell.nix +++ b/modules/plugins/languages/haskell.nix @@ -33,6 +33,7 @@ '' function(client, bufnr) local ht = require("haskell-tools") + default_on_attach(client, bufnr, ht) local opts = { noremap = true, silent = true, buffer = bufnr } vim.keymap.set('n', 'cl', vim.lsp.codelens.run, opts) vim.keymap.set('n', 'hs', ht.hoogle.hoogle_signature, opts) diff --git a/modules/plugins/languages/python.nix b/modules/plugins/languages/python.nix index 1bb7fdd2..8e1f0ebd 100644 --- a/modules/plugins/languages/python.nix +++ b/modules/plugins/languages/python.nix @@ -42,6 +42,7 @@ }; on_attach = mkLuaInline '' function(client, bufnr) + default_on_attach(client, bufnr); vim.api.nvim_buf_create_user_command(bufnr, 'LspPyrightOrganizeImports', function() local params = { command = 'pyright.organizeimports', @@ -88,6 +89,7 @@ }; on_attach = mkLuaInline '' function(client, bufnr) + default_on_attach(client, bufnr); vim.api.nvim_buf_create_user_command(bufnr, 'LspPyrightOrganizeImports', function() local params = { command = 'basedpyright.organizeimports', diff --git a/modules/plugins/languages/rust.nix b/modules/plugins/languages/rust.nix index 3a0a2a9e..09c54ae6 100644 --- a/modules/plugins/languages/rust.nix +++ b/modules/plugins/languages/rust.nix @@ -160,6 +160,7 @@ in { ${cfg.lsp.opts} }, on_attach = function(client, bufnr) + default_on_attach(client, bufnr) local opts = { noremap=true, silent=true, buffer = bufnr } vim.keymap.set("n", "rr", ":RustLsp runnables", opts) vim.keymap.set("n", "rp", ":RustLsp parentModule", opts) diff --git a/modules/plugins/languages/ts.nix b/modules/plugins/languages/ts.nix index 3895c29a..40e598ae 100644 --- a/modules/plugins/languages/ts.nix +++ b/modules/plugins/languages/ts.nix @@ -50,6 +50,8 @@ }; on_attach = mkLuaInline '' function(client, bufnr) + default_on_attach(client, bufnr); + -- ts_ls provides `source.*` code actions that apply to the whole file. These only appear in -- `vim.lsp.buf.code_action()` if specified in `context.only`. vim.api.nvim_buf_create_user_command(0, 'LspTypescriptSourceAction', function() @@ -104,6 +106,7 @@ }; on_attach = mkLuaInline '' function(client, bufnr) + default_on_attach(client, bufnr) vim.api.nvim_buf_create_user_command(0, 'LspDenolsCache', function() client:exec_cmd({ command = 'deno.cache', diff --git a/modules/plugins/languages/yaml.nix b/modules/plugins/languages/yaml.nix index ea9e65d0..b06ef17f 100644 --- a/modules/plugins/languages/yaml.nix +++ b/modules/plugins/languages/yaml.nix @@ -15,18 +15,18 @@ cfg = config.vim.languages.yaml; - on_attach = + on_attach = mkLuaInline ( if config.vim.languages.helm.lsp.enable && config.vim.languages.helm.enable - then - mkLuaInline '' - function(client, bufnr) - local filetype = vim.bo[bufnr].filetype - if filetype == "helm" then - client.stop() - end + then '' + function(client, bufnr) + default_on_attach() + local filetype = vim.bo[bufnr].filetype + if filetype == "helm" then + client.stop() end - '' - else null; + end'' + else "default_on_attach" + ); defaultServers = ["yaml-language-server"]; servers = { diff --git a/modules/plugins/lsp/config.nix b/modules/plugins/lsp/config.nix index 791b72b7..d6875205 100644 --- a/modules/plugins/lsp/config.nix +++ b/modules/plugins/lsp/config.nix @@ -10,8 +10,6 @@ inherit (lib.strings) optionalString; inherit (lib.trivial) boolToString; inherit (lib.nvim.binds) addDescriptionsToMappings; - inherit (lib.nvim.dag) entryBefore; - inherit (lib.nvim.lua) toLuaObject; cfg = config.vim.lsp; usingNvimCmp = config.vim.autocomplete.nvim-cmp.enable; @@ -24,7 +22,7 @@ mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions; mkBinding = binding: action: if binding.value != null - then "vim.keymap.set('n', ${toLuaObject binding.value}, ${action}, {buffer=bufnr, noremap=true, silent=true, desc=${toLuaObject binding.description}})" + then "vim.keymap.set('n', '${binding.value}', ${action}, {buffer=bufnr, noremap=true, silent=true, desc='${binding.description}'})" else ""; in { config = mkIf cfg.enable { @@ -36,26 +34,20 @@ in { augroups = [{name = augroup;}]; autocmds = - [ - { - group = augroup; - event = ["LspAttach"]; - desc = "LSP on-attach add keybinds, enable inlay hints, and other plugin integrations"; - callback = mkLuaInline '' - function(event) - local bufnr = event.buf - local client = vim.lsp.get_client_by_id(event.data.client_id) - default_on_attach(client, bufnr) - - ${optionalString cfg.inlayHints.enable '' - if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint) then - vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = bufnr }), { bufnr = bufnr }) - end - ''} + (optional cfg.inlayHints.enable { + group = augroup; + event = ["LspAttach"]; + desc = "LSP on-attach enable inlay hints autocmd"; + callback = mkLuaInline '' + function(event) + local bufnr = event.buf + local client = vim.lsp.get_client_by_id(event.data.client_id) + if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint) then + vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = bufnr }), { bufnr = bufnr }) end - ''; - } - ] + end + ''; + }) ++ (optional (!conformFormatOnSave) { group = augroup; event = ["BufWritePre"]; @@ -94,7 +86,7 @@ in { ''; }); - pluginRC.lsp-setup = entryBefore ["autocmds"] '' + pluginRC.lsp-setup = '' vim.g.formatsave = ${boolToString cfg.formatOnSave}; local attach_keymaps = function(client, bufnr)