dotfiles/nvim/lua/lsp.lua

275 lines
7.5 KiB
Lua
Raw Permalink Normal View History

2022-01-18 01:25:46 -05:00
vim.g.coq_settings = {
2024-03-03 01:30:24 -05:00
-- auto_start = 'shut-up',
2022-09-27 23:46:19 -04:00
keymap = {
eval_snips = "<Leader>se",
},
clients = {
buffers = {
enabled = true,
weight_adjust = -2.0,
},
tree_sitter = {
enabled = true,
weight_adjust = -1.5,
},
lsp = {
enabled = true,
weight_adjust = 1.5,
},
snippets = {
enabled = true,
weight_adjust = 2.0,
}
}
2022-01-18 01:25:46 -05:00
}
local coq = require('coq')
2022-09-27 23:46:19 -04:00
require('coq_3p') {
2023-05-11 21:09:38 -04:00
{ src = 'vimtex', short_name = 'TEX' },
2022-11-08 20:32:39 -05:00
{ src = 'nvimlua', short_name = 'NLUA', conf_only = true },
2023-05-11 21:09:38 -04:00
{ src = 'bc', short_name = 'CALC', precision = 8 },
2022-09-27 23:46:19 -04:00
}
2022-01-18 01:25:46 -05:00
local lspstatus = require('lsp-status')
lspstatus.register_progress()
2022-05-13 18:15:19 -04:00
local function find_repo_root(names)
local util = require("lspconfig.util")
local config = names.configfiles
2022-11-08 20:32:39 -05:00
local function matcher(filename, _bufnr)
local gitroot = util.root_pattern('.git')(filename)
2022-05-13 18:15:19 -04:00
if gitroot then
for _, file in ipairs(config) do
if util.path.is_file(util.path.join(gitroot, file)) then
return gitroot
end
end
end
2022-11-08 20:32:39 -05:00
return util.root_pattern(unpack(config))(filename)
2022-05-13 18:15:19 -04:00
end
2022-11-08 20:32:39 -05:00
return matcher
2022-05-13 18:15:19 -04:00
end
2022-01-18 01:25:46 -05:00
local lsp_confs = {
2023-05-11 21:09:38 -04:00
lua_ls = {
2022-11-08 20:32:39 -05:00
settings = {
Lua = {
-- Settings for working with nvim (copied from https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#sumneko_lua)
runtime = {
version = 'LuaJIT',
path = runtime_path,
},
diagnostics = {
globals = { 'vim' },
},
workspace = {
library = vim.api.nvim_get_runtime_file("", true),
},
},
},
},
2023-09-03 20:55:58 -04:00
racket_langserver = {},
2023-12-20 20:29:27 -05:00
ocamllsp = {},
2022-11-08 20:32:39 -05:00
rust_analyzer = {
cmd_env = {
CARGO_TARGET_DIR = "/tmp/rust-analyzer"
},
settings = {
["rust-analyzer"] = {
checkOnSave = {
command = "clippy",
allTargets = false,
},
2022-08-06 13:09:13 -04:00
cargo = {
features = "all",
}
2022-02-16 20:08:28 -05:00
2022-11-08 20:32:39 -05:00
},
},
},
ccls = {},
2022-09-02 08:44:04 -04:00
jedi_language_server = {
filetypes = { "python", "sage.python" },
},
2022-11-08 20:32:39 -05:00
gopls = {},
2022-05-13 18:15:19 -04:00
dartls = {},
2024-11-14 03:41:41 -05:00
ts_ls = {
2022-05-13 18:15:19 -04:00
root_dir = find_repo_root({
configfiles = { "tsconfig.json", "jsconfig.json", "package.json" }
}),
},
2022-11-21 00:05:55 -05:00
denols = {
root_dir = find_repo_root({
configfiles = { "deno.json", "deno.jsonc" }
}),
},
astro = {
root_dir = find_repo_root({
configfiles = { "astro.config.mjs" }
}),
},
2022-05-13 18:15:19 -04:00
eslint = {
root_dir = find_repo_root({
configfiles = { ".eslintrc", ".eslintrc.js", "package.json" }
}),
2022-11-08 20:32:39 -05:00
on_new_config = function(config, new_root_dir)
local default_config = require('lspconfig.server_configurations.eslint').default_config
default_config.on_new_config(config, new_root_dir)
local util = require('lspconfig.util')
local pnp_cjs = util.path.join(new_root_dir, '.pnp.cjs')
local pnp_js = util.path.join(new_root_dir, '.pnp.js')
if util.path.exists(pnp_cjs) or util.path.exists(pnp_js) then
config.cmd = { 'yarn', 'exec', unpack(default_config.cmd) }
end
end
2022-05-13 18:15:19 -04:00
},
2022-05-14 19:29:51 -04:00
svelte = {},
svls = {},
2022-01-18 01:25:46 -05:00
}
local lsp_special_setup = {
}
2022-11-08 20:32:39 -05:00
local function on_attach(client, _bufnr)
lspstatus.on_attach(client)
end
2022-01-18 01:25:46 -05:00
local lspconfig = require('lspconfig')
2022-09-06 01:02:14 -04:00
2022-01-18 01:25:46 -05:00
for server, conf in pairs(lsp_confs) do
2022-11-08 20:32:39 -05:00
local source_on_attach = conf.on_attach
if source_on_attach == nil then
conf.on_attach = on_attach
else
conf.on_attach = function(client, bufnr)
on_attach(client, bufnr)
source_on_attach(client, bufnr)
end
end
conf.capabilities = vim.tbl_deep_extend(
"keep",
conf.capabilities or {},
lspstatus.capabilities
)
local final_config = coq.lsp_ensure_capabilities(conf)
local special_setup = lsp_special_setup[server]
if special_setup then
special_setup(final_config)
else
lspconfig[server].setup(final_config)
end
2022-01-18 01:25:46 -05:00
end
2024-11-14 03:41:41 -05:00
-- local null_ls = require('null-ls')
-- null_ls.setup({
-- sources = {
-- -- null_ls.builtins.diagnostics.chktex,
-- null_ls.builtins.diagnostics.cppcheck,
-- null_ls.builtins.diagnostics.shellcheck,
--
-- null_ls.builtins.code_actions.gitsigns,
-- },
-- })
2022-01-18 01:25:46 -05:00
vim.diagnostic.config({
2022-11-08 20:32:39 -05:00
severity_sort = true,
update_in_insert = true,
float = {
source = true,
},
2022-01-18 01:25:46 -05:00
})
do -- signs
2022-11-08 20:32:39 -05:00
local signs = {
{ 'DiagnosticSignError', text = '×', texthl = 'DiagnosticSignError' },
2024-01-05 21:15:21 -05:00
{ 'DiagnosticSignWarn', text = '>', texthl = 'DiagnosticSignWarn' },
{ 'DiagnosticSignInfo', text = 'I', texthl = 'DiagnosticSignInfo' },
{ 'DiagnosticSignHint', text = 'H', texthl = 'DiagnosticSignHint' },
2022-11-08 20:32:39 -05:00
}
for _, sign in pairs(signs) do
local name = sign[1]
local opts = sign
opts[1] = nil
vim.fn.sign_define(name, opts)
end
2022-01-18 01:25:46 -05:00
end
local map = vim.api.nvim_set_keymap
map(
2022-11-08 20:32:39 -05:00
'n',
'K',
[[luaeval('next(vim.lsp.buf_get_clients()) == nil') ? 'K' : '<Cmd>lua vim.lsp.buf.hover()<CR>']],
{ noremap = true, expr = true }
2022-01-18 01:25:46 -05:00
)
map(
2022-11-08 20:32:39 -05:00
'n',
'<C-]>',
[[luaeval('next(vim.lsp.buf_get_clients()) == nil') ? '<C-]>' : '<Cmd>lua vim.lsp.buf.definition()<CR>']],
{ noremap = true, expr = true }
2022-01-18 01:25:46 -05:00
)
2022-11-08 20:32:39 -05:00
local M = {}
M.format_on_save_hook = function()
local enabled = vim.b.format_on_save
if enabled == nil then
enabled = true
end
if enabled ~= 0 and enabled ~= false then
2022-12-04 16:01:19 -05:00
if vim.bo.filetype ~= "plaintex" and vim.bo.filetype ~= "tex" and vim.bo.filetype ~= "latex" and
vim.bo.filetype ~= "qf" and vim.bo.filetype ~= "bib" and vim.bo.filetype ~= "" and vim.bo.filetype ~= "pdf"
2024-11-14 03:41:41 -05:00
and vim.bo.filetype ~= "conf" and vim.bo.filetype ~= "TelescopePrompt" then
2022-12-04 16:01:19 -05:00
vim.lsp.buf.format({ async = false })
end
2022-11-08 20:32:39 -05:00
end
end
2022-01-18 01:25:46 -05:00
vim.cmd [[
2024-06-24 19:55:44 -04:00
augroup hoverlspconfig
au!
" diagnostic on hover
au BufWritePre * lua require'lsp'.format_on_save_hook()
au CursorHold * lua vim.diagnostic.open_float({focus = false})
augroup END
2022-01-18 01:25:46 -05:00
]]
2024-11-14 03:41:41 -05:00
vim.api.nvim_create_autocmd(
{ 'FileType',
}, {
pattern = "*",
callback = function()
if vim.bo.filetype ~= "plaintex" and vim.bo.filetype ~= "tex" and vim.bo.filetype ~= "latex" and
vim.bo.filetype ~= "qf" and vim.bo.filetype ~= "bib" and vim.bo.filetype ~= "" and vim.bo.filetype ~= "pdf"
and vim.bo.filetype ~= "conf" and vim.bo.filetype ~= "TelescopePrompt" then
vim.cmd [[ :COQnow -s ]]
end
2022-11-08 20:32:39 -05:00
end
2024-11-14 03:41:41 -05:00
})
2022-11-08 20:32:39 -05:00
2022-11-19 13:46:44 -05:00
-- vim.api.nvim_create_autocmd({ 'FileType', 'BufRead', 'BufReadPre', 'BufReadPost', 'BufWrite', 'BufWritePre',
-- 'BufWritePost' }, {
-- pattern = "*",
-- callback = function()
-- if vim.bo.filetype ~= "plaintex" and vim.bo.filetype ~= "tex" and vim.bo.filetype ~= "latex" then
-- vim.cmd [[ :COQnow -s ]]
-- end
-- end
-- })
2022-11-08 20:32:39 -05:00
-- vim.cmd [[
-- augroup disabletexlsp
-- autocmd!
-- autocmd FileType tex :COQstop
-- augroup END
-- ]]
return M