2023-01-10 02:38:06 +01:00
|
|
|
local helpers = require("my.helpers")
|
|
|
|
local env = require("my.helpers.env")
|
|
|
|
|
|
|
|
local lspconfig = {
|
|
|
|
"neovim/nvim-lspconfig",
|
|
|
|
event = "BufReadPre",
|
|
|
|
dependencies = {
|
|
|
|
"folke/neoconf.nvim",
|
|
|
|
{
|
|
|
|
"folke/neodev.nvim",
|
|
|
|
config = true,
|
|
|
|
},
|
2023-04-17 15:19:41 +02:00
|
|
|
"simrat39/rust-tools.nvim",
|
2023-01-10 02:38:06 +01:00
|
|
|
},
|
|
|
|
cond = env.vscode.not_active(),
|
|
|
|
}
|
|
|
|
|
|
|
|
local M = {
|
|
|
|
lspconfig,
|
|
|
|
{
|
|
|
|
"smjonas/inc-rename.nvim",
|
|
|
|
cmd = "IncRename",
|
2023-02-09 06:59:58 +01:00
|
|
|
opts = {
|
2023-01-10 02:38:06 +01:00
|
|
|
input_buffer_type = "dressing",
|
|
|
|
},
|
|
|
|
cond = env.vscode.not_active(),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
function M.on_attach(client, bufnr)
|
|
|
|
-- {{{ Keymap helpers
|
|
|
|
local opts = function(desc)
|
2023-12-07 22:35:57 +01:00
|
|
|
return { silent = true, desc = desc, buffer = bufnr }
|
2023-01-10 02:38:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local nmap = function(from, to, desc)
|
|
|
|
vim.keymap.set("n", from, to, opts(desc))
|
|
|
|
end
|
|
|
|
-- }}}
|
2023-03-14 20:57:07 +01:00
|
|
|
-- {{{ Go to declaration / references / implementation
|
2023-01-10 02:38:06 +01:00
|
|
|
nmap("gd", vim.lsp.buf.definition, "[G]o to [d]efinition")
|
2023-12-16 19:40:08 +01:00
|
|
|
nmap("<leader>gi", vim.lsp.buf.implementation, "[G]o to [i]mplementation")
|
|
|
|
nmap("<leader>gr", vim.lsp.buf.references, "[G]o to [r]eferences")
|
2023-01-10 02:38:06 +01:00
|
|
|
-- }}}
|
|
|
|
-- {{{ Hover
|
|
|
|
-- Note: diagnostics are already covered in keymaps.lua
|
2023-04-17 15:19:41 +02:00
|
|
|
if client.supports_method("textDocument/hover") then
|
|
|
|
nmap("K", vim.lsp.buf.hover, "Hover")
|
|
|
|
end
|
2023-01-10 02:38:06 +01:00
|
|
|
nmap("L", vim.lsp.buf.signature_help, "Signature help")
|
|
|
|
-- }}}
|
|
|
|
-- {{{ Code actions
|
|
|
|
nmap("<leader>c", vim.lsp.buf.code_action, "[C]ode actions")
|
|
|
|
nmap("<leader>li", "<cmd>LspInfo<cr>", "[L]sp [i]nfo")
|
|
|
|
|
|
|
|
vim.keymap.set("n", "<leader>rn", function()
|
|
|
|
return ":IncRename " .. vim.fn.expand("<cword>")
|
|
|
|
end, helpers.mergeTables(opts("[R]e[n]ame"), { expr = true }))
|
|
|
|
|
|
|
|
vim.keymap.set(
|
|
|
|
"v",
|
|
|
|
"<leader>c",
|
|
|
|
":'<,'> lua vim.lsp.buf.range_code_action()",
|
|
|
|
opts("[C]ode actions")
|
|
|
|
)
|
|
|
|
-- }}}
|
|
|
|
-- {{{ Workspace stuff
|
|
|
|
nmap(
|
|
|
|
"<leader>wa",
|
|
|
|
vim.lsp.buf.add_workspace_folder,
|
|
|
|
"[W]orkspace [A]dd Folder"
|
|
|
|
)
|
|
|
|
nmap(
|
|
|
|
"<leader>wr",
|
|
|
|
vim.lsp.buf.remove_workspace_folder,
|
|
|
|
"[W]orkspace [R]emove Folder"
|
|
|
|
)
|
|
|
|
nmap("<leader>wl", function()
|
|
|
|
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
|
|
|
end, "[W]orkspace [L]ist Folders")
|
|
|
|
-- }}}
|
|
|
|
end
|
|
|
|
|
|
|
|
-- {{{ General server config
|
|
|
|
---@type lspconfig.options
|
2023-09-22 20:08:11 +02:00
|
|
|
---@diagnostic disable-next-line: missing-fields
|
2023-01-10 02:38:06 +01:00
|
|
|
local servers = {
|
|
|
|
-- {{{ Typescript
|
2023-09-22 20:08:11 +02:00
|
|
|
---@diagnostic disable-next-line: missing-fields
|
2023-01-10 02:38:06 +01:00
|
|
|
tsserver = {
|
|
|
|
on_attach = function(client, bufnr)
|
|
|
|
-- We handle formatting using null-ls and prettierd
|
|
|
|
client.server_capabilities.documentFormattingProvider = false
|
|
|
|
M.on_attach(client, bufnr)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
-- }}}
|
|
|
|
-- {{{ Purescript
|
|
|
|
purescriptls = {
|
|
|
|
settings = {
|
2023-09-22 20:08:11 +02:00
|
|
|
---@diagnostic disable-next-line: missing-fields
|
2023-01-10 02:38:06 +01:00
|
|
|
purescript = {
|
|
|
|
censorWarnings = { "UnusedName", "ShadowedName", "UserDefinedWarning" },
|
|
|
|
formatter = "purs-tidy",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
-- }}}
|
|
|
|
-- {{{ Lua
|
2023-03-30 02:54:57 +02:00
|
|
|
lua_ls = {
|
2023-01-10 02:38:06 +01:00
|
|
|
cmd = {
|
|
|
|
"lua-language-server",
|
|
|
|
"--logpath=/home/adrielus/.local/share/lua-language-server/log",
|
|
|
|
},
|
2023-03-30 02:54:57 +02:00
|
|
|
settings = {
|
2023-09-22 20:08:11 +02:00
|
|
|
---@diagnostic disable-next-line: missing-fields
|
2023-03-30 02:54:57 +02:00
|
|
|
Lua = {
|
2023-12-04 06:25:00 +01:00
|
|
|
---@diagnostic disable-next-line: missing-fields
|
|
|
|
format = {
|
2023-12-07 22:35:57 +01:00
|
|
|
enable = true,
|
2023-12-04 06:25:00 +01:00
|
|
|
},
|
2023-03-30 02:54:57 +02:00
|
|
|
-- Do not send telemetry data containing a randomized but unique identifier
|
|
|
|
telemetry = {
|
|
|
|
enable = false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-01-10 02:38:06 +01:00
|
|
|
},
|
|
|
|
-- }}}
|
|
|
|
-- {{{ Latex
|
|
|
|
texlab = {
|
|
|
|
settings = {
|
|
|
|
texlab = {
|
|
|
|
build = {
|
|
|
|
args = {
|
|
|
|
-- Here by default:
|
|
|
|
"-pdf",
|
|
|
|
"-interaction=nonstopmode",
|
|
|
|
"-synctex=1",
|
|
|
|
"%f",
|
|
|
|
-- Required for syntax highlighting inside the generated pdf aparently
|
|
|
|
"-shell-escape",
|
|
|
|
},
|
|
|
|
executable = "latexmk",
|
|
|
|
forwardSearchAfter = true,
|
|
|
|
onSave = true,
|
|
|
|
},
|
2023-04-25 15:35:09 +02:00
|
|
|
chktex = {
|
|
|
|
onOpenAndSave = true,
|
|
|
|
onEdit = true,
|
|
|
|
},
|
2023-01-10 02:38:06 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
-- }}}
|
2023-06-15 20:08:20 +02:00
|
|
|
-- {{{ Nix
|
2023-01-10 02:38:06 +01:00
|
|
|
rnix = {},
|
2023-04-13 19:06:57 +02:00
|
|
|
nil_ls = {},
|
2023-06-15 20:08:20 +02:00
|
|
|
nixd = {},
|
|
|
|
-- }}}
|
2023-09-22 20:08:11 +02:00
|
|
|
---@diagnostic disable-next-line: missing-fields
|
2023-01-10 02:38:06 +01:00
|
|
|
cssls = {},
|
2023-09-22 20:08:11 +02:00
|
|
|
---@diagnostic disable-next-line: missing-fields
|
2023-01-10 02:38:06 +01:00
|
|
|
jsonls = {},
|
|
|
|
dhall_lsp_server = {},
|
2023-05-18 01:56:19 +02:00
|
|
|
typst_lsp = {},
|
2023-09-22 20:08:11 +02:00
|
|
|
---@diagnostic disable-next-line: missing-fields
|
2023-08-19 21:13:34 +02:00
|
|
|
elmls = {},
|
2023-06-15 20:08:20 +02:00
|
|
|
-- {{{ Inactive
|
2023-03-30 02:54:57 +02:00
|
|
|
-- pylsp = {},
|
|
|
|
-- pyright = {},
|
2023-06-15 20:08:20 +02:00
|
|
|
-- }}}
|
2023-01-10 02:38:06 +01:00
|
|
|
}
|
|
|
|
-- }}}
|
|
|
|
-- {{{ Capabilities
|
|
|
|
M.capabilities = function()
|
|
|
|
local c = require("cmp_nvim_lsp").default_capabilities()
|
|
|
|
-- Add folding capabilities
|
2023-06-15 20:08:20 +02:00
|
|
|
c.textDocument.foldingRange = {
|
|
|
|
dynamicRegistration = false,
|
|
|
|
lineFoldingOnly = true,
|
|
|
|
}
|
|
|
|
|
2023-01-10 02:38:06 +01:00
|
|
|
return c
|
|
|
|
end
|
|
|
|
-- }}}
|
|
|
|
-- {{{ Nice diagnostic icons
|
|
|
|
-- See https://github.com/folke/dot/blob/master/config/nvim/lua/config/plugins/lsp/diagnostics.lua
|
|
|
|
local function diagnostics_icons()
|
|
|
|
local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " }
|
|
|
|
|
|
|
|
for type, icon in pairs(signs) do
|
|
|
|
local hl = "DiagnosticSign" .. type
|
|
|
|
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--}}}
|
|
|
|
-- {{{ Main config function
|
|
|
|
function lspconfig.config()
|
|
|
|
diagnostics_icons()
|
2023-01-22 01:22:38 +01:00
|
|
|
-- -- {{{ Change on-hover borders
|
2023-08-14 13:49:55 +02:00
|
|
|
vim.lsp.handlers["textDocument/hover"] =
|
2023-12-07 22:35:57 +01:00
|
|
|
vim.lsp.with(vim.lsp.handlers.hover, { border = "single" })
|
2023-08-14 13:49:55 +02:00
|
|
|
vim.lsp.handlers["textDocument/signatureHelp"] =
|
2023-12-07 22:35:57 +01:00
|
|
|
vim.lsp.with(vim.lsp.handlers.signature_help, { border = "single" })
|
2023-01-22 01:22:38 +01:00
|
|
|
-- -- }}}
|
2023-01-10 02:38:06 +01:00
|
|
|
|
|
|
|
local capabilities = M.capabilities()
|
|
|
|
-- Setup basic language servers
|
|
|
|
for lsp, details in pairs(servers) do
|
|
|
|
if details.on_attach == nil then
|
|
|
|
-- Default setting for on_attach
|
|
|
|
details.on_attach = M.on_attach
|
|
|
|
end
|
|
|
|
|
|
|
|
require("lspconfig")[lsp].setup({
|
|
|
|
on_attach = details.on_attach,
|
2023-12-07 22:35:57 +01:00
|
|
|
settings = details.settings, -- Specific per-language settings
|
2023-01-10 02:38:06 +01:00
|
|
|
flags = {
|
|
|
|
debounce_text_changes = 150, -- This will be the default in neovim 0.7+
|
|
|
|
},
|
|
|
|
cmd = details.cmd,
|
|
|
|
capabilities = capabilities,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--}}}
|
|
|
|
|
|
|
|
return M
|