2023-09-19 05:21:43 +00:00
|
|
|
local nvim_lsp = require("lspconfig")
|
2023-09-19 05:28:46 +00:00
|
|
|
|
2024-11-11 07:56:28 +00:00
|
|
|
vim.lsp.set_log_level("debug")
|
|
|
|
|
2023-09-19 04:51:33 +00:00
|
|
|
local on_attach = function(client, bufnr)
|
2024-11-11 07:56:28 +00:00
|
|
|
-- TODO: use vim.api.nvim_create_autocmd
|
|
|
|
vim.api.nvim_exec2([[autocmd User LspDiagnosticsChanged call lightline#update()]], { output = false })
|
|
|
|
|
|
|
|
local opts = { noremap = true, silent = false }
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "gd", "<Cmd>lua vim.lsp.buf.definition()<CR>", opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "<Cmd>lua vim.lsp.buf.type_definition()<CR>", opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>gd", "<Cmd>lua vim.lsp.buf.definition()<CR>", opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>gD", "<Cmd>lua vim.lsp.buf.type_definition()<CR>", opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>k", "<Cmd>lua vim.diagnostic.open_float()<CR>", opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>e", "<Cmd>lua vim.lsp.buf.rename()<CR>", opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>r", "<Cmd>lua vim.lsp.buf.references()<CR>", opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>i", "<Cmd>lua vim.lsp.buf.implementation()<CR>", opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>ca", "<Cmd>lua vim.lsp.buf.code_action()<CR>", opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>ci", "<Cmd>lua vim.lsp.buf.incoming_calls()<CR>", opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>co", "<Cmd>lua vim.lsp.buf.outgoing_calls()<CR>", opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "K", "<Cmd>lua vim.lsp.buf.hover()<CR>", opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "]e", '<Cmd>lua vim.diagnostic.goto_next({severity="Error"})<CR>', opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "[e", '<Cmd>lua vim.diagnostic.goto_prev({severity="Error"})<CR>', opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "]d", "<Cmd>lua vim.diagnostic.goto_next()<CR>", opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "[d", "<Cmd>lua vim.diagnostic.goto_prev()<CR>", opts)
|
2024-12-20 15:34:59 +00:00
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "ch", "<Cmd>lua vim.diagnostic.hide(nil, 0)<CR>", opts)
|
2024-11-11 07:56:28 +00:00
|
|
|
|
|
|
|
-- fzf triggers:
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>fr", "<Cmd>References<CR>", opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>fi", "<Cmd>Implementations<CR>", opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>fs", "<Cmd>DocumentSymbols<CR>", opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>fw", "<Cmd>WorkspaceSymbols<CR>", opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>fc", "<Cmd>CodeActions<CR>", opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>fci", "<Cmd>IncomingCalls<CR>", opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>fco", "<Cmd>OutgoingCalls<CR>", opts)
|
|
|
|
|
|
|
|
require("lsp_signature").on_attach({
|
|
|
|
hint_enable = false,
|
|
|
|
})
|
|
|
|
|
|
|
|
require("copilot_cmp").setup()
|
2023-09-19 04:51:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Go
|
|
|
|
|
2023-09-19 05:21:43 +00:00
|
|
|
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
2023-11-06 06:35:44 +00:00
|
|
|
capabilities.textDocument.completion.completionItem.snippetSupport = false
|
2023-09-19 04:51:33 +00:00
|
|
|
capabilities.textDocument.completion.completionItem.resolveSupport = {
|
2024-11-11 07:56:28 +00:00
|
|
|
properties = {
|
|
|
|
"documentation",
|
|
|
|
"detail",
|
|
|
|
"additionalTextEdits",
|
|
|
|
},
|
2023-09-19 04:51:33 +00:00
|
|
|
}
|
|
|
|
|
2023-09-19 05:21:43 +00:00
|
|
|
nvim_lsp.gopls.setup({
|
2024-11-11 07:56:28 +00:00
|
|
|
settings = {
|
|
|
|
gopls = {
|
|
|
|
staticcheck = true,
|
|
|
|
-- Disabling linksInHover may not be working as expected:
|
|
|
|
linksInHover = false,
|
|
|
|
usePlaceholders = true,
|
|
|
|
experimentalPostfixCompletions = true,
|
|
|
|
analyses = {
|
|
|
|
unusedparams = true,
|
|
|
|
shadow = true,
|
|
|
|
unusedwrite = true,
|
|
|
|
unusedresult = true,
|
|
|
|
nilness = true,
|
|
|
|
},
|
|
|
|
buildFlags = { "-tags=acceptance,basketapitest,graphqlapitest" }
|
|
|
|
},
|
|
|
|
},
|
|
|
|
init_options = {
|
|
|
|
usePlaceholders = true,
|
|
|
|
},
|
|
|
|
capabilities = vim.tbl_extend(
|
|
|
|
"error",
|
|
|
|
capabilities,
|
|
|
|
{
|
|
|
|
workspace = {
|
|
|
|
didChangeWatchedFiles = {
|
|
|
|
dynamicRegistration = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
),
|
|
|
|
on_attach = on_attach,
|
2023-09-19 05:21:43 +00:00
|
|
|
})
|
2023-09-19 04:51:33 +00:00
|
|
|
|
|
|
|
-- Rust
|
2023-09-19 05:21:43 +00:00
|
|
|
nvim_lsp.rust_analyzer.setup({
|
|
|
|
capabilities = capabilities,
|
|
|
|
on_attach = on_attach,
|
|
|
|
settings = {
|
|
|
|
["rust-analyzer"] = {
|
|
|
|
imports = {
|
|
|
|
granularity = {
|
|
|
|
group = "module",
|
|
|
|
},
|
|
|
|
prefix = "self",
|
|
|
|
},
|
|
|
|
cargo = {
|
|
|
|
buildScripts = {
|
|
|
|
enable = true,
|
|
|
|
},
|
|
|
|
},
|
2024-11-10 13:47:00 +00:00
|
|
|
-- procMacro = {
|
|
|
|
-- enable = false,
|
|
|
|
-- },
|
|
|
|
-- diagnostics = {
|
|
|
|
-- disabled = { "unresolved-proc-macro" },
|
|
|
|
-- },
|
2023-09-19 05:21:43 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2023-09-19 04:51:33 +00:00
|
|
|
|
|
|
|
-- Ruby
|
|
|
|
|
2023-09-19 05:21:43 +00:00
|
|
|
nvim_lsp.solargraph.setup({
|
2024-11-11 07:56:28 +00:00
|
|
|
on_attach = on_attach,
|
|
|
|
settings = {
|
|
|
|
solargraph = {
|
|
|
|
autoformat = false,
|
|
|
|
formatting = false,
|
|
|
|
},
|
|
|
|
},
|
2023-09-19 05:21:43 +00:00
|
|
|
})
|
2023-09-19 04:51:33 +00:00
|
|
|
|
|
|
|
-- Typescript
|
|
|
|
-- https://jose-elias-alvarez.medium.com/configuring-neovims-lsp-client-for-typescript-development-5789d58ea9c
|
|
|
|
|
2024-09-23 06:36:50 +00:00
|
|
|
nvim_lsp.ts_ls.setup({
|
2024-11-11 07:56:28 +00:00
|
|
|
on_attach = on_attach,
|
2023-09-19 05:21:43 +00:00
|
|
|
})
|
2023-09-19 04:51:33 +00:00
|
|
|
|
|
|
|
local filetypes = {
|
2024-11-11 07:56:28 +00:00
|
|
|
typescript = "eslint",
|
|
|
|
typescriptreact = "eslint",
|
2023-09-19 04:51:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
-- diagnosticls
|
|
|
|
|
|
|
|
local linters = {
|
2024-11-11 07:56:28 +00:00
|
|
|
eslint = {
|
|
|
|
sourceName = "eslint",
|
|
|
|
-- fallback to global eslint if the local is not found?
|
|
|
|
-- https://github.com/creativenull/diagnosticls-configs-nvim/blob/e7d6f7e99f6b416d2aeee89314bc46fc36df7b22/lua/diagnosticls-configs/fs.lua#L20
|
|
|
|
command = "./node_modules/.bin/eslint",
|
|
|
|
rootPatterns = { ".eslintrc", ".eslintrc.js" },
|
|
|
|
debounce = 100,
|
|
|
|
args = { "--stdin", "--stdin-filename", "%filepath", "--format", "json" },
|
|
|
|
parseJson = {
|
|
|
|
errorsRoot = "[0].messages",
|
|
|
|
line = "line",
|
|
|
|
column = "column",
|
|
|
|
endLine = "endLine",
|
|
|
|
endColumn = "endColumn",
|
|
|
|
message = "${message} [${ruleId}]",
|
|
|
|
security = "severity",
|
|
|
|
},
|
|
|
|
securities = { [1] = "error", [2] = "warning" },
|
|
|
|
},
|
2023-09-19 04:51:33 +00:00
|
|
|
}
|
|
|
|
|
2023-09-19 05:21:43 +00:00
|
|
|
nvim_lsp.diagnosticls.setup({
|
2024-11-11 07:56:28 +00:00
|
|
|
on_attach = on_attach,
|
|
|
|
filetypes = vim.tbl_keys(filetypes),
|
|
|
|
init_options = {
|
|
|
|
linters = linters,
|
|
|
|
filetypes = filetypes,
|
|
|
|
},
|
2023-09-19 05:21:43 +00:00
|
|
|
})
|
2023-09-19 04:51:33 +00:00
|
|
|
|
|
|
|
-- Lua
|
|
|
|
|
2023-09-19 05:21:43 +00:00
|
|
|
local runtime_path = vim.split(package.path, ";")
|
2023-09-19 04:51:33 +00:00
|
|
|
table.insert(runtime_path, "lua/?.lua")
|
|
|
|
table.insert(runtime_path, "lua/?/init.lua")
|
|
|
|
|
2023-09-19 05:21:43 +00:00
|
|
|
nvim_lsp.lua_ls.setup({
|
2024-11-11 07:56:28 +00:00
|
|
|
settings = {
|
|
|
|
Lua = {
|
|
|
|
runtime = {
|
|
|
|
version = "LuaJIT",
|
|
|
|
path = runtime_path,
|
|
|
|
},
|
|
|
|
diagnostics = {
|
|
|
|
globals = { "vim" },
|
|
|
|
},
|
|
|
|
workspace = {
|
|
|
|
library = vim.api.nvim_get_runtime_file("", true),
|
|
|
|
},
|
|
|
|
telemetry = {
|
|
|
|
enable = false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
on_attach = on_attach,
|
2023-09-19 05:21:43 +00:00
|
|
|
})
|
2023-10-07 07:32:31 +00:00
|
|
|
|
|
|
|
-- Bash language server
|
|
|
|
|
|
|
|
-- https://github.com/bash-lsp/bash-language-server#neovim
|
|
|
|
vim.api.nvim_create_autocmd("FileType", {
|
2024-11-11 07:56:28 +00:00
|
|
|
pattern = "sh",
|
|
|
|
callback = function()
|
|
|
|
vim.lsp.start({
|
|
|
|
name = "bash-language-server",
|
|
|
|
cmd = { "bash-language-server", "start" },
|
|
|
|
})
|
|
|
|
end,
|
2023-10-07 07:32:31 +00:00
|
|
|
})
|