Simplify lsp config

main
Buddy Sandidge 2 weeks ago
parent 3888baed8c
commit 75ca9068b6

@ -1,11 +1,10 @@
# chezmoi:template:left-delimiter=--{{
--{{- /* vim: set filetype=lua: */ -}}
local function format_buffer(_)
vim.lsp.buf.format()
end
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',
@ -13,110 +12,83 @@ local function on_attach(_, buffer)
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
local lspconfig = require('lspconfig')
map('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
map('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
local capabilities = require('cmp_nvim_lsp').default_capabilities(
vim.lsp.protocol.make_client_capabilities())
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')
--{{ if lookPath "bash-language-server" -}}
-- npm install --global bash-language-server
lspconfig.bashls.setup {
capabilities = capabilities,
on_attach = on_attach,
settings = {},
}
--{{- end }}
-- 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')
--{{ if lookPath "go" -}}
lspconfig.gopls.setup {
capabilities = capabilities,
on_attach = on_attach,
settings = {},
}
--{{- end }}
local function inspect_workspace_folders()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end
--{{ if lookPath "nu" -}}
lspconfig.nushell.setup {
capabilities = capabilities,
on_attach = on_attach,
settings = {},
}
--{{- 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')
--{{ if lookPath "templ" -}}
lspconfig.templ.setup {
capabilities = capabilities,
on_attach = on_attach,
settings = {},
}
--{{- end }}
--{{ if lookPath "vscode-eslint-language-server" -}}
-- # npm i -g vscode-langservers-extracted
lspconfig.eslint.setup {
capabilities = capabilities,
on_attach = on_attach,
settings = {},
}
-- 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,
})
lspconfig.html.setup {
capabilities = capabilities,
on_attach = on_attach,
settings = {},
}
vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, {
buffer = event.buf,
callback = vim.lsp.buf.clear_references,
})
end
lspconfig.cssls.setup {
capabilities = capabilities,
on_attach = on_attach,
settings = {},
}
end
})
lspconfig.jsonls.setup {
capabilities = capabilities,
on_attach = on_attach,
settings = {},
}
--{{- end }}
local servers = {
bashls = {},
bufls = {},
taplo = {},
dockerls = {},
jsonls = {},
jqls = {},
marksman = {},
sqlls = {},
vimls = {},
yamlls = {},
cmake = {},
cssls = {},
--{{ if lookPath "node" -}}
eslint = {},
ts_ls = {},
--{{- end }}
--{{ if lookPath "go" -}}
gopls = {},
templ = {},
-- golangci_lint_ls = {},
--{{- end }}
lua_ls = {
--{{ if lookPath "lua-language-server" -}}
lspconfig.lua_ls.setup {
capabilities = capabilities,
on_attach = on_attach,
settings = {
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 }}
end
return {
@ -125,15 +97,8 @@ return {
tag = 'v1.0.0',
config = config,
dependencies = {
{ 'williamboman/mason.nvim', tag = 'v1.10.0', opts = {} },
{ 'williamboman/mason-lspconfig.nvim', tag = 'v1.31.0' },
{ 'j-hui/fidget.nvim', tag = 'legacy', opts = {} },
{ 'folke/trouble.nvim', tag = 'v3.6.0' },
-- { 'folke/lazydev.nvim',
-- tag = 'v1.8.0',
-- ft = "lua",
-- opts = {
-- }
-- },
{ 'folke/lazydev.nvim', tag = 'v1.9.0', ft = "lua", opts = {} },
},
}

@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -euo pipefail
# shellcheck disable=SC1091
source "${XDG_DATA_HOME}/buddy-up/includes/utils.sh"
main() (
APP=lua-language-server
VERSION=${VERSION:-3.13.3}
DEST=${XDG_DATA_HOME}/apps/releases/${APP}
URL=https://github.com/LuaLS/lua-language-server/releases/download/${VERSION}/lua-language-server-${VERSION}-$(get_os)-$(get_arch).tar.gz
extract_tarball "${URL}" "${DEST}/${VERSION}"
set_current_link "${DEST}" "${VERSION}"
set_link "${XDG_BIN_HOME}/lua-language-server" "${DEST}" bin/lua-language-server
)
get_arch() (
case $(uname -m) in
x86_64*) echo x64 ;;
*)
echo >&2 "unsupported architecture: $(uname -m)"
exit 1
;;
esac
)
main "$@"
Loading…
Cancel
Save