83 lines
2.4 KiB
Lua
83 lines
2.4 KiB
Lua
return {
|
|
'neovim/nvim-lspconfig',
|
|
event = { 'BufReadPre', 'BufNewFile' },
|
|
dependencies = {
|
|
'williamboman/mason.nvim',
|
|
'hrsh7th/cmp-nvim-lsp',
|
|
{ 'antosha417/nvim-lsp-file-operations', config = true },
|
|
{
|
|
'folke/lazydev.nvim',
|
|
ft = 'lua',
|
|
opts = {
|
|
library = {
|
|
{ path = '${3rd}/luv/library', words = { 'vim%.uv' } },
|
|
},
|
|
},
|
|
},
|
|
},
|
|
config = function()
|
|
local cmp_nvim_lsp = require('cmp_nvim_lsp')
|
|
local keymap = vim.keymap
|
|
local wk = require('which-key')
|
|
|
|
vim.api.nvim_create_autocmd('LspAttach', {
|
|
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
|
|
callback = function(ev)
|
|
local function opts(desc)
|
|
return { desc = desc, buffer = ev.buf, silent = true }
|
|
end
|
|
|
|
keymap.set('n', 'gr', vim.lsp.buf.rename, opts('Rename'))
|
|
keymap.set('n', 'K', vim.lsp.buf.hover, opts('Show documentation'))
|
|
keymap.set('n', 'gR', '<cmd>Telescope lsp_references<cr>', opts('Show LSP references'))
|
|
keymap.set('n', 'gD', vim.lsp.buf.declaration, opts('Go to declaration'))
|
|
keymap.set('n', 'gd', '<cmd>Telescope lsp_definitions<cr>', opts('Show LSP definitions'))
|
|
keymap.set('n', 'gi', '<cmd>Telescope lsp_implementations<cr>', opts('Show LSP implementations'))
|
|
keymap.set('n', 'gt', '<cmd>Telescope lsp_type_definitions<cr>', opts('Show LSP type definitions'))
|
|
keymap.set('n', 'gE', vim.diagnostic.open_float, opts('Show diagnostics'))
|
|
keymap.set({ 'n', 'v' }, 'ga', vim.lsp.buf.code_action, opts('Show available code actions'))
|
|
wk.add({
|
|
{ '<leader>r', group = 'Rename' },
|
|
{ '<leader>rn', vim.lsp.buf.rename, desc = 'Smart Rename' },
|
|
})
|
|
end,
|
|
})
|
|
|
|
-- Apply default capabilities to all servers
|
|
local capabilities = cmp_nvim_lsp.default_capabilities()
|
|
vim.lsp.config('*', { capabilities = capabilities })
|
|
|
|
-- lua_ls: suppress vim global warnings, improve completion
|
|
vim.lsp.config('lua_ls', {
|
|
settings = {
|
|
Lua = {
|
|
diagnostics = {
|
|
globals = { 'vim' },
|
|
},
|
|
completion = {
|
|
callSnippet = 'Replace',
|
|
},
|
|
},
|
|
},
|
|
})
|
|
|
|
-- ts_ls: explicit host info
|
|
vim.lsp.config('ts_ls', {
|
|
cmd = { 'typescript-language-server', '--stdio' },
|
|
init_options = {
|
|
hostInfo = 'neovim',
|
|
},
|
|
})
|
|
|
|
-- hyprls: not managed by mason, enable manually
|
|
vim.lsp.config('hyprls', {
|
|
cmd = { 'hyprls' },
|
|
filetypes = { 'hyprlang' },
|
|
root_dir = function(fname)
|
|
return vim.fn.getcwd()
|
|
end,
|
|
})
|
|
vim.lsp.enable('hyprls')
|
|
end,
|
|
}
|