dotfiles/modules/programs/nvim/plugins/nvim-lspconfig.lua

167 lines
4.7 KiB
Lua
Raw Normal View History

2023-02-18 16:25:09 +01:00
local lsp_lines = require("lsp_lines")
lsp_lines.setup()
-- Disable virtual_text since it's redundant due to lsp_lines.
vim.diagnostic.config({
virtual_text = false,
})
vim.o.foldcolumn = "1" -- '0' is not bad
vim.o.foldlevel = 99 -- Using ufo provider need a large value, feel free to decrease the value
vim.o.foldlevelstart = 99
vim.o.foldenable = true
vim.o.fillchars = [[eob: ,fold: ,foldopen:,foldsep: ,foldclose:]]
vim.o.statuscolumn = "%= "
-- FIXME: figure out how to put on the other side without having to do a lot of shifting
.. "%s" -- sign column
.. "%{%" -- evaluate this, and then evaluate what it returns
.. "&number ?"
.. "(v:relnum ?"
-- when showing relative numbers, make sure to pad so things don't shift as you move the cursor
.. 'printf("%"..len(line("$")).."s", v:relnum)'
.. ":"
.. "v:lnum"
.. ")"
.. ":"
.. '""'
.. " " -- space between lines and fold
.. "%}"
.. "%= "
.. "%#FoldColumn#" -- highlight group for fold
.. "%{" -- expression for showing fold expand/colapse
.. "foldlevel(v:lnum) > foldlevel(v:lnum - 1)" -- any folds?
.. "? (foldclosed(v:lnum) == -1" -- currently open?
.. '? ""' -- point down
.. ': ""' -- point to right
.. ")"
.. ': " "' -- blank for no fold, or inside fold
.. "}"
.. "%= " -- spacing between end of column and start of text
-- Using ufo provider need remap `zR` and `zM`. If Neovim is 0.6.1, remap yourself
2023-03-26 18:28:49 +02:00
require("which-key").register({
z = {
R = { require("ufo").openAllFolds, "Open all folds" },
M = { require("ufo").closeAllFolds, "Close all folds" },
},
})
2023-07-24 18:44:03 +02:00
local capabilities = vim.lsp.protocol.make_client_capabilities()
-- Tell the server the capability of foldingRange,
-- Neovim hasn't added foldingRange to default capabilities, users must add it manually
capabilities.textDocument.foldingRange = {
dynamicRegistration = false,
lineFoldingOnly = true,
}
require("ufo").setup()
2023-02-18 13:35:11 +01:00
local lspconfig = require("lspconfig")
2023-02-18 16:25:09 +01:00
local on_attach_def = function(_, bufnr)
2023-03-26 18:28:49 +02:00
require("which-key").register({
2023-08-11 17:38:26 +02:00
K = { vim.lsp.buf.hover, "Hover" },
2023-02-18 16:25:09 +01:00
["<leader>"] = {
l = {
2023-08-11 17:38:26 +02:00
d = { vim.diagnostic.open_float, "Open diagnostic window" },
c = { vim.lsp.buf.code_action, "Code action" },
r = { vim.lsp.buf.rename, "Rename" },
2023-02-18 16:25:09 +01:00
f = {
2023-02-18 13:35:11 +01:00
function()
vim.lsp.buf.format({ async = true })
end,
2023-08-11 17:38:26 +02:00
"Format (lsp)",
2023-02-18 16:25:09 +01:00
mode = { "n", "v" },
2023-02-18 13:35:11 +01:00
},
2023-02-18 16:25:09 +01:00
},
t = {
2023-08-11 17:38:26 +02:00
l = { lsp_lines.toggle, "Lsp lines" },
2023-02-18 16:25:09 +01:00
},
2023-02-18 13:35:11 +01:00
},
g = {
2023-08-11 17:38:26 +02:00
d = {
function()
require("telescope.builtin").lsp_definitions({ reuse_win = true })
end,
"Goto definition",
},
t = {
function()
require("telescope.builtin").lsp_type_definitions({ reuse_win = true })
end,
"Goto type defininition",
},
r = { "<cmd>Telescope lsp_references<cr>", "Goto references" },
2023-04-09 19:31:14 +02:00
D = { vim.lsp.buf.declaration, "Goto declaration" },
I = { "<cmd>Telescope lsp_implementations<cr>", "Goto implementation" },
2023-08-11 17:38:26 +02:00
K = { vim.lsp.buf.signature_help, "Signature help" },
2023-04-09 19:31:14 +02:00
},
["["] = {
2023-08-11 17:38:26 +02:00
d = { vim.diagnostic.goto_prev, "Previous diagnostic" },
2023-04-09 19:31:14 +02:00
},
["]"] = {
2023-08-11 17:38:26 +02:00
d = { vim.diagnostic.goto_next, "Next diagnostic" },
2023-02-18 13:35:11 +01:00
},
2023-02-18 17:55:20 +01:00
}, { buffer = bufnr, silent = true })
2023-02-18 13:35:11 +01:00
end
2023-02-17 22:09:13 +01:00
local lspconfig_default_options = {
on_attach = on_attach_def,
capabilities = capabilities,
}
---function to add default options to lspconfig
---@param lsp string
---@param options table
---@return nil
local function lspconfig_setup(lsp, options)
2023-07-24 18:44:03 +02:00
local coq_options = require("coq").lsp_ensure_capabilities({})
local merged_options = vim.tbl_deep_extend("force", coq_options, lspconfig_default_options, options)
lspconfig[lsp].setup(merged_options)
2023-02-17 12:38:44 +01:00
end
2023-03-13 09:07:50 +01:00
local servers = {
"bashls",
"nil_ls",
"pylsp",
"ruff_lsp",
2023-06-25 11:15:08 +02:00
"typst_lsp",
2023-07-29 17:06:33 +02:00
"gopls",
2023-03-13 09:07:50 +01:00
}
2023-02-17 12:38:44 +01:00
for _, lsp in ipairs(servers) do
2023-02-17 22:09:13 +01:00
lspconfig_setup(lsp, {})
2023-02-17 12:38:44 +01:00
end
lspconfig_setup("rust_analyzer", {
settings = {
["rust-analyzer"] = {
checkOnSave = {
command = "clippy",
},
},
},
})
2023-02-17 22:09:13 +01:00
lspconfig_setup("lua_ls", {
settings = {
Lua = {
runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = "LuaJIT",
},
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = { "vim" },
},
workspace = {
-- Make the server aware of Neovim runtime files
library = vim.api.nvim_get_runtime_file("", true),
checkThirdParty = false,
},
-- Do not send telemetry data containing a randomized but unique identifier
telemetry = {
enable = false,
},
format = {
enable = false,
},
},
},
2023-02-17 12:38:44 +01:00
})