perf(util): split lazyvim.util in smaller separate modules

This commit is contained in:
Folke Lemaitre 2023-10-10 19:29:24 +02:00
parent 5f5acb5b88
commit c8c929c9fd
20 changed files with 442 additions and 283 deletions

View file

@ -1,3 +1,5 @@
local Util = require("lazyvim.util")
return {
-- lspconfig
{
@ -88,6 +90,8 @@ return {
require("lazyvim.plugins.lsp.format").setup(opts)
-- setup formatting and keymaps
Util.on_attach(function(client, buffer)
-- setup keymaps
Util.lsp.on_attach(function(client, buffer)
require("lazyvim.plugins.lsp.keymaps").on_attach(client, buffer)
end)
@ -112,7 +116,7 @@ return {
local inlay_hint = vim.lsp.buf.inlay_hint or vim.lsp.inlay_hint
if opts.inlay_hints.enabled and inlay_hint then
Util.on_attach(function(client, buffer)
Util.lsp.on_attach(function(client, buffer)
if client.supports_method("textDocument/inlayHint") then
inlay_hint(buffer, true)
end
@ -184,10 +188,10 @@ return {
mlsp.setup({ ensure_installed = ensure_installed, handlers = { setup } })
end
if Util.lsp_get_config("denols") and Util.lsp_get_config("tsserver") then
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)
Util.lsp.disable("tsserver", is_deno)
Util.lsp.disable("denols", function(root_dir)
return not is_deno(root_dir)
end)
end
@ -208,7 +212,6 @@ return {
nls.builtins.diagnostics.fish,
nls.builtins.formatting.stylua,
nls.builtins.formatting.shfmt,
-- nls.builtins.diagnostics.flake8,
},
}
end,

View file

@ -66,7 +66,7 @@ end
---@param method string
function M.has(buffer, method)
method = method:find("/") and method or "textDocument/" .. method
local clients = require("lazyvim.util").get_clients({ bufnr = buffer })
local clients = require("lazyvim.util").lsp.get_clients({ bufnr = buffer })
for _, client in ipairs(clients) do
if client.supports_method(method) then
return true
@ -83,7 +83,7 @@ function M.resolve(buffer)
end
local spec = M.get()
local opts = require("lazyvim.util").opts("nvim-lspconfig")
local clients = require("lazyvim.util").get_clients({ bufnr = buffer })
local clients = require("lazyvim.util").lsp.get_clients({ bufnr = buffer })
for _, client in ipairs(clients) do
local maps = opts.servers[client.name] and opts.servers[client.name].keys or {}
vim.list_extend(spec, maps)