From c488f0490fd290d71c77ae6e4d501a5afb0ddd54 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Tue, 12 Mar 2024 03:46:29 +0300 Subject: [PATCH] modules/lsp: switch to explicit lib calls --- modules/lsp/config.nix | 163 +++++++++--------- modules/lsp/default.nix | 2 +- modules/lsp/lightbulb/config.nix | 19 +- modules/lsp/lightbulb/default.nix | 2 +- modules/lsp/lightbulb/lightbulb.nix | 8 +- modules/lsp/lsp-signature/config.nix | 34 ++-- modules/lsp/lsp-signature/default.nix | 2 +- modules/lsp/lsp-signature/lsp-signature.nix | 10 +- modules/lsp/lspconfig/config.nix | 31 ++-- modules/lsp/lspconfig/default.nix | 2 +- modules/lsp/lspconfig/lspconfig.nix | 12 +- modules/lsp/lspkind/config.nix | 6 +- modules/lsp/lspkind/default.nix | 2 +- modules/lsp/lspkind/lspkind.nix | 14 +- modules/lsp/lsplines/config.nix | 5 +- modules/lsp/lsplines/default.nix | 2 +- modules/lsp/lsplines/lsplines.nix | 6 +- modules/lsp/lspsaga/config.nix | 58 ++++--- modules/lsp/lspsaga/default.nix | 2 +- modules/lsp/lspsaga/lspsaga.nix | 3 +- modules/lsp/module.nix | 3 +- modules/lsp/null-ls/config.nix | 40 +++-- modules/lsp/null-ls/default.nix | 2 +- modules/lsp/null-ls/null-ls.nix | 14 +- modules/lsp/nvim-code-action-menu/config.nix | 35 ++-- modules/lsp/nvim-code-action-menu/default.nix | 2 +- .../nvim-code-action-menu.nix | 3 +- modules/lsp/nvim-docs-view/config.nix | 6 +- modules/lsp/nvim-docs-view/default.nix | 2 +- modules/lsp/nvim-docs-view/nvim-docs-view.nix | 20 ++- modules/lsp/trouble/config.nix | 43 ++--- modules/lsp/trouble/default.nix | 2 +- modules/lsp/trouble/trouble.nix | 3 +- 33 files changed, 285 insertions(+), 273 deletions(-) diff --git a/modules/lsp/config.nix b/modules/lsp/config.nix index 1d44ea7..cabe371 100644 --- a/modules/lsp/config.nix +++ b/modules/lsp/config.nix @@ -15,99 +15,102 @@ mkBinding = binding: action: "vim.api.nvim_buf_set_keymap(bufnr, 'n', '${binding.value}', 'lua ${action}', {noremap=true, silent=true, desc='${binding.description}'})"; in { config = mkIf cfg.enable { - vim.startPlugins = optional usingNvimCmp "cmp-nvim-lsp"; + vim = { + startPlugins = optional usingNvimCmp "cmp-nvim-lsp"; - vim.autocomplete.sources = {"nvim_lsp" = "[LSP]";}; - vim.luaConfigRC.lsp-setup = '' - vim.g.formatsave = ${boolToString cfg.formatOnSave}; + autocomplete.sources = {"nvim_lsp" = "[LSP]";}; - local attach_keymaps = function(client, bufnr) - ${mkBinding mappings.goToDeclaration "vim.lsp.buf.declaration()"} - ${mkBinding mappings.goToDefinition "vim.lsp.buf.definition()"} - ${mkBinding mappings.goToType "vim.lsp.buf.type_definition()"} - ${mkBinding mappings.listImplementations "vim.lsp.buf.implementation()"} - ${mkBinding mappings.listReferences "vim.lsp.buf.references()"} - ${mkBinding mappings.nextDiagnostic "vim.diagnostic.goto_next()"} - ${mkBinding mappings.previousDiagnostic "vim.diagnostic.goto_prev()"} - ${mkBinding mappings.openDiagnosticFloat "vim.diagnostic.open_float()"} - ${mkBinding mappings.documentHighlight "vim.lsp.buf.document_highlight()"} - ${mkBinding mappings.listDocumentSymbols "vim.lsp.buf.document_symbol()"} - ${mkBinding mappings.addWorkspaceFolder "vim.lsp.buf.add_workspace_folder()"} - ${mkBinding mappings.removeWorkspaceFolder "vim.lsp.buf.remove_workspace_folder()"} - ${mkBinding mappings.listWorkspaceFolders "print(vim.inspect(vim.lsp.buf.list_workspace_folders()))"} - ${mkBinding mappings.listWorkspaceSymbols "vim.lsp.buf.workspace_symbol()"} - ${mkBinding mappings.hover "vim.lsp.buf.hover()"} - ${mkBinding mappings.signatureHelp "vim.lsp.buf.signature_help()"} - ${mkBinding mappings.renameSymbol "vim.lsp.buf.rename()"} - ${mkBinding mappings.codeAction "vim.lsp.buf.code_action()"} - ${mkBinding mappings.format "vim.lsp.buf.format()"} - ${mkBinding mappings.toggleFormatOnSave "vim.b.disableFormatSave = not vim.b.disableFormatSave"} - end + luaConfigRC.lsp-setup = '' + vim.g.formatsave = ${boolToString cfg.formatOnSave}; - -- Enable formatting - local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) + local attach_keymaps = function(client, bufnr) + ${mkBinding mappings.goToDeclaration "vim.lsp.buf.declaration()"} + ${mkBinding mappings.goToDefinition "vim.lsp.buf.definition()"} + ${mkBinding mappings.goToType "vim.lsp.buf.type_definition()"} + ${mkBinding mappings.listImplementations "vim.lsp.buf.implementation()"} + ${mkBinding mappings.listReferences "vim.lsp.buf.references()"} + ${mkBinding mappings.nextDiagnostic "vim.diagnostic.goto_next()"} + ${mkBinding mappings.previousDiagnostic "vim.diagnostic.goto_prev()"} + ${mkBinding mappings.openDiagnosticFloat "vim.diagnostic.open_float()"} + ${mkBinding mappings.documentHighlight "vim.lsp.buf.document_highlight()"} + ${mkBinding mappings.listDocumentSymbols "vim.lsp.buf.document_symbol()"} + ${mkBinding mappings.addWorkspaceFolder "vim.lsp.buf.add_workspace_folder()"} + ${mkBinding mappings.removeWorkspaceFolder "vim.lsp.buf.remove_workspace_folder()"} + ${mkBinding mappings.listWorkspaceFolders "print(vim.inspect(vim.lsp.buf.list_workspace_folders()))"} + ${mkBinding mappings.listWorkspaceSymbols "vim.lsp.buf.workspace_symbol()"} + ${mkBinding mappings.hover "vim.lsp.buf.hover()"} + ${mkBinding mappings.signatureHelp "vim.lsp.buf.signature_help()"} + ${mkBinding mappings.renameSymbol "vim.lsp.buf.rename()"} + ${mkBinding mappings.codeAction "vim.lsp.buf.code_action()"} + ${mkBinding mappings.format "vim.lsp.buf.format()"} + ${mkBinding mappings.toggleFormatOnSave "vim.b.disableFormatSave = not vim.b.disableFormatSave"} + end - format_callback = function(client, bufnr) - if vim.g.formatsave then - vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) - vim.api.nvim_create_autocmd("BufWritePre", { - group = augroup, - buffer = bufnr, - callback = function() - ${ - if config.vim.lsp.null-ls.enable - then '' - if vim.b.disableFormatSave then - return - end + -- Enable formatting + local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) - local function is_null_ls_formatting_enabled(bufnr) - local file_type = vim.api.nvim_buf_get_option(bufnr, "filetype") - local generators = require("null-ls.generators").get_available( - file_type, - require("null-ls.methods").internal.FORMATTING - ) - return #generators > 0 - end + format_callback = function(client, bufnr) + if vim.g.formatsave then + vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) + vim.api.nvim_create_autocmd("BufWritePre", { + group = augroup, + buffer = bufnr, + callback = function() + ${ + if config.vim.lsp.null-ls.enable + then '' + if vim.b.disableFormatSave then + return + end - if is_null_ls_formatting_enabled(bufnr) then - vim.lsp.buf.format({ - bufnr = bufnr, - filter = function(client) - return client.name == "null-ls" - end - }) - else - vim.lsp.buf.format({ - bufnr = bufnr, - }) - end - '' - else " + local function is_null_ls_formatting_enabled(bufnr) + local file_type = vim.api.nvim_buf_get_option(bufnr, "filetype") + local generators = require("null-ls.generators").get_available( + file_type, + require("null-ls.methods").internal.FORMATTING + ) + return #generators > 0 + end + + if is_null_ls_formatting_enabled(bufnr) then + vim.lsp.buf.format({ + bufnr = bufnr, + filter = function(client) + return client.name == "null-ls" + end + }) + else + vim.lsp.buf.format({ + bufnr = bufnr, + }) + end + '' + else " vim.lsp.buf.format({ bufnr = bufnr, }) " - } - end, - }) + } + end, + }) + end end - end - ${optionalString (config.vim.ui.breadcrumbs.enable) ''local navic = require("nvim-navic")''} - default_on_attach = function(client, bufnr) - attach_keymaps(client, bufnr) - format_callback(client, bufnr) - ${optionalString (config.vim.ui.breadcrumbs.enable) '' - -- let navic attach to buffers - if client.server_capabilities.documentSymbolProvider then - navic.attach(client, bufnr) + ${optionalString (config.vim.ui.breadcrumbs.enable) ''local navic = require("nvim-navic")''} + default_on_attach = function(client, bufnr) + attach_keymaps(client, bufnr) + format_callback(client, bufnr) + ${optionalString (config.vim.ui.breadcrumbs.enable) '' + -- let navic attach to buffers + if client.server_capabilities.documentSymbolProvider then + navic.attach(client, bufnr) + end + ''} end - ''} - end - local capabilities = vim.lsp.protocol.make_client_capabilities() - ${optionalString usingNvimCmp "capabilities = require('cmp_nvim_lsp').default_capabilities()"} - ''; + local capabilities = vim.lsp.protocol.make_client_capabilities() + ${optionalString usingNvimCmp "capabilities = require('cmp_nvim_lsp').default_capabilities()"} + ''; + }; }; } diff --git a/modules/lsp/default.nix b/modules/lsp/default.nix index 9a70efc..f8408aa 100644 --- a/modules/lsp/default.nix +++ b/modules/lsp/default.nix @@ -1,4 +1,4 @@ -_: { +{ imports = [ # nvim lsp support ./config.nix diff --git a/modules/lsp/lightbulb/config.nix b/modules/lsp/lightbulb/config.nix index 3a13f68..ef2239f 100644 --- a/modules/lsp/lightbulb/config.nix +++ b/modules/lsp/lightbulb/config.nix @@ -3,20 +3,21 @@ lib, ... }: let - inherit (lib) mkIf nvim; + inherit (lib.modules) mkIf; + inherit (lib.nvim.dag) entryAnywhere; cfg = config.vim.lsp; in { config = mkIf (cfg.enable && cfg.lightbulb.enable) { - vim.startPlugins = ["nvim-lightbulb"]; + vim = { + startPlugins = ["nvim-lightbulb"]; - vim.configRC.lightbulb = nvim.dag.entryAnywhere '' - autocmd CursorHold,CursorHoldI * lua require'nvim-lightbulb'.update_lightbulb() - ''; + luaConfigRC.lightbulb = entryAnywhere '' + vim.api.nvim_command('autocmd CursorHold,CursorHoldI * lua require\'nvim-lightbulb\'.update_lightbulb()') - vim.luaConfigRC.lightbulb = nvim.dag.entryAnywhere '' - -- Enable trouble diagnostics viewer - require'nvim-lightbulb'.setup() - ''; + -- Enable trouble diagnostics viewer + require'nvim-lightbulb'.setup() + ''; + }; }; } diff --git a/modules/lsp/lightbulb/default.nix b/modules/lsp/lightbulb/default.nix index 883944a..3e6e8a3 100644 --- a/modules/lsp/lightbulb/default.nix +++ b/modules/lsp/lightbulb/default.nix @@ -1,4 +1,4 @@ -_: { +{ imports = [ ./lightbulb.nix ./config.nix diff --git a/modules/lsp/lightbulb/lightbulb.nix b/modules/lsp/lightbulb/lightbulb.nix index 44d0ce0..ef101a0 100644 --- a/modules/lsp/lightbulb/lightbulb.nix +++ b/modules/lsp/lightbulb/lightbulb.nix @@ -1,9 +1,5 @@ -{ - config, - lib, - ... -}: let - inherit (lib) mkEnableOption; +{lib, ...}: let + inherit (lib.options) mkEnableOption; in { options.vim.lsp = { lightbulb = { diff --git a/modules/lsp/lsp-signature/config.nix b/modules/lsp/lsp-signature/config.nix index 18ac5d1..5b231bd 100644 --- a/modules/lsp/lsp-signature/config.nix +++ b/modules/lsp/lsp-signature/config.nix @@ -3,25 +3,29 @@ lib, ... }: let - inherit (lib) mkIf nvim optionalString; + inherit (lib.modules) mkIf; + inherit (lib.nvim.dag) entryAnywhere; + inherit (lib.strings) optionalString; cfg = config.vim.lsp; in { config = mkIf (cfg.enable && cfg.lspSignature.enable) { - vim.startPlugins = [ - "lsp-signature" - ]; + vim = { + startPlugins = [ + "lsp-signature" + ]; - vim.luaConfigRC.lsp-signature = nvim.dag.entryAnywhere '' - -- Enable lsp signature viewer - require("lsp_signature").setup({ - ${optionalString (config.vim.ui.borders.plugins.lsp-signature.enable) '' - bind = true, -- This is mandatory, otherwise border config won't get registered. - handler_opts = { - border = "${config.vim.ui.borders.plugins.lsp-signature.style}" - } - ''} - }) - ''; + luaConfigRC.lsp-signature = entryAnywhere '' + -- Enable lsp signature viewer + require("lsp_signature").setup({ + ${optionalString config.vim.ui.borders.plugins.lsp-signature.enable '' + bind = true, -- This is mandatory, otherwise border config won't get registered. + handler_opts = { + border = "${config.vim.ui.borders.plugins.lsp-signature.style}" + } + ''} + }) + ''; + }; }; } diff --git a/modules/lsp/lsp-signature/default.nix b/modules/lsp/lsp-signature/default.nix index 0449a9e..d88ec99 100644 --- a/modules/lsp/lsp-signature/default.nix +++ b/modules/lsp/lsp-signature/default.nix @@ -1,4 +1,4 @@ -_: { +{ imports = [ ./lsp-signature.nix ./config.nix diff --git a/modules/lsp/lsp-signature/lsp-signature.nix b/modules/lsp/lsp-signature/lsp-signature.nix index d05161e..981526b 100644 --- a/modules/lsp/lsp-signature/lsp-signature.nix +++ b/modules/lsp/lsp-signature/lsp-signature.nix @@ -1,13 +1,9 @@ -{ - config, - lib, - ... -}: let - inherit (lib) mkEnableOption; +{lib, ...}: let + inherit (lib.options) mkEnableOption; in { options.vim.lsp = { lspSignature = { - enable = mkEnableOption "lsp signature viewer"; + enable = mkEnableOption "lsp signature viewer [lsp-signature]"; }; }; } diff --git a/modules/lsp/lspconfig/config.nix b/modules/lsp/lspconfig/config.nix index 527bbed..1736ce9 100644 --- a/modules/lsp/lspconfig/config.nix +++ b/modules/lsp/lspconfig/config.nix @@ -1,32 +1,35 @@ { - pkgs, config, lib, ... }: let - inherit (lib) mkIf mkMerge nvim optionalString mapAttrs; + inherit (lib.modules) mkIf mkMerge; + inherit (lib.strings) optionalString; + inherit (lib.attrsets) mapAttrs; + inherit (lib.nvim.dag) entryAfter; cfg = config.vim.lsp; in { config = mkIf cfg.lspconfig.enable (mkMerge [ { - vim.lsp.enable = true; + vim = { + lsp.enable = true; - vim.startPlugins = ["nvim-lspconfig"]; + startPlugins = ["nvim-lspconfig"]; - vim.luaConfigRC.lspconfig = nvim.dag.entryAfter ["lsp-setup"] '' - local lspconfig = require('lspconfig') + luaConfigRC.lspconfig = entryAfter ["lsp-setup"] '' + local lspconfig = require('lspconfig') - ${ - # TODO: make border style configurable - optionalString (config.vim.ui.borders.enable) '' - require('lspconfig.ui.windows').default_options.border = '${config.vim.ui.borders.globalStyle}' - '' - } - ''; + ${ + optionalString config.vim.ui.borders.enable '' + require('lspconfig.ui.windows').default_options.border = '${config.vim.ui.borders.globalStyle}' + '' + } + ''; + }; } { - vim.luaConfigRC = mapAttrs (_: v: (nvim.dag.entryAfter ["lspconfig"] v)) cfg.lspconfig.sources; + vim.luaConfigRC = mapAttrs (_: v: (entryAfter ["lspconfig"] v)) cfg.lspconfig.sources; } ]); } diff --git a/modules/lsp/lspconfig/default.nix b/modules/lsp/lspconfig/default.nix index 117e4d4..e6e6c18 100644 --- a/modules/lsp/lspconfig/default.nix +++ b/modules/lsp/lspconfig/default.nix @@ -1,4 +1,4 @@ -_: { +{ imports = [ ./config.nix ./lspconfig.nix diff --git a/modules/lsp/lspconfig/lspconfig.nix b/modules/lsp/lspconfig/lspconfig.nix index 7dd8ff0..2f7c7ac 100644 --- a/modules/lsp/lspconfig/lspconfig.nix +++ b/modules/lsp/lspconfig/lspconfig.nix @@ -1,17 +1,13 @@ -{ - pkgs, - config, - lib, - ... -}: let - inherit (lib) mkEnableOption mkOption types; +{lib, ...}: let + inherit (lib.options) mkEnableOption mkOption; + inherit (lib.types) attrsOf str; in { options.vim.lsp.lspconfig = { enable = mkEnableOption "nvim-lspconfig, also enabled automatically"; sources = mkOption { description = "nvim-lspconfig sources"; - type = with types; attrsOf str; + type = attrsOf str; default = {}; }; }; diff --git a/modules/lsp/lspkind/config.nix b/modules/lsp/lspkind/config.nix index 2c21c26..a98aeab 100644 --- a/modules/lsp/lspkind/config.nix +++ b/modules/lsp/lspkind/config.nix @@ -1,16 +1,16 @@ { - pkgs, config, lib, ... }: let - inherit (lib) mkIf nvim; + inherit (lib.modules) mkIf; + inherit (lib.nvim.dag) entryAnywhere; cfg = config.vim.lsp; in { config = mkIf (cfg.enable && cfg.lspkind.enable) { vim.startPlugins = ["lspkind"]; - vim.luaConfigRC.lspkind = nvim.dag.entryAnywhere '' + vim.luaConfigRC.lspkind = entryAnywhere '' local lspkind = require'lspkind' local lspkind_opts = { mode = '${cfg.lspkind.mode}' diff --git a/modules/lsp/lspkind/default.nix b/modules/lsp/lspkind/default.nix index 81f7418..fbfa506 100644 --- a/modules/lsp/lspkind/default.nix +++ b/modules/lsp/lspkind/default.nix @@ -1,4 +1,4 @@ -_: { +{ imports = [ ./config.nix ./lspkind.nix diff --git a/modules/lsp/lspkind/lspkind.nix b/modules/lsp/lspkind/lspkind.nix index 4856688..8ae9f39 100644 --- a/modules/lsp/lspkind/lspkind.nix +++ b/modules/lsp/lspkind/lspkind.nix @@ -1,12 +1,6 @@ -{ - pkgs, - config, - lib, - ... -}: let - inherit (lib) mkEnableOption mkOption types; - - cfg = config.vim.lsp; +{lib, ...}: let + inherit (lib.options) mkEnableOption mkOption; + inherit (lib.types) enum; in { options.vim.lsp = { lspkind = { @@ -14,7 +8,7 @@ in { mode = mkOption { description = "Defines how annotations are shown"; - type = with types; enum ["text" "text_symbol" "symbol_text" "symbol"]; + type = enum ["text" "text_symbol" "symbol_text" "symbol"]; default = "symbol_text"; }; }; diff --git a/modules/lsp/lsplines/config.nix b/modules/lsp/lsplines/config.nix index 66eb5ff..3436f64 100644 --- a/modules/lsp/lsplines/config.nix +++ b/modules/lsp/lsplines/config.nix @@ -3,13 +3,14 @@ lib, ... }: let - inherit (lib) mkIf nvim; + inherit (lib.modules) mkIf; + inherit (lib.nvim.dag) entryAfter; cfg = config.vim.lsp; in { config = mkIf (cfg.enable && cfg.lsplines.enable) { vim.startPlugins = ["lsp-lines"]; - vim.luaConfigRC.lsplines = nvim.dag.entryAfter ["lspconfig"] '' + vim.luaConfigRC.lsplines = entryAfter ["lspconfig"] '' require("lsp_lines").setup() vim.diagnostic.config({ diff --git a/modules/lsp/lsplines/default.nix b/modules/lsp/lsplines/default.nix index fa50897..359cec4 100644 --- a/modules/lsp/lsplines/default.nix +++ b/modules/lsp/lsplines/default.nix @@ -1,4 +1,4 @@ -_: { +{ imports = [ ./config.nix ./lsplines.nix diff --git a/modules/lsp/lsplines/lsplines.nix b/modules/lsp/lsplines/lsplines.nix index 9b5f6a6..aac4cbb 100644 --- a/modules/lsp/lsplines/lsplines.nix +++ b/modules/lsp/lsplines/lsplines.nix @@ -1,9 +1,11 @@ {lib, ...}: let - inherit (lib) mkEnableOption; + inherit (lib.options) mkEnableOption; in { options.vim.lsp = { lsplines = { - enable = mkEnableOption "diagnostics using virtual lines on top of the real line of code. [lsp_lines]"; + enable = mkEnableOption '' + diagnostics using virtual lines on top of the real line of code. [lsp_lines] + ''; }; }; } diff --git a/modules/lsp/lspsaga/config.nix b/modules/lsp/lspsaga/config.nix index 722bdde..ffacf12 100644 --- a/modules/lsp/lspsaga/config.nix +++ b/modules/lsp/lspsaga/config.nix @@ -3,7 +3,10 @@ lib, ... }: let - inherit (lib) addDescriptionsToMappings mkIf mkSetLuaBinding mkMerge nvim optionalString; + inherit (lib.modules) mkIf mkMerge; + inherit (lib.strings) optionalString; + inherit (lib.nvim.dag) entryAnywhere; + inherit (lib.nvim.binds) addDescriptionsToMappings mkSetLuaBinding; cfg = config.vim.lsp; self = import ./lspsaga.nix {inherit lib;}; @@ -12,38 +15,39 @@ mappings = addDescriptionsToMappings cfg.lspsaga.mappings mappingDefinitions; in { config = mkIf (cfg.enable && cfg.lspsaga.enable) { - vim.startPlugins = ["lspsaga"]; + vim = { + startPlugins = ["lspsaga"]; - vim.maps.visual = mkSetLuaBinding mappings.codeAction "require('lspsaga.codeaction').range_code_action"; + maps = { + visual = mkSetLuaBinding mappings.codeAction "require('lspsaga.codeaction').range_code_action"; + normal = mkMerge [ + (mkSetLuaBinding mappings.lspFinder "require('lspsaga.provider').lsp_finder") + (mkSetLuaBinding mappings.renderHoveredDoc "require('lspsaga.hover').render_hover_doc") - vim.maps.normal = mkMerge [ - (mkSetLuaBinding mappings.lspFinder "require('lspsaga.provider').lsp_finder") - (mkSetLuaBinding mappings.renderHoveredDoc "require('lspsaga.hover').render_hover_doc") + (mkSetLuaBinding mappings.smartScrollUp "function() require('lspsaga.action').smart_scroll_with_saga(-1) end") + (mkSetLuaBinding mappings.smartScrollDown "function() require('lspsaga.action').smart_scroll_with_saga(1) end") - (mkSetLuaBinding mappings.smartScrollUp "function() require('lspsaga.action').smart_scroll_with_saga(-1) end") - (mkSetLuaBinding mappings.smartScrollDown "function() require('lspsaga.action').smart_scroll_with_saga(1) end") + (mkSetLuaBinding mappings.rename "require('lspsaga.rename').rename") + (mkSetLuaBinding mappings.previewDefinition "require('lspsaga.provider').preview_definition") - (mkSetLuaBinding mappings.rename "require('lspsaga.rename').rename") - (mkSetLuaBinding mappings.previewDefinition "require('lspsaga.provider').preview_definition") + (mkSetLuaBinding mappings.showLineDiagnostics "require('lspsaga.diagnostic').show_line_diagnostics") + (mkSetLuaBinding mappings.showCursorDiagnostics "require('lspsaga.diagnostic').show_cursor_diagnostics") - (mkSetLuaBinding mappings.showLineDiagnostics "require('lspsaga.diagnostic').show_line_diagnostics") - (mkSetLuaBinding mappings.showCursorDiagnostics "require('lspsaga.diagnostic').show_cursor_diagnostics") + (mkSetLuaBinding mappings.nextDiagnostic "require('lspsaga.diagnostic').navigate('next')") + (mkSetLuaBinding mappings.previousDiagnostic "require('lspsaga.diagnostic').navigate('prev')") - (mkSetLuaBinding mappings.nextDiagnostic "require('lspsaga.diagnostic').navigate('next')") - (mkSetLuaBinding mappings.previousDiagnostic "require('lspsaga.diagnostic').navigate('prev')") + (mkIf (!cfg.nvimCodeActionMenu.enable) (mkSetLuaBinding mappings.codeAction "require('lspsaga.codeaction').code_action")) + (mkIf (!cfg.lspSignature.enable) (mkSetLuaBinding mappings.signatureHelp "require('lspsaga.signaturehelp').signature_help")) + ]; + }; - (mkIf (!cfg.nvimCodeActionMenu.enable) (mkSetLuaBinding mappings.codeAction "require('lspsaga.codeaction').code_action")) - (mkIf (!cfg.lspSignature.enable) (mkSetLuaBinding mappings.signatureHelp "require('lspsaga.signaturehelp').signature_help")) - ]; - - vim.luaConfigRC.lspsage = nvim.dag.entryAnywhere '' - -- Enable lspsaga - local saga = require 'lspsaga' - saga.init_lsp_saga({ - ${optionalString (config.vim.ui.borders.plugins.lspsaga.enable) '' - border_style = '${config.vim.ui.borders.plugins.lspsaga.style}', - ''} - }) - ''; + luaConfigRC.lspsaga = entryAnywhere '' + require('lspsaga').init_lsp_saga({ + ${optionalString config.vim.ui.borders.plugins.lspsaga.enable '' + border_style = '${config.vim.ui.borders.plugins.lspsaga.style}', + ''} + }) + ''; + }; }; } diff --git a/modules/lsp/lspsaga/default.nix b/modules/lsp/lspsaga/default.nix index 29cf580..82c2ed7 100644 --- a/modules/lsp/lspsaga/default.nix +++ b/modules/lsp/lspsaga/default.nix @@ -1,4 +1,4 @@ -_: { +{ imports = [ ./lspsaga.nix ./config.nix diff --git a/modules/lsp/lspsaga/lspsaga.nix b/modules/lsp/lspsaga/lspsaga.nix index 35e1ecc..f308aaa 100644 --- a/modules/lsp/lspsaga/lspsaga.nix +++ b/modules/lsp/lspsaga/lspsaga.nix @@ -1,5 +1,6 @@ {lib, ...}: let - inherit (lib) mkEnableOption mkMappingOption; + inherit (lib.options) mkEnableOption; + inherit (lib.nvim.binds) mkMappingOption; in { options.vim.lsp.lspsaga = { enable = mkEnableOption "LSP Saga"; diff --git a/modules/lsp/module.nix b/modules/lsp/module.nix index 1a56240..b16f9c1 100644 --- a/modules/lsp/module.nix +++ b/modules/lsp/module.nix @@ -1,5 +1,6 @@ {lib, ...}: let - inherit (lib) mkEnableOption mkMappingOption; + inherit (lib.options) mkEnableOption; + inherit (lib.nvim.binds) mkMappingOption; in { options.vim.lsp = { enable = mkEnableOption "LSP, also enabled automatically through null-ls and lspconfig options"; diff --git a/modules/lsp/null-ls/config.nix b/modules/lsp/null-ls/config.nix index 23a6818..f161fb9 100644 --- a/modules/lsp/null-ls/config.nix +++ b/modules/lsp/null-ls/config.nix @@ -1,5 +1,4 @@ { - pkgs, config, lib, ... @@ -10,25 +9,28 @@ in { config = mkIf cfg.null-ls.enable (mkMerge [ { - vim.lsp.enable = true; - vim.startPlugins = ["none-ls"]; + vim = { + lsp.enable = true; + startPlugins = ["none-ls"]; - vim.luaConfigRC.null_ls-setup = nvim.dag.entryAnywhere '' - local null_ls = require("null-ls") - local null_helpers = require("null-ls.helpers") - local null_methods = require("null-ls.methods") - local ls_sources = {} - ''; - vim.luaConfigRC.null_ls = nvim.dag.entryAfter ["null_ls-setup" "lsp-setup"] '' - require('null-ls').setup({ - debug = false, - diagnostics_format = "[#{m}] #{s} (#{c})", - debounce = 250, - default_timeout = 5000, - sources = ls_sources, - on_attach=default_on_attach - }) - ''; + luaConfigRC.null_ls-setup = nvim.dag.entryAnywhere '' + local null_ls = require("null-ls") + local null_helpers = require("null-ls.helpers") + local null_methods = require("null-ls.methods") + local ls_sources = {} + ''; + + luaConfigRC.null_ls = nvim.dag.entryAfter ["null_ls-setup" "lsp-setup"] '' + require('null-ls').setup({ + debug = false, + diagnostics_format = "[#{m}] #{s} (#{c})", + debounce = 250, + default_timeout = 5000, + sources = ls_sources, + on_attach = default_on_attach + }) + ''; + }; } { vim.luaConfigRC = mapAttrs (_: v: (nvim.dag.entryBetween ["null_ls"] ["null_ls-setup"] v)) cfg.null-ls.sources; diff --git a/modules/lsp/null-ls/default.nix b/modules/lsp/null-ls/default.nix index 01e6e59..d104e68 100644 --- a/modules/lsp/null-ls/default.nix +++ b/modules/lsp/null-ls/default.nix @@ -1,4 +1,4 @@ -_: { +{ imports = [ ./config.nix ./null-ls.nix diff --git a/modules/lsp/null-ls/null-ls.nix b/modules/lsp/null-ls/null-ls.nix index 3ffb0ca..8c63df2 100644 --- a/modules/lsp/null-ls/null-ls.nix +++ b/modules/lsp/null-ls/null-ls.nix @@ -1,19 +1,13 @@ -{ - pkgs, - config, - lib, - ... -}: let - inherit (lib) mkEnableOption mkOption types; - - cfg = config.vim.lsp; +{lib, ...}: let + inherit (lib.options) mkEnableOption mkOption; + inherit (lib.types) attrsOf str; in { options.vim.lsp.null-ls = { enable = mkEnableOption "null-ls, also enabled automatically"; sources = mkOption { description = "null-ls sources"; - type = with types; attrsOf str; + type = attrsOf str; default = {}; }; }; diff --git a/modules/lsp/nvim-code-action-menu/config.nix b/modules/lsp/nvim-code-action-menu/config.nix index 9f8f604..e55fb4a 100644 --- a/modules/lsp/nvim-code-action-menu/config.nix +++ b/modules/lsp/nvim-code-action-menu/config.nix @@ -3,32 +3,35 @@ lib, ... }: let - inherit (lib) addDescriptionsToMappings mkIf mkSetBinding nvim pushDownDefault; + inherit (lib.modules) mkIf; + inherit (lib.nvim.dag) entryAnywhere; + inherit (lib.nvim.binds) mkSetBinding addDescriptionsToMappings pushDownDefault; cfg = config.vim.lsp; self = import ./nvim-code-action-menu.nix {inherit lib;}; - mappingDefinitions = self.options.vim.lsp.nvimCodeActionMenu.mappings; mappings = addDescriptionsToMappings cfg.nvimCodeActionMenu.mappings mappingDefinitions; in { config = mkIf (cfg.enable && cfg.nvimCodeActionMenu.enable) { - vim.startPlugins = ["nvim-code-action-menu"]; + vim = { + startPlugins = ["nvim-code-action-menu"]; - vim.maps.normal = mkSetBinding mappings.open ":CodeActionMenu"; + maps.normal = mkSetBinding mappings.open ":CodeActionMenu"; - vim.binds.whichKey.register = pushDownDefault { - "c" = "+CodeAction"; + binds.whichKey.register = pushDownDefault { + "c" = "+CodeAction"; + }; + + luaConfigRC.code-action-menu = entryAnywhere '' + -- border configuration + vim.g.code_action_menu_window_border = '${config.vim.ui.borders.plugins.code-action-menu.style}' + + -- show individual sections of the code action menu + ${lib.optionalString cfg.nvimCodeActionMenu.show.details "vim.g.code_action_menu_show_details = true"} + ${lib.optionalString cfg.nvimCodeActionMenu.show.diff "vim.g.code_action_menu_show_diff = true"} + ${lib.optionalString cfg.nvimCodeActionMenu.show.actionKind "vim.g.code_action_menu_show_action_kind = true"} + ''; }; - - vim.luaConfigRC.code-action-menu = nvim.dag.entryAnywhere '' - -- border configuration - vim.g.code_action_menu_window_border = '${config.vim.ui.borders.plugins.code-action-menu.style}' - - -- show individual sections of the code action menu - ${lib.optionalString (cfg.nvimCodeActionMenu.show.details) "vim.g.code_action_menu_show_details = true"} - ${lib.optionalString (cfg.nvimCodeActionMenu.show.diff) "vim.g.code_action_menu_show_diff = true"} - ${lib.optionalString (cfg.nvimCodeActionMenu.show.actionKind) "vim.g.code_action_menu_show_action_kind = true"} - ''; }; } diff --git a/modules/lsp/nvim-code-action-menu/default.nix b/modules/lsp/nvim-code-action-menu/default.nix index 665cf92..f94dd22 100644 --- a/modules/lsp/nvim-code-action-menu/default.nix +++ b/modules/lsp/nvim-code-action-menu/default.nix @@ -1,4 +1,4 @@ -_: { +{ imports = [ ./nvim-code-action-menu.nix ./config.nix diff --git a/modules/lsp/nvim-code-action-menu/nvim-code-action-menu.nix b/modules/lsp/nvim-code-action-menu/nvim-code-action-menu.nix index c04beda..c303f7c 100644 --- a/modules/lsp/nvim-code-action-menu/nvim-code-action-menu.nix +++ b/modules/lsp/nvim-code-action-menu/nvim-code-action-menu.nix @@ -1,5 +1,6 @@ {lib, ...}: let - inherit (lib) mkEnableOption mkMappingOption; + inherit (lib.options) mkEnableOption; + inherit (lib.nvim.binds) mkMappingOption; in { options.vim.lsp = { nvimCodeActionMenu = { diff --git a/modules/lsp/nvim-docs-view/config.nix b/modules/lsp/nvim-docs-view/config.nix index d7dc837..008eee8 100644 --- a/modules/lsp/nvim-docs-view/config.nix +++ b/modules/lsp/nvim-docs-view/config.nix @@ -3,8 +3,10 @@ lib, ... }: let - inherit (lib) mkIf nvim addDescriptionsToMappings mkSetBinding mkMerge; inherit (builtins) toString; + inherit (lib.modules) mkIf mkMerge; + inherit (lib.nvim.dag) entryAnywhere; + inherit (lib.nvim.binds) addDescriptionsToMappings mkSetBinding; cfg = config.vim.lsp.nvim-docs-view; self = import ./nvim-docs-view.nix {inherit lib;}; @@ -17,7 +19,7 @@ in { lsp.enable = true; startPlugins = ["nvim-docs-view"]; - luaConfigRC.nvim-docs-view = nvim.dag.entryAnywhere '' + luaConfigRC.nvim-docs-view = entryAnywhere '' require("docs-view").setup { position = "${cfg.position}", width = ${toString cfg.width}, diff --git a/modules/lsp/nvim-docs-view/default.nix b/modules/lsp/nvim-docs-view/default.nix index 499ec39..48716d0 100644 --- a/modules/lsp/nvim-docs-view/default.nix +++ b/modules/lsp/nvim-docs-view/default.nix @@ -1,4 +1,4 @@ -_: { +{ imports = [ ./config.nix ./nvim-docs-view.nix diff --git a/modules/lsp/nvim-docs-view/nvim-docs-view.nix b/modules/lsp/nvim-docs-view/nvim-docs-view.nix index 808613e..6b59a27 100644 --- a/modules/lsp/nvim-docs-view/nvim-docs-view.nix +++ b/modules/lsp/nvim-docs-view/nvim-docs-view.nix @@ -1,11 +1,13 @@ {lib, ...}: let - inherit (lib) mkEnableOption mkOption types mkMappingOption; + inherit (lib.options) mkEnableOption mkOption; + inherit (lib.types) enum int; + inherit (lib.nvim.binds) mkMappingOption; in { options.vim.lsp.nvim-docs-view = { enable = mkEnableOption "nvim-docs-view, for displaying lsp hover documentation in a side panel."; position = mkOption { - type = types.enum ["left" "right" "top" "bottom"]; + type = enum ["left" "right" "top" "bottom"]; default = "right"; description = '' Where to open the docs view panel @@ -13,7 +15,7 @@ in { }; height = mkOption { - type = types.int; + type = int; default = 10; description = '' Height of the docs view panel if the position is set to either top or bottom @@ -21,7 +23,7 @@ in { }; width = mkOption { - type = types.int; + type = int; default = 60; description = '' Width of the docs view panel if the position is set to either left or right @@ -29,12 +31,14 @@ in { }; updateMode = mkOption { - type = types.enum ["auto" "manual"]; + type = enum ["auto" "manual"]; default = "auto"; description = '' - Determines the mechanism used to update the docs view panel content. - - If auto, the content will update upon cursor move. - - If manual, the content will only update once :DocsViewUpdate is called + Determines the mechanism used to update the docs view panel content + + Possible values: + - auto: the content will update upon cursor move. + - manual: the content will only update once :DocsViewUpdate is called ''; }; diff --git a/modules/lsp/trouble/config.nix b/modules/lsp/trouble/config.nix index bb751c7..72fc1ec 100644 --- a/modules/lsp/trouble/config.nix +++ b/modules/lsp/trouble/config.nix @@ -3,36 +3,39 @@ lib, ... }: let - inherit (lib) addDescriptionsToMappings mkIf mkMerge mkSetBinding nvim pushDownDefault; + inherit (lib.modules) mkIf mkMerge; + inherit (lib.nvim.dag) entryAnywhere; + inherit (lib.nvim.binds) addDescriptionsToMappings mkSetBinding pushDownDefault; cfg = config.vim.lsp; self = import ./trouble.nix {inherit lib;}; - mappingDefinitions = self.options.vim.lsp.trouble.mappings; mappings = addDescriptionsToMappings cfg.trouble.mappings mappingDefinitions; in { config = mkIf (cfg.enable && cfg.trouble.enable) { - vim.startPlugins = ["trouble"]; + vim = { + startPlugins = ["trouble"]; - vim.maps.normal = mkMerge [ - (mkSetBinding mappings.toggle "TroubleToggle") - (mkSetBinding mappings.workspaceDiagnostics "TroubleToggle workspace_diagnostics") - (mkSetBinding mappings.documentDiagnostics "TroubleToggle document_diagnostics") - (mkSetBinding mappings.lspReferences "TroubleToggle lsp_references") - (mkSetBinding mappings.quickfix "TroubleToggle quickfix") - (mkSetBinding mappings.locList "TroubleToggle loclist") - ]; + maps.normal = mkMerge [ + (mkSetBinding mappings.toggle "TroubleToggle") + (mkSetBinding mappings.workspaceDiagnostics "TroubleToggle workspace_diagnostics") + (mkSetBinding mappings.documentDiagnostics "TroubleToggle document_diagnostics") + (mkSetBinding mappings.lspReferences "TroubleToggle lsp_references") + (mkSetBinding mappings.quickfix "TroubleToggle quickfix") + (mkSetBinding mappings.locList "TroubleToggle loclist") + ]; - vim.binds.whichKey.register = pushDownDefault { - "l" = "Trouble"; - "x" = "+Trouble"; - "lw" = "Workspace"; + binds.whichKey.register = pushDownDefault { + "l" = "Trouble"; + "x" = "+Trouble"; + "lw" = "Workspace"; + }; + + luaConfigRC.trouble = entryAnywhere '' + -- Enable trouble diagnostics viewer + require("trouble").setup {} + ''; }; - - vim.luaConfigRC.trouble = nvim.dag.entryAnywhere '' - -- Enable trouble diagnostics viewer - require("trouble").setup {} - ''; }; } diff --git a/modules/lsp/trouble/default.nix b/modules/lsp/trouble/default.nix index 3a5d2cb..77e9337 100644 --- a/modules/lsp/trouble/default.nix +++ b/modules/lsp/trouble/default.nix @@ -1,4 +1,4 @@ -_: { +{ imports = [ ./trouble.nix ./config.nix diff --git a/modules/lsp/trouble/trouble.nix b/modules/lsp/trouble/trouble.nix index b8aa0de..bd16c67 100644 --- a/modules/lsp/trouble/trouble.nix +++ b/modules/lsp/trouble/trouble.nix @@ -1,5 +1,6 @@ {lib, ...}: let - inherit (lib) mkEnableOption mkMappingOption; + inherit (lib.options) mkEnableOption; + inherit (lib.nvim.binds) mkMappingOption; in { options.vim.lsp = { trouble = {