From cd98cc29f177e16bcc019a2b84e5cea1fa49945c Mon Sep 17 00:00:00 2001 From: n3oney Date: Sat, 22 Apr 2023 19:42:31 +0200 Subject: [PATCH] feat: add lspsaga keybindings --- modules/lsp/lspsaga/config.nix | 54 ++++++++++++-------------- modules/lsp/lspsaga/lspsaga.nix | 69 +++++++++++---------------------- 2 files changed, 46 insertions(+), 77 deletions(-) diff --git a/modules/lsp/lspsaga/config.nix b/modules/lsp/lspsaga/config.nix index e8c71fa..3b7ea26 100644 --- a/modules/lsp/lspsaga/config.nix +++ b/modules/lsp/lspsaga/config.nix @@ -6,41 +6,35 @@ with lib; with builtins; let cfg = config.vim.lsp; + self = import ./lspsaga.nix {inherit lib;}; + + mappingDefinitions = self.options.vim.lsp.lspsaga.mappings; + mappings = addDescriptionsToMappings cfg.lspsaga.mappings mappingDefinitions; in { config = mkIf (cfg.enable && cfg.lspsaga.enable) { vim.startPlugins = ["lspsaga"]; - vim.maps.visual = { - "ca" = {action = ":lua require('lspsaga.codeaction').range_code_action()";}; - }; + vim.maps.visual = mkSetLuaBinding mappings.codeAction "require('lspsaga.codeaction').range_code_action"; - vim.maps.normal = - { - "lf" = {action = "lua require'lspsaga.provider'.lsp_finder()";}; - "lh" = {action = "lua require('lspsaga.hover').render_hover_doc()";}; - "" = {action = "lua require('lspsaga.action').smart_scroll_with_saga(1)";}; - "" = {action = "lua require('lspsaga.action').smart_scroll_with_saga(-1)";}; - "lr" = {action = "lua require'lspsaga.rename'.rename()";}; - "ld" = {action = "lua require'lspsaga.provider'.preview_definition()";}; - "ll" = {action = "lua require'lspsaga.diagnostic'.show_line_diagnostics()";}; - "lc" = {action = "lua require'lspsaga.diagnostic'.show_cursor_diagnostics()";}; - "lp" = {action = "lua require'lspsaga.diagnostic'.lsp_jump_diagnostic_prev()";}; - "ln" = {action = "lua require'lspsaga.diagnostic'.lsp_jump_diagnostic_next()";}; - } - // ( - if (!cfg.nvimCodeActionMenu.enable) - then { - "ca" = {action = "lua require('lspsaga.codeaction').code_action()";}; - } - else {} - ) - // ( - if (!cfg.lspSignature.enable) - then { - "ls" = {action = "lua require('lspsaga.signaturehelp').signature_help()";}; - } - else {} - ); + 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.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.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")) + ]; vim.luaConfigRC.lspsage = nvim.dag.entryAnywhere '' -- Enable lspsaga diff --git a/modules/lsp/lspsaga/lspsaga.nix b/modules/lsp/lspsaga/lspsaga.nix index 6107273..fec7ef4 100644 --- a/modules/lsp/lspsaga/lspsaga.nix +++ b/modules/lsp/lspsaga/lspsaga.nix @@ -1,53 +1,28 @@ -{ - config, - lib, - ... -}: +{lib, ...}: with lib; -with builtins; let - cfg = config.vim.lsp; -in { - options.vim.lsp = {lspsaga = {enable = mkEnableOption "LSP Saga";};}; +with builtins; { + options.vim.lsp.lspsaga = { + enable = mkEnableOption "LSP Saga"; - config = mkIf (cfg.enable && cfg.lspsaga.enable) { - vim.startPlugins = ["lspsaga"]; + mappings = { + lspFinder = mkMappingOption "LSP Finder [LSPSaga]" "lf"; + renderHoveredDoc = mkMappingOption "Rendered hovered docs [LSPSaga]" "lh"; - vim.maps.visual = { - "ca" = {action = ":lua require('lspsaga.codeaction').range_code_action()";}; + smartScrollUp = mkMappingOption "Smart scroll up [LSPSaga]" ""; + smartScrollDown = mkMappingOption "Smart scroll up [LSPSaga]" ""; + + rename = mkMappingOption "Rename [LSPSaga]" "lr"; + previewDefinition = mkMappingOption "Preview definition [LSPSaga]" "ld"; + + showLineDiagnostics = mkMappingOption "Show line diagnostics [LSPSaga]" "ll"; + showCursorDiagnostics = mkMappingOption "Show cursor diagnostics [LSPSaga]" "lc"; + + nextDiagnostic = mkMappingOption "Next diagnostic [LSPSaga]" "ln"; + previousDiagnostic = mkMappingOption "Previous diagnostic [LSPSaga]" "lp"; + + codeAction = mkMappingOption "Code action [LSPSaga]" "ca"; + + signatureHelp = mkMappingOption "Signature help [LSPSaga]" "ls"; }; - - vim.maps.normal = - { - "lf" = {action = "lua require'lspsaga.provider'.lsp_finder()";}; - "lh" = {action = "lua require('lspsaga.hover').render_hover_doc()";}; - "" = {action = "lua require('lspsaga.action').smart_scroll_with_saga(1)";}; - "" = {action = "lua require('lspsaga.action').smart_scroll_with_saga(-1)";}; - "lr" = {action = "lua require'lspsaga.rename'.rename()";}; - "ld" = {action = "lua require'lspsaga.provider'.preview_definition()";}; - "ll" = {action = "lua require'lspsaga.diagnostic'.show_line_diagnostics()";}; - "lc" = {action = "lua require'lspsaga.diagnostic'.show_cursor_diagnostics()";}; - "lp" = {action = "lua require'lspsaga.diagnostic'.lsp_jump_diagnostic_prev()";}; - "ln" = {action = "lua require'lspsaga.diagnostic'.lsp_jump_diagnostic_next()";}; - } - // ( - if (!cfg.nvimCodeActionMenu.enable) - then { - "ca" = {action = "lua require('lspsaga.codeaction').code_action()";}; - } - else {} - ) - // ( - if (!cfg.lspSignature.enable) - then { - "ls" = {action = "lua require('lspsaga.signaturehelp').signature_help()";}; - } - else {} - ); - - vim.luaConfigRC.lspsage = nvim.dag.entryAnywhere '' - -- Enable lspsaga - local saga = require 'lspsaga' - saga.init_lsp_saga() - ''; }; }