95 lines
3.3 KiB
Lua
95 lines
3.3 KiB
Lua
-- Diagnostic keymaps
|
|
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev)
|
|
vim.keymap.set('n', ']d', vim.diagnostic.goto_next)
|
|
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float)
|
|
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist)
|
|
|
|
local on_attach = function(_, bufnr)
|
|
local nmap = function(keys, func, desc)
|
|
if desc then
|
|
desc = 'LSP: ' .. desc
|
|
end
|
|
|
|
vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc })
|
|
end
|
|
|
|
nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
|
|
nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
|
|
nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition')
|
|
nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition')
|
|
nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
|
|
nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation')
|
|
|
|
-- nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
|
|
-- nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
|
|
-- nmap('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
|
|
|
|
nmap('K', vim.lsp.buf.hover, 'Hover Documentation')
|
|
nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation')
|
|
nmap('<leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder')
|
|
nmap('<leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder')
|
|
nmap('<leader>wl', function()
|
|
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
|
end, '[W]orkspace [L]ist Folders')
|
|
|
|
-- Create a command `:Format` local to the LSP buffer
|
|
vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_)
|
|
if vim.lsp.buf.format then
|
|
vim.lsp.buf.format()
|
|
elseif vim.lsp.buf.formatting then
|
|
vim.lsp.buf.formatting()
|
|
end
|
|
end, { desc = 'Format current buffer with LSP' })
|
|
|
|
end
|
|
|
|
-- mason - package manager for lsp servers
|
|
require('mason').setup()
|
|
local servers = { 'clangd', 'rust_analyzer', 'pyright', 'tsserver', 'sumneko_lua', 'gopls', 'bashls' }
|
|
require('mason-lspconfig').setup {
|
|
ensure_installed = servers,
|
|
}
|
|
|
|
-- nvim-cmp - extend capabilities
|
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
|
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
|
|
|
|
-- loop through servers, adding keymaps and capabilities
|
|
for _, lsp in ipairs(servers) do
|
|
require('lspconfig')[lsp].setup {
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
}
|
|
end
|
|
|
|
-- fidget - for lsp status above statusline
|
|
require('fidget').setup()
|
|
|
|
|
|
-- lua lsp config
|
|
-- Make runtime files discoverable to the server
|
|
local runtime_path = vim.split(package.path, ';')
|
|
table.insert(runtime_path, 'lua/?.lua')
|
|
table.insert(runtime_path, 'lua/?/init.lua')
|
|
|
|
require('lspconfig').sumneko_lua.setup {
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
settings = {
|
|
Lua = {
|
|
runtime = {
|
|
-- Tell the language server which version of Lua you're using (most likely LuaJIT)
|
|
version = 'LuaJIT',
|
|
-- Setup your lua path
|
|
path = runtime_path,
|
|
},
|
|
diagnostics = {
|
|
globals = { 'vim' },
|
|
},
|
|
workspace = { library = vim.api.nvim_get_runtime_file('', true), checkThirdParty = false, },
|
|
-- Do not send telemetry data containing a randomized but unique identifier
|
|
telemetry = { enable = false },
|
|
},
|
|
},
|
|
}
|