342 lines
11 KiB
Lua
342 lines
11 KiB
Lua
return {
|
|
{
|
|
"neovim/nvim-lspconfig",
|
|
lazy = true,
|
|
event = { "BufReadPre", "BufNewFile" },
|
|
dependencies = {
|
|
{ "folke/neoconf.nvim", cmd = "Neoconf", config = false, dependencies = { "nvim-lspconfig" } },
|
|
{ "folke/neodev.nvim", opts = { experimental = { pathStrict = true } } },
|
|
"mason.nvim",
|
|
"williamboman/mason-lspconfig.nvim",
|
|
"mfussenegger/nvim-jdtls",
|
|
{
|
|
"hrsh7th/cmp-nvim-lsp",
|
|
cond = function()
|
|
return require("lazyvim.util").has("nvim-cmp")
|
|
end,
|
|
},
|
|
{ "Hoffs/omnisharp-extended-lsp.nvim", lazy = true },
|
|
},
|
|
---@class PluginLspOpts
|
|
opts = {
|
|
-- options for vim.diagnostic.config()
|
|
diagnostics = {
|
|
underline = true,
|
|
update_in_insert = false,
|
|
virtual_text = { spacing = 4, source = "if_many", prefix = "●" },
|
|
severity_sort = true,
|
|
},
|
|
inlay_hints = {
|
|
enabled = true,
|
|
},
|
|
capabilities = {},
|
|
autoformat = false,
|
|
format_notify = false,
|
|
format = {
|
|
formatting_options = nil,
|
|
timeout_ms = nil,
|
|
},
|
|
-- LSP Server Settings
|
|
---@type lspconfig.options
|
|
servers = {
|
|
jsonls = {},
|
|
tailwindcss = {},
|
|
cssls = {},
|
|
html = {},
|
|
clangd = {
|
|
root_pattern = {
|
|
".clangd",
|
|
".clang-tidy",
|
|
".clang-format",
|
|
"compile_commands.json",
|
|
"compile_flags.txt",
|
|
"configure.ac",
|
|
".git",
|
|
"build/compile_commands.json",
|
|
},
|
|
filetypes = {
|
|
"c",
|
|
"cpp",
|
|
"objc",
|
|
"objcpp",
|
|
"cuda",
|
|
"proto",
|
|
"cl",
|
|
},
|
|
},
|
|
pyright = {},
|
|
cmake = {},
|
|
bashls = {},
|
|
ansiblels = {},
|
|
marksman = {},
|
|
asm_lsp = {},
|
|
omnisharp = {
|
|
handlers = {
|
|
["textDocument/definition"] = function(...)
|
|
return require("omnisharp_extended").handler(...)
|
|
end,
|
|
},
|
|
inlayHintsOptions = {
|
|
enableForParameters = true,
|
|
forLiteralParameters = true,
|
|
forIndexerParameters = true,
|
|
forObjectCreationParameters = true,
|
|
forOtherParameters = true,
|
|
suppressForParametersThatDifferOnlyBySuffix = false,
|
|
suppressForParametersThatMatchMethodIntent = false,
|
|
suppressForParametersThatMatchArgumentName = false,
|
|
enableForTypes = true,
|
|
forImplicitVariableTypes = true,
|
|
forLambdaParameterTypes = true,
|
|
forImplicitObjectCreation = true,
|
|
},
|
|
enable_roslyn_analyzers = true,
|
|
organize_imports_on_format = true,
|
|
enable_import_completion = true,
|
|
},
|
|
rnix = {},
|
|
rust_analyzer = {
|
|
diagnostics = {
|
|
enable = true,
|
|
experimental = true,
|
|
},
|
|
},
|
|
tsserver = {
|
|
settings = {
|
|
typescript = {
|
|
inlayHints = {
|
|
includeInlayParameterNameHints = "all",
|
|
includeInlayParameterNameHintsWhenArgumentMatchesName = true,
|
|
includeInlayFunctionParameterTypeHints = true,
|
|
includeInlayVariableTypeHints = true,
|
|
includeInlayPropertyDeclarationTypeHints = true,
|
|
includeInlayFunctionLikeReturnTypeHints = true,
|
|
includeInlayEnumMemberValueHints = true,
|
|
},
|
|
},
|
|
javascript = {
|
|
inlayHints = {
|
|
includeInlayParameterNameHints = "all",
|
|
includeInlayParameterNameHintsWhenArgumentMatchesName = true,
|
|
includeInlayFunctionParameterTypeHints = true,
|
|
includeInlayVariableTypeHints = true,
|
|
includeInlayPropertyDeclarationTypeHints = true,
|
|
includeInlayFunctionLikeReturnTypeHints = true,
|
|
includeInlayEnumMemberValueHints = true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
typst_lsp = {
|
|
settings = {
|
|
experimentalFormatterMode = "on",
|
|
exportPdf = "onSave",
|
|
},
|
|
},
|
|
texlab = {},
|
|
ltex = {
|
|
settings = {
|
|
ltex = {
|
|
checkFrequency = "save",
|
|
},
|
|
},
|
|
filetypes = {
|
|
"bib",
|
|
"gitcommit",
|
|
"markdown",
|
|
"org",
|
|
"plaintex",
|
|
"rst",
|
|
"rnoweb",
|
|
"tex",
|
|
"pandoc",
|
|
"typst",
|
|
"typ",
|
|
},
|
|
},
|
|
gopls = {
|
|
staticcheck = true,
|
|
},
|
|
sqlls = {},
|
|
taplo = {},
|
|
lemminx = {},
|
|
opencl_ls = {},
|
|
yamlls = {},
|
|
lua_ls = {
|
|
-- mason = false, -- set to false if you don't want this server to be installed with mason
|
|
settings = {
|
|
Lua = {
|
|
workspace = {
|
|
checkThirdParty = false,
|
|
},
|
|
completion = {
|
|
callSnippet = "Replace",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
setup = {
|
|
jdtls = function()
|
|
return true
|
|
end,
|
|
},
|
|
},
|
|
config = function(_, opts)
|
|
local Util = require("lazyvim.util")
|
|
|
|
if Util.has("neoconf.nvim") then
|
|
local plugin = require("lazy.core.config").spec.plugins["neoconf.nvim"]
|
|
require("neoconf").setup(require("lazy.core.plugin").values(plugin, "opts", false))
|
|
end
|
|
|
|
-- setup autoformat
|
|
Util.format.register(Util.lsp.formatter())
|
|
|
|
-- deprectaed options
|
|
if opts.autoformat ~= nil then
|
|
vim.g.autoformat = opts.autoformat
|
|
end
|
|
|
|
-- setup formatting and keymaps
|
|
Util.lsp.on_attach(function(client, buffer)
|
|
require("config.lsp-keymap").on_attach(client, buffer)
|
|
end)
|
|
|
|
local register_capability = vim.lsp.handlers["client/registerCapability"]
|
|
|
|
vim.lsp.handlers["client/registerCapability"] = function(err, res, ctx)
|
|
local ret = register_capability(err, res, ctx)
|
|
local client_id = ctx.client_id
|
|
---@type lsp.Client
|
|
local client = vim.lsp.get_client_by_id(client_id)
|
|
local buffer = vim.api.nvim_get_current_buf()
|
|
require("config.lsp-keymap").on_attach(client, buffer)
|
|
return ret
|
|
end
|
|
|
|
-- diagnostics
|
|
for name, icon in pairs(require("lazyvim.config").icons.diagnostics) do
|
|
name = "DiagnosticSign" .. name
|
|
vim.fn.sign_define(name, { text = icon, texthl = name, numhl = "" })
|
|
end
|
|
|
|
local inlay_hint = vim.lsp.buf.inlay_hint or vim.lsp.inlay_hint
|
|
|
|
if opts.inlay_hints.enabled and inlay_hint then
|
|
Util.lsp.on_attach(function(client, buffer)
|
|
if client.supports_method("textDocument/inlayHint") then
|
|
inlay_hint(buffer, true)
|
|
end
|
|
end)
|
|
end
|
|
|
|
if type(opts.diagnostics.virtual_text) == "table" and opts.diagnostics.virtual_text.prefix == "icons" then
|
|
opts.diagnostics.virtual_text.prefix = vim.fn.has("nvim-0.10.0") == 0 and "●"
|
|
or function(diagnostic)
|
|
local icons = require("lazyvim.config").icons.diagnostics
|
|
for d, icon in pairs(icons) do
|
|
if diagnostic.severity == vim.diagnostic.severity[d:upper()] then
|
|
return icon
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
vim.diagnostic.config(vim.deepcopy(opts.diagnostics))
|
|
|
|
local servers = opts.servers
|
|
local has_cmp, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
|
|
local capabilities = vim.tbl_deep_extend(
|
|
"force",
|
|
{},
|
|
vim.lsp.protocol.make_client_capabilities(),
|
|
has_cmp and cmp_nvim_lsp.default_capabilities() or {},
|
|
opts.capabilities or {}
|
|
)
|
|
|
|
local function setup(server)
|
|
local server_opts = vim.tbl_deep_extend("force", {
|
|
capabilities = vim.deepcopy(capabilities),
|
|
}, servers[server] or {})
|
|
|
|
if opts.setup[server] then
|
|
if opts.setup[server](server, server_opts) then
|
|
return
|
|
end
|
|
elseif opts.setup["*"] then
|
|
if opts.setup["*"](server, server_opts) then
|
|
return
|
|
end
|
|
end
|
|
require("lspconfig")[server].setup(server_opts)
|
|
end
|
|
|
|
-- get all the servers that are available through mason-lspconfig
|
|
local have_mason, mlsp = pcall(require, "mason-lspconfig")
|
|
local all_mslp_servers = {}
|
|
if have_mason then
|
|
all_mslp_servers = vim.tbl_keys(require("mason-lspconfig.mappings.server").lspconfig_to_package)
|
|
end
|
|
|
|
local ensure_installed = {} ---@type string[]
|
|
for server, server_opts in pairs(servers) do
|
|
if server_opts then
|
|
server_opts = server_opts == true and {} or server_opts
|
|
-- run manual setup if mason=false or if this is a server that cannot be installed with mason-lspconfig
|
|
if server_opts.mason == false or not vim.tbl_contains(all_mslp_servers, server) then
|
|
setup(server)
|
|
else
|
|
ensure_installed[#ensure_installed + 1] = server
|
|
end
|
|
end
|
|
end
|
|
|
|
if have_mason then
|
|
mlsp.setup({ ensure_installed = ensure_installed, handlers = { setup } })
|
|
end
|
|
|
|
if Util.lsp.get_config("denols") and Util.lsp.get_config("tsserver") then
|
|
local is_deno = require("lspconfig.util").root_pattern("deno.json", "deno.jsonc")
|
|
Util.lsp.disable("tsserver", is_deno)
|
|
Util.lsp.disable("denols", function(root_dir)
|
|
return not is_deno(root_dir)
|
|
end)
|
|
end
|
|
|
|
require("lspconfig").ltex.setup({
|
|
capabilities = capabilities,
|
|
on_attach = Util.lsp.on_attach(function(client, buffer)
|
|
require("config.lsp-keymap").on_attach(client, buffer)
|
|
require("ltex_extra").setup({
|
|
path = vim.fn.expand("~") .. "/.local/share/ltex",
|
|
})
|
|
end),
|
|
})
|
|
|
|
vim.cmd([[highlight LspInlayHint guibg=#1A1B26]])
|
|
end,
|
|
},
|
|
{
|
|
"DashieTM/null.nvim",
|
|
event = { "BufReadPre", "BufNewFile" },
|
|
dependencies = { "mason.nvim" },
|
|
opts = function()
|
|
local nls = require("null-ls")
|
|
return {
|
|
root_dir = require("null-ls.utils").root_pattern(".null-ls-root", ".neoconf.json", "Makefile", ".git"),
|
|
|
|
sources = {
|
|
nls.builtins.formatting.fish_indent,
|
|
nls.builtins.diagnostics.fish,
|
|
nls.builtins.formatting.stylua,
|
|
nls.builtins.formatting.shfmt,
|
|
nls.builtins.diagnostics.flake8,
|
|
nls.builtins.formatting.autopep8,
|
|
nls.builtins.formatting.prettierd,
|
|
nls.builtins.formatting.typst,
|
|
},
|
|
}
|
|
end,
|
|
},
|
|
}
|