diff --git a/plugins/dap.nix b/plugins/dap.nix new file mode 100644 index 0000000..161d2ed --- /dev/null +++ b/plugins/dap.nix @@ -0,0 +1,235 @@ +{ icons, pkgs, ... }: + +{ + extra = { + packages = [ pkgs.vimPlugins.nvim-dap-ui ]; + + # https://github.com/AstroNvim/AstroNvim/blob/v4.7.7/lua/astronvim/plugins/configs/nvim-dap-ui.lua + # https://github.com/AstroNvim/AstroNvim/blob/v4.7.7/lua/astronvim/plugins/dap.lua#L37 + config = '' + local dap, dapui = require "dap", require "dapui" + + dap.listeners.after.event_initialized["dapui_config"] = function() dapui.open() end + dap.listeners.before.event_terminated["dapui_config"] = function() dapui.close() end + dap.listeners.before.event_exited["dapui_config"] = function() dapui.close() end + + dapui.setup({ floating = { border = "rounded" } }) + ''; + }; + + opts = { + enable = true; + + signs = { + dapBreakpoint = { + text = icons.DapBreakpoint; + texthl = "DiagnosticInfo"; + }; + + dapBreakpointCondition = { + text = icons.DapBreakpointCondition; + texthl = "DiagnosticInfo"; + }; + + dapBreakpointRejected = { + text = icons.DapBreakpointRejected; + texthl = "DiagnosticError"; + }; + + dapLogPoint = { + text = icons.DapLogPoint; + texthl = "DiagnosticInfo"; + }; + + dapStopped = { + text = icons.DapStopped; + texthl = "DiagnosticWarn"; + }; + }; + }; + + # rootOpts.plugins.cmp-dap.enable = true; + rootOpts.keymaps = [ + { + mode = "n"; + key = "dE"; + options.desc = "Evaluate input"; + + action.__raw = '' + function() + vim.ui.input({ prompt = "Expression: " }, function(expr) + if expr then require("dapui").eval(expr, { enter = true }) end + end) + end + ''; + } + { + mode = "n"; + key = "du"; + action.__raw = "function() require('dapui').toggle() end"; + options.desc = "Toggle Debugger UI"; + } + { + mode = "n"; + key = "dh"; + action.__raw = "function() require('dap.ui.widgets').hover() end"; + options.desc = "Debugger Hover"; + } + { + mode = "v"; + key = "dE"; + action.__raw = "function() require('dapui').eval() end"; + options.desc = "Evaluate Input"; + } + { + mode = "n"; + key = ""; + action.__raw = "function() require('dap').continue() end"; + options.desc = "Debugger: Start"; + } + # Shift+F5 + { + mode = "n"; + key = ""; + action.__raw = "function() require('dap').terminate() end"; + options.desc = "Debugger: Stop"; + } + # Shift+F9 + { + mode = "n"; + key = ""; + options.desc = "Debugger: Conditional Breakpoint"; + + action.__raw = '' + function() + vim.ui.input({ prompt = "Condition: " }, function(condition) + if condition then require("dap").set_breakpoint(condition) end + end) + end + ''; + } + # Control+F5 + { + mode = "n"; + key = ""; + action.__raw = "function() require('dap').restart_frame() end"; + options.desc = "Debugger: Restart"; + } + { + mode = "n"; + key = ""; + action.__raw = "function() require('dap').pause() end"; + options.desc = "Debugger: Pause"; + } + { + mode = "n"; + key = ""; + action.__raw = "function() require('dap').toggle_breakpoint() end"; + options.desc = "Debugger: Toggle Breakpoint"; + } + { + mode = "n"; + key = ""; + action.__raw = "function() require('dap').step_over() end"; + options.desc = "Debugger: Step Over"; + } + { + mode = "n"; + key = ""; + action.__raw = "function() require('dap').step_into() end"; + options.desc = "Debugger: Step Into"; + } + # Shift+F11 + { + mode = "n"; + key = ""; + action.__raw = "function() require('dap').step_out() end"; + options.desc = "Debugger: Step Out"; + } + { + mode = "n"; + key = "db"; + action.__raw = "function() require('dap').toggle_breakpoint() end"; + options.desc = "Toggle Breakpoint (F9)"; + } + { + mode = "n"; + key = "dB"; + action.__raw = "function() require('dap').clear_breakpoints() end"; + options.desc = "Clear Breakpoints"; + } + { + mode = "n"; + key = "dc"; + action.__raw = "function() require('dap').continue() end"; + options.desc = "Start/Continue (F5)"; + } + { + mode = "n"; + key = "dC"; + options.desc = "Conditional Breakpoint (S-F9)"; + + action.__raw = '' + function() + vim.ui.input({ prompt = "Condition: " }, function(condition) + if condition then require("dap").set_breakpoint(condition) end + end) + end + ''; + } + { + mode = "n"; + key = "di"; + action.__raw = "function() require('dap').step_into() end"; + options.desc = "Step Into (F11)"; + } + { + mode = "n"; + key = "do"; + action.__raw = "function() require('dap').step_over() end"; + options.desc = "Step Over (F10)"; + } + { + mode = "n"; + key = "dO"; + action.__raw = "function() require('dap').step_out() end"; + options.desc = "Step Out (S-F11)"; + } + { + mode = "n"; + key = "dq"; + action.__raw = "function() require('dap').close() end"; + options.desc = "Close Session"; + } + { + mode = "n"; + key = "dQ"; + action.__raw = "function() require('dap').terminate() end"; + options.desc = "Terminate Session (S-F5)"; + } + { + mode = "n"; + key = "dp"; + action.__raw = "function() require('dap').pause() end"; + options.desc = "Pause (F6)"; + } + { + mode = "n"; + key = "dr"; + action.__raw = "function() require('dap').restart_frame() end"; + options.desc = "Restart (C-F5)"; + } + { + mode = "n"; + key = "dR"; + action.__raw = "function() require('dap').repl.toggle() end"; + options.desc = "Toggle REPL"; + } + { + mode = "n"; + key = "ds"; + action.__raw = "function() require('dap').run_to_cursor() end"; + options.desc = "Run To Cursor"; + } + ]; +} diff --git a/plugins/lsp.nix b/plugins/lsp.nix new file mode 100644 index 0000000..ebea72f --- /dev/null +++ b/plugins/lsp.nix @@ -0,0 +1,114 @@ +{ icons, pkgs, ... }: + +{ + opts = { + enable = true; + + # Set keymaps when LSP is attached + keymaps = { + extra = [ + { + mode = "n"; + key = "li"; + action = "LspInfo"; + options.desc = "Show LSP info"; + } + { + mode = "n"; + key = "ll"; + action.__raw = "function() vim.lsp.codelens.refresh() end"; + options.desc = "LSP CodeLens refresh"; + } + { + mode = "n"; + key = "lL"; + action.__raw = "function() vim.lsp.codelens.run() end"; + options.desc = "LSP CodeLens run"; + } + ]; + + lspBuf = { + "la" = { + action = "code_action"; + desc = "LSP code action"; + }; + + gd = { + action = "definition"; + desc = "Go to definition"; + }; + + gI = { + action = "implementation"; + desc = "Go to implementation"; + }; + + gy = { + action = "type_definition"; + desc = "Go to type definition"; + }; + + K = { + action = "hover"; + desc = "LSP hover"; + }; + }; + }; + + postConfig = '' + vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded" }) + + vim.diagnostic.config({ + virtual_text = true, + signs = true, + underline = true, + update_in_insert = true, + severity_sort = false, + }) + + local signs = { + Error = "${icons.DiagnosticError}", + Warn = "${icons.DiagnosticWarn}", + Info = "${icons.DiagnosticInfo}", + Hint = "${icons.DiagnosticHint}", + } + for type, icon in pairs(signs) do + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl }) + end + ''; + + # Load all servers definitions + servers = { + ansiblels.enable = true; + bashls.enable = true; + cssls.enable = true; + docker-compose-language-service.enable = true; + dockerls.enable = true; + eslint.enable = true; + gopls.enable = true; + helm-ls.enable = true; + html.enable = true; + java-language-server.enable = true; + jsonls.enable = true; + lua-ls.enable = true; + nginx-language-server.enable = true; + nixd.enable = true; + pyright.enable = true; + sqls.enable = true; + terraformls.enable = true; + tsserver.enable = true; + yamlls.enable = true; + + typos-lsp = { + enable = true; + extraOptions.init_options.diagnosticSeverity = "Hint"; + }; + }; + }; + + rootOpts = { + colorschemes.catppuccin.settings.integrations.native_lsp.enabled = true; + extraPackages = [ pkgs.go ]; + }; +} diff --git a/plugins/wakatime.nix b/plugins/wakatime.nix new file mode 100644 index 0000000..9791bd5 --- /dev/null +++ b/plugins/wakatime.nix @@ -0,0 +1,10 @@ +{ pkgs, ... }: + +{ + extra = { + packages = [ pkgs.vimPlugins.vim-wakatime ]; + # TODO: auto-configure API key from sops + # (not sure if this is possible though) + #config = ""; + }; +}