1
Fork 0
satellite/dotfiles/neovim/lua/my/plugins/lspconfig.lua

192 lines
4.9 KiB
Lua
Raw Normal View History

2022-12-27 20:45:43 +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,
},
"hrsh7th/cmp-nvim-lsp",
},
cond = env.vscode.not_active(),
}
local M = {
lspconfig,
{
"smjonas/inc-rename.nvim",
cmd = "IncRename",
config = {
input_buffer_type = "dressing",
},
dependencies = {
"dressing.nvim",
},
cond = env.vscode.not_active(),
},
}
2022-01-31 21:41:13 +01:00
2022-03-09 19:44:21 +01:00
function M.on_attach(client, bufnr)
2022-12-26 20:07:10 +01:00
-- {{{ Auto format
local function format()
vim.lsp.buf.format({ async = false, bufnr = bufnr })
end
2022-01-31 21:41:13 +01:00
2022-12-26 20:07:10 +01:00
if false and client.supports_method("textDocument/formatting") then
vim.api.nvim_create_autocmd("BufWritePre", {
2022-12-26 20:07:10 +01:00
group = vim.api.nvim_create_augroup("LspFormatting", { clear = false }),
2022-10-09 03:28:51 +02:00
buffer = bufnr,
2022-12-26 20:07:10 +01:00
callback = format,
})
2022-07-19 20:19:36 +02:00
end
2022-12-26 20:07:10 +01:00
-- }}}
-- {{{ Keymap helpers
2022-10-09 03:28:51 +02:00
local opts = function(desc)
2022-12-27 20:45:43 +01:00
return { noremap = true, silent = true, desc = desc, buffer = bufnr }
2022-10-09 03:28:51 +02:00
end
2022-12-26 20:07:10 +01:00
local nmap = function(from, to, desc)
vim.keymap.set("n", from, to, opts(desc))
end
-- }}}
-- {{{ Go to declaration / definition / implementation
nmap("gd", vim.lsp.buf.definition, "[G]o to [d]efinition")
nmap("gi", vim.lsp.buf.implementation, "[G]o to [i]mplementation")
nmap("gr", vim.lsp.buf.references, "[G]o to [r]eferences")
-- }}}
-- {{{ Hover
-- Note: diagnostics are already covered in keymaps.lua
nmap("K", vim.lsp.buf.hover, "Hover")
nmap("L", vim.lsp.buf.signature_help, "Signature help")
-- }}}
-- {{{ Code actions
nmap("<leader>c", vim.lsp.buf.code_action, "[C]ode actions")
2022-12-27 20:45:43 +01:00
nmap("<leader>F", format, "[F]ormat")
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 }))
2022-07-19 20:19:36 +02:00
2022-12-26 20:07:10 +01:00
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")
-- }}}
2022-05-10 14:28:36 +02:00
end
2022-12-26 20:07:10 +01:00
-- {{{ General server config
2022-12-14 03:20:59 +01:00
---@type lspconfig.options
2022-02-01 15:18:36 +01:00
local servers = {
2022-11-14 01:16:10 +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)
2022-12-26 20:07:10 +01:00
end,
2022-11-14 01:16:10 +01:00
},
2022-07-19 20:19:36 +02:00
dhall_lsp_server = {},
purescriptls = {
settings = {
purescript = {
2022-11-14 01:16:10 +01:00
censorWarnings = { "UnusedName", "ShadowedName", "UserDefinedWarning" },
2022-12-26 20:07:10 +01:00
formatter = "purs-tidy",
},
},
2022-07-19 20:19:36 +02:00
},
hls = {
haskell = {
-- set formatter
2022-12-26 20:07:10 +01:00
formattingProvider = "ormolu",
},
2022-07-19 20:19:36 +02:00
},
rnix = {},
cssls = {},
2022-12-14 03:20:59 +01:00
jsonls = {},
rust_analyzer = {},
2022-12-26 20:07:10 +01:00
-- teal_ls = {},
2022-12-14 03:20:59 +01:00
sumneko_lua = {
2022-12-26 20:07:10 +01:00
cmd = {
"lua-language-server",
"--logpath=/home/adrielus/.local/share/lua-language-server/log",
},
},
2022-02-01 15:18:36 +01:00
}
2022-12-26 20:07:10 +01:00
-- }}}
-- {{{ Capabilities
2022-12-27 20:45:43 +01:00
M.capabilities = function()
-- require("lazy").load({ plugins = "hrsh7th/cmp-nvim-lsp" })
local c = require("cmp_nvim_lsp").default_capabilities()
-- Add folding capabilities
c.textDocument.foldingRange =
{ dynamicRegistration = false, lineFoldingOnly = true }
return c
end
2022-12-26 20:07:10 +01:00
-- }}}
2022-12-27 20:45:43 +01:00
-- {{{ 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 = "" }
2022-12-27 20:45:43 +01:00
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()
2022-12-26 20:07:10 +01:00
-- {{{ Change on-hover borders
vim.lsp.handlers["textDocument/hover"] =
vim.lsp.with(vim.lsp.handlers.hover, { border = "single" })
2022-12-05 01:18:31 +01:00
vim.lsp.handlers["textDocument/signatureHelp"] =
2022-12-26 20:07:10 +01:00
vim.lsp.with(vim.lsp.handlers.signature_help, { border = "single" })
-- }}}
2022-07-19 20:19:36 +02:00
2022-12-27 20:45:43 +01:00
local capabilities = M.capabilities()
2022-07-19 20:19:36 +02:00
-- 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
2022-01-31 21:41:13 +01:00
end
2022-07-19 20:19:36 +02:00
2022-12-26 20:07:10 +01:00
require("lspconfig")[lsp].setup({
2022-07-19 20:19:36 +02:00
on_attach = details.on_attach,
settings = details.settings, -- Specific per-language settings
flags = {
2022-12-26 20:07:10 +01:00
debounce_text_changes = 150, -- This will be the default in neovim 0.7+
2022-07-19 20:19:36 +02:00
},
cmd = details.cmd,
2022-12-27 20:45:43 +01:00
capabilities = capabilities,
2022-12-26 20:07:10 +01:00
})
2022-07-19 20:19:36 +02:00
end
2022-01-31 21:41:13 +01:00
end
2022-12-27 20:45:43 +01:00
--}}}
2022-02-01 00:06:48 +01:00
return M