Simplify lsp config

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

@ -1,11 +1,10 @@
# chezmoi:template:left-delimiter=--{{ # chezmoi:template:left-delimiter=--{{
--{{- /* vim: set filetype=lua: */ -}} --{{- /* vim: set filetype=lua: */ -}}
local function format_buffer(_)
local function on_attach(_, buffer)
local function format_buffer(_)
vim.lsp.buf.format() vim.lsp.buf.format()
end end
local function on_attach(_, buffer)
-- Create a command `:Format` local to the LSP buffer -- Create a command `:Format` local to the LSP buffer
vim.api.nvim_buf_create_user_command(buffer, 'Format', format_buffer, { vim.api.nvim_buf_create_user_command(buffer, 'Format', format_buffer, {
desc = 'Format current buffer with LSP', desc = 'Format current buffer with LSP',
@ -13,110 +12,83 @@ local function on_attach(_, buffer)
end end
local function config() local function config()
local cmp_nvim_lsp = require 'cmp_nvim_lsp' local lspconfig = require('lspconfig')
local lspconfig = require 'lspconfig'
local mason_lspconfig = require 'mason-lspconfig'
local builtin = require 'telescope.builtin'
vim.api.nvim_create_autocmd('LspAttach', { local capabilities = require('cmp_nvim_lsp').default_capabilities(
group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }), vim.lsp.protocol.make_client_capabilities())
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') --{{ if lookPath "bash-language-server" -}}
map('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction') -- npm install --global bash-language-server
lspconfig.bashls.setup {
map('gd', builtin.lsp_definitions, '[G]oto [D]efinition') capabilities = capabilities,
map('gr', builtin.lsp_references, '[G]oto [R]eferences') on_attach = on_attach,
map('gI', builtin.lsp_implementations, '[G]oto [I]mplementation') settings = {},
map('<leader>D', builtin.lsp_type_definitions, 'Type [D]efinition') }
map('<leader>ds', builtin.lsp_document_symbols, '[D]ocument [S]ymbols') --{{- end }}
map('<leader>ws', builtin.lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
-- See `:help K` for why this keymap --{{ if lookPath "go" -}}
map('K', vim.lsp.buf.hover, 'Hover Documentation') lspconfig.gopls.setup {
map('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation') capabilities = capabilities,
on_attach = on_attach,
settings = {},
}
--{{- end }}
local function inspect_workspace_folders() --{{ if lookPath "nu" -}}
print(vim.inspect(vim.lsp.buf.list_workspace_folders())) lspconfig.nushell.setup {
end capabilities = capabilities,
on_attach = on_attach,
settings = {},
}
--{{- end }}
-- Lesser used LSP functionality --{{ if lookPath "templ" -}}
map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') lspconfig.templ.setup {
map('<leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder') capabilities = capabilities,
map('<leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder') on_attach = on_attach,
map('<leader>wl', inspect_workspace_folders, '[W]orkspace [L]ist Folders') settings = {},
}
--{{- end }}
-- The following two autocommands are used to highlight references of the --{{ if lookPath "vscode-eslint-language-server" -}}
-- word under your cursor when your cursor rests there for a little while. -- # npm i -g vscode-langservers-extracted
-- See `:help CursorHold` for information about when this is executed lspconfig.eslint.setup {
-- capabilities = capabilities,
-- When you move your cursor, the highlights will be cleared (the second autocommand). on_attach = on_attach,
local client = vim.lsp.get_client_by_id(event.data.client_id) settings = {},
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' }, { lspconfig.html.setup {
buffer = event.buf, capabilities = capabilities,
callback = vim.lsp.buf.clear_references, on_attach = on_attach,
}) settings = {},
end }
end lspconfig.cssls.setup {
}) capabilities = capabilities,
on_attach = on_attach,
settings = {},
}
local servers = { lspconfig.jsonls.setup {
bashls = {}, capabilities = capabilities,
bufls = {}, on_attach = on_attach,
taplo = {}, settings = {},
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 }} --{{- end }}
lua_ls = {
--{{ if lookPath "lua-language-server" -}}
lspconfig.lua_ls.setup {
capabilities = capabilities,
on_attach = on_attach,
settings = {
Lua = { Lua = {
workspace = { checkThirdParty = false }, workspace = { checkThirdParty = false },
telemetry = { enable = false }, telemetry = { enable = false },
}, },
}, },
} }
--{{- end }}
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 { return {
@ -125,15 +97,8 @@ return {
tag = 'v1.0.0', tag = 'v1.0.0',
config = config, config = config,
dependencies = { dependencies = {
{ 'williamboman/mason.nvim', tag = 'v1.10.0', opts = {} },
{ 'williamboman/mason-lspconfig.nvim', tag = 'v1.31.0' },
{ 'j-hui/fidget.nvim', tag = 'legacy', opts = {} }, { 'j-hui/fidget.nvim', tag = 'legacy', opts = {} },
{ 'folke/trouble.nvim', tag = 'v3.6.0' }, { 'folke/trouble.nvim', tag = 'v3.6.0' },
-- { 'folke/lazydev.nvim', { 'folke/lazydev.nvim', tag = 'v1.9.0', ft = "lua", opts = {} },
-- tag = 'v1.8.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