diff --git a/nix/neovim-overlay.nix b/nix/neovim-overlay.nix index 841f2ef..f63f50e 100644 --- a/nix/neovim-overlay.nix +++ b/nix/neovim-overlay.nix @@ -98,9 +98,13 @@ with final.pkgs.lib; let ]; extraPackages = with pkgs; [ + # Dependencies + ripgrep + # language servers, etc. - clang-tools asm-lsp # Assembly language server + clang-tools # C/C++ language server + nodePackages.bash-language-server # Bash language server lua-language-server nil # nix LSP nodejs_20 diff --git a/nvim/ftplugin/sh.lua b/nvim/ftplugin/sh.lua new file mode 100644 index 0000000..8c5c068 --- /dev/null +++ b/nvim/ftplugin/sh.lua @@ -0,0 +1,43 @@ +-- Exit if the language server isn't available +if vim.fn.executable('bash-language-server') ~= 1 then + return +end + +local root_files = { + '.env', + '.vscode', + '.git', +} + +vim.lsp.start { + name = 'bashls', + cmd = { 'bash-language-server', 'start' }, + root_dir = vim.fs.dirname(vim.fs.find(root_files, { upward = true })[1]), + -- capabilities = require('user.lsp').make_client_capabilities(), + single_file_support = true, +} + +-- local dap = require("dap") +-- +-- if require('user.file_exists').file_exists(vim.fs.dirname(vim.fs.find(root_files, { upward = true })[1]) .. "/.vscode/launch.json") then +-- require("dap.ext.vscode").load_launchjs(nil, { cppdbg = { "c", "cpp", "asm" } }) +-- end +-- +-- dap.adapters.gdb = { +-- type = "executable", +-- command = "gdb", +-- args = { "-i", "dap" } +-- } +-- +-- dap.configurations.c = { +-- { +-- name = "Launch", +-- type = "gdb", +-- request = "launch", +-- program = function() +-- return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') +-- end, +-- cwd = "${workspaceFolder}", +-- stopAtBeginningOfMainSubprogram = false, +-- }, +-- } diff --git a/nvim/init.lua b/nvim/init.lua index b2ebe26..4109f4b 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -4,7 +4,7 @@ local opt = vim.o local g = vim.g -- key. Defaults to `\`. Some people prefer space. --- g.mapleader = ' ' +g.mapleader = ' ' -- g.maplocalleader = ' ' opt.compatible = false diff --git a/nvim/plugin/autocommands.lua b/nvim/plugin/autocommands.lua index 754cf9a..ab4d99b 100644 --- a/nvim/plugin/autocommands.lua +++ b/nvim/plugin/autocommands.lua @@ -4,6 +4,7 @@ end vim.g.did_load_autocommands_plugin = true local api = vim.api +local wk = require('which-key') local tempdirgroup = api.nvim_create_augroup('tempdir', { clear = true }) -- Do not set undofile for files in /tmp @@ -73,35 +74,59 @@ vim.api.nvim_create_autocmd('LspAttach', { local function desc(description) return { noremap = true, silent = true, buffer = bufnr, desc = description } end + + -- Set name for the l prefix keymap.set('n', 'gD', vim.lsp.buf.declaration, desc('lsp [g]o to [D]eclaration')) keymap.set('n', 'gd', vim.lsp.buf.definition, desc('lsp [g]o to [d]efinition')) - keymap.set('n', 'gt', vim.lsp.buf.type_definition, desc('lsp [g]o to [t]ype definition')) keymap.set('n', 'K', vim.lsp.buf.hover, desc('[lsp] hover')) - keymap.set('n', 'pd', peek_definition, desc('lsp [p]eek [d]efinition')) - keymap.set('n', 'pt', peek_type_definition, desc('lsp [p]eek [t]ype definition')) keymap.set('n', 'gi', vim.lsp.buf.implementation, desc('lsp [g]o to [i]mplementation')) keymap.set('n', '', vim.lsp.buf.signature_help, desc('[lsp] signature help')) - keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, desc('lsp add [w]orksp[a]ce folder')) - keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, desc('lsp [w]orkspace folder [r]emove')) - keymap.set('n', 'wl', function() - vim.print(vim.lsp.buf.list_workspace_folders()) - end, desc('[lsp] [w]orkspace folders [l]ist')) - keymap.set('n', 'rn', vim.lsp.buf.rename, desc('lsp [r]e[n]ame')) - keymap.set('n', 'wq', vim.lsp.buf.workspace_symbol, desc('lsp [w]orkspace symbol [q]')) - keymap.set('n', 'dd', vim.lsp.buf.document_symbol, desc('lsp [dd]ocument symbol')) keymap.set('n', '', vim.lsp.buf.code_action, desc('[lsp] code action')) keymap.set('n', '', vim.lsp.codelens.run, desc('[lsp] run code lens')) - keymap.set('n', 'cr', vim.lsp.codelens.refresh, desc('lsp [c]ode lenses [r]efresh')) keymap.set('n', 'gr', vim.lsp.buf.references, desc('lsp [g]et [r]eferences')) - keymap.set('n', 'f', function() - vim.lsp.buf.format { async = true } - end, desc('[lsp] [f]ormat buffer')) + wk.register({ + l = { + name = "[l]sp", + g = { + name = "[g]o to", + t = { "vim.lsp.buf.type_definition", '[l]sp [g]o to [t]ype definition' }, + }, + + p = { + name = "[p]eek", + d = { peek_definition, '[l]sp [p]eek [d]efinition' }, + t = { peek_type_definition, '[l]sp [p]eek [t]ype definition' }, + }, + + w = { + name = "[w]orkspace", + a = { "vim.lsp.buf.add_workspace_folder", '[l]sp add [w]orksp[a]ce folder' }, + r = { "vim.lsp.buf.remove_workspace_folder", '[l]sp [w]orkspace folder [r]emove' }, + l = { function() vim.print(vim.lsp.buf.list_workspace_folders()) end, '[l]sp [w]orkspace folders [l]ist' }, + q = { "vim.lsp.buf.workspace_symbol", '[l]sp [w]orkspace symbol [q]' }, + }, + + r = { "vim.lsp.buf.rename", '[l]sp [r]ename' }, + d = { "vim.lsp.buf.document_symbol", '[l]sp [d]ocument symbol' }, + R = { "vim.lsp.codelens.refresh", '[l]sp code lenses [R]efresh' }, + f = { function() vim.lsp.buf.format { async = true } end, '[l]sp [f]ormat buffer' }, + }, + }, { prefix = "" }) if client.server_capabilities.inlayHintProvider then - keymap.set('n', 'h', function() - local current_setting = vim.lsp.inlay_hint.is_enabled(bufnr) - vim.lsp.inlay_hint.enable(bufnr, not current_setting) - end, desc('[lsp] toggle inlay hints')) - end + -- keymap.set('n', 'lh', function() + wk.register({ + ['lh'] = { function() + local current_setting = vim.lsp.inlay_hint.is_enabled(bufnr) + vim.lsp.inlay_hint.enable(bufnr, not current_setting) + end, '[l]sp toggle inlay [h]ints' }}) + end + -- TODO: InlayHint setting not working - the code below is the original one + -- if client.server_capabilities.inlayHintProvider then + -- keymap.set('n', 'lh', function() + -- local current_setting = vim.lsp.inlay_hint.is_enabled(bufnr) + -- vim.lsp.inlay_hint.enable(bufnr, not current_setting) + -- end, desc('[l]sp toggle inlay [h]ints')) + -- end -- Auto-refresh code lenses if not client then