You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
4.3 KiB
Cheetah

# chezmoi:template:left-delimiter=--{{
--{{- /* vim: set filetype=lua: */ -}}
local function on_attach(_, buffer)
local function format_buffer(_)
vim.lsp.buf.format()
end
-- Create a command `:Format` local to the LSP buffer
vim.api.nvim_buf_create_user_command(buffer, 'Format', format_buffer, {
desc = 'Format current buffer with LSP',
})
end
local function config()
local cmp_nvim_lsp = require 'cmp_nvim_lsp'
local lspconfig = require 'lspconfig'
local mason_lspconfig = require 'mason-lspconfig'
local builtin = require 'telescope.builtin'
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }),
callback = function (event)
local function map(keys, func, desc)
vim.keymap.set('n', keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc})
end
map('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
map('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
map('gd', builtin.lsp_definitions, '[G]oto [D]efinition')
map('gr', builtin.lsp_references, '[G]oto [R]eferences')
map('gI', builtin.lsp_implementations, '[G]oto [I]mplementation')
map('<leader>D', builtin.lsp_type_definitions, 'Type [D]efinition')
map('<leader>ds', builtin.lsp_document_symbols, '[D]ocument [S]ymbols')
map('<leader>ws', builtin.lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
-- See `:help K` for why this keymap
map('K', vim.lsp.buf.hover, 'Hover Documentation')
map('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation')
local function inspect_workspace_folders()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end
-- Lesser used LSP functionality
map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
map('<leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder')
map('<leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder')
map('<leader>wl', inspect_workspace_folders, '[W]orkspace [L]ist Folders')
-- The following two autocommands are used to highlight references of the
-- word under your cursor when your cursor rests there for a little while.
-- See `:help CursorHold` for information about when this is executed
--
-- When you move your cursor, the highlights will be cleared (the second autocommand).
local client = vim.lsp.get_client_by_id(event.data.client_id)
if client and client.server_capabilities.documentHighlightProvider then
vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
buffer = event.buf,
callback = vim.lsp.buf.document_highlight,
})
vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, {
buffer = event.buf,
callback = vim.lsp.buf.clear_references,
})
end
end
})
local servers = {
bashls = {},
bufls = {},
taplo = {},
dockerls = {},
jsonls = {},
jqls = {},
marksman = {},
sqlls = {},
vimls = {},
yamlls = {},
11 months ago
cmake = {},
cssls = {},
--{{ if lookPath "node" -}}
eslint = {},
11 months ago
tsserver = {},
--{{- end }}
--{{ if lookPath "go" -}}
gopls = {},
templ = {},
-- golangci_lint_ls = {},
--{{- end }}
lua_ls = {
Lua = {
workspace = { checkThirdParty = false },
telemetry = { enable = false },
},
},
}
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = cmp_nvim_lsp.default_capabilities(capabilities)
mason_lspconfig.setup {
ensure_installed = vim.tbl_keys(servers),
}
mason_lspconfig.setup_handlers {
function(server_name)
lspconfig[server_name].setup {
capabilities = capabilities,
on_attach = on_attach,
settings = servers[server_name],
filetypes = (servers[server_name] or {}).filetypes,
}
end,
}
end
return {
'neovim/nvim-lspconfig',
name = 'lspconfig',
config = config,
dependencies = {
{ 'williamboman/mason.nvim', tag = 'v1.*', opts = {} },
{ 'williamboman/mason-lspconfig.nvim', tag = 'v1.*' },
{ 'j-hui/fidget.nvim', tag = 'legacy', opts = {} },
{ 'folke/neodev.nvim', tag = 'v2.*', opts = {} },
{ 'folke/trouble.nvim', tag = 'v2.*' },
},
}