feat: add .sh file support, leader set to <space>, LSP keybinds cleanup
This commit is contained in:
parent
8f0b088886
commit
45715cccc0
4 changed files with 94 additions and 22 deletions
|
@ -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
|
||||
|
|
43
nvim/ftplugin/sh.lua
Normal file
43
nvim/ftplugin/sh.lua
Normal file
|
@ -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,
|
||||
-- },
|
||||
-- }
|
|
@ -4,7 +4,7 @@ local opt = vim.o
|
|||
local g = vim.g
|
||||
|
||||
-- <leader> key. Defaults to `\`. Some people prefer space.
|
||||
-- g.mapleader = ' '
|
||||
g.mapleader = ' '
|
||||
-- g.maplocalleader = ' '
|
||||
|
||||
opt.compatible = false
|
||||
|
|
|
@ -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 <space>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', '<space>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', '<space>pd', peek_definition, desc('lsp [p]eek [d]efinition'))
|
||||
keymap.set('n', '<space>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', '<C-k>', vim.lsp.buf.signature_help, desc('[lsp] signature help'))
|
||||
keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, desc('lsp add [w]orksp[a]ce folder'))
|
||||
keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, desc('lsp [w]orkspace folder [r]emove'))
|
||||
keymap.set('n', '<space>wl', function()
|
||||
vim.print(vim.lsp.buf.list_workspace_folders())
|
||||
end, desc('[lsp] [w]orkspace folders [l]ist'))
|
||||
keymap.set('n', '<space>rn', vim.lsp.buf.rename, desc('lsp [r]e[n]ame'))
|
||||
keymap.set('n', '<space>wq', vim.lsp.buf.workspace_symbol, desc('lsp [w]orkspace symbol [q]'))
|
||||
keymap.set('n', '<space>dd', vim.lsp.buf.document_symbol, desc('lsp [dd]ocument symbol'))
|
||||
keymap.set('n', '<M-CR>', vim.lsp.buf.code_action, desc('[lsp] code action'))
|
||||
keymap.set('n', '<M-l>', vim.lsp.codelens.run, desc('[lsp] run code lens'))
|
||||
keymap.set('n', '<space>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', '<space>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 = { "<cmd>vim.lsp.buf.type_definition<cr>", '[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 = { "<cmd>vim.lsp.buf.add_workspace_folder<cr>", '[l]sp add [w]orksp[a]ce folder' },
|
||||
r = { "<cmd>vim.lsp.buf.remove_workspace_folder<cr>", '[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 = { "<cmd>vim.lsp.buf.workspace_symbol<cr>", '[l]sp [w]orkspace symbol [q]' },
|
||||
},
|
||||
|
||||
r = { "<cmd>vim.lsp.buf.rename<cr>", '[l]sp [r]ename' },
|
||||
d = { "<cmd>vim.lsp.buf.document_symbol<cr>", '[l]sp [d]ocument symbol' },
|
||||
R = { "<cmd>vim.lsp.codelens.refresh<cr>", '[l]sp code lenses [R]efresh' },
|
||||
f = { function() vim.lsp.buf.format { async = true } end, '[l]sp [f]ormat buffer' },
|
||||
},
|
||||
}, { prefix = "<leader>" })
|
||||
if client.server_capabilities.inlayHintProvider then
|
||||
keymap.set('n', '<space>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', '<space>lh', function()
|
||||
wk.register({
|
||||
['<leader>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', '<space>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
|
||||
|
|
Loading…
Reference in a new issue