mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-22 04:21:08 +00:00
refactor(lsp): remove LazyVim.lsp.get_clients
This commit is contained in:
parent
9fa832dc95
commit
f4e64eea45
6 changed files with 11 additions and 20 deletions
|
|
@ -49,7 +49,7 @@ return {
|
||||||
opts.sections.lualine_x,
|
opts.sections.lualine_x,
|
||||||
2,
|
2,
|
||||||
LazyVim.lualine.status(LazyVim.config.icons.kinds.Copilot, function()
|
LazyVim.lualine.status(LazyVim.config.icons.kinds.Copilot, function()
|
||||||
local clients = package.loaded["copilot"] and LazyVim.lsp.get_clients({ name = "copilot", bufnr = 0 }) or {}
|
local clients = package.loaded["copilot"] and vim.lsp.get_clients({ name = "copilot", bufnr = 0 }) or {}
|
||||||
if #clients > 0 then
|
if #clients > 0 then
|
||||||
local status = require("copilot.status").data.status
|
local status = require("copilot.status").data.status
|
||||||
return (status == "InProgress" and "pending") or (status == "Warning" and "error") or "ok"
|
return (status == "InProgress" and "pending") or (status == "Warning" and "error") or "ok"
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,7 @@ return {
|
||||||
-- height is number of items minus 15 lines for the preview, with a max of 80% screen height
|
-- height is number of items minus 15 lines for the preview, with a max of 80% screen height
|
||||||
height = math.floor(math.min(vim.o.lines * 0.8 - 16, #items + 2) + 0.5) + 16,
|
height = math.floor(math.min(vim.o.lines * 0.8 - 16, #items + 2) + 0.5) + 16,
|
||||||
width = 0.5,
|
width = 0.5,
|
||||||
preview = not vim.tbl_isempty(LazyVim.lsp.get_clients({ bufnr = 0, name = "vtsls" })) and {
|
preview = not vim.tbl_isempty(vim.lsp.get_clients({ bufnr = 0, name = "vtsls" })) and {
|
||||||
layout = "vertical",
|
layout = "vertical",
|
||||||
vertical = "down:15,border-top",
|
vertical = "down:15,border-top",
|
||||||
hidden = "hidden",
|
hidden = "hidden",
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ return {
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_client(buf)
|
local function get_client(buf)
|
||||||
return LazyVim.lsp.get_clients({ name = "eslint", bufnr = buf })[1]
|
return vim.lsp.get_clients({ name = "eslint", bufnr = buf })[1]
|
||||||
end
|
end
|
||||||
|
|
||||||
local formatter = LazyVim.lsp.formatter({
|
local formatter = LazyVim.lsp.formatter({
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ function M.has(buffer, method)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
method = method:find("/") and method or "textDocument/" .. method
|
method = method:find("/") and method or "textDocument/" .. method
|
||||||
local clients = LazyVim.lsp.get_clients({ bufnr = buffer })
|
local clients = vim.lsp.get_clients({ bufnr = buffer })
|
||||||
for _, client in ipairs(clients) do
|
for _, client in ipairs(clients) do
|
||||||
if client:supports_method(method) then
|
if client:supports_method(method) then
|
||||||
return true
|
return true
|
||||||
|
|
@ -69,7 +69,7 @@ function M.resolve(buffer)
|
||||||
end
|
end
|
||||||
local spec = vim.tbl_extend("force", {}, M.get())
|
local spec = vim.tbl_extend("force", {}, M.get())
|
||||||
local opts = LazyVim.opts("nvim-lspconfig")
|
local opts = LazyVim.opts("nvim-lspconfig")
|
||||||
local clients = LazyVim.lsp.get_clients({ bufnr = buffer })
|
local clients = vim.lsp.get_clients({ bufnr = buffer })
|
||||||
for _, client in ipairs(clients) do
|
for _, client in ipairs(clients) do
|
||||||
local maps = opts.servers[client.name] and opts.servers[client.name].keys or {}
|
local maps = opts.servers[client.name] and opts.servers[client.name].keys or {}
|
||||||
vim.list_extend(spec, maps)
|
vim.list_extend(spec, maps)
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,6 @@
|
||||||
---@class lazyvim.util.lsp
|
---@class lazyvim.util.lsp
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
---@alias lsp.Client.filter {id?: number, bufnr?: number, name?: string, method?: string, filter?:fun(client: vim.lsp.Client):boolean}
|
|
||||||
|
|
||||||
---@param opts? lsp.Client.filter
|
|
||||||
function M.get_clients(opts)
|
|
||||||
local ret = {} ---@type vim.lsp.Client[]
|
|
||||||
ret = vim.lsp.get_clients(opts)
|
|
||||||
return opts and opts.filter and vim.tbl_filter(opts.filter, ret) or ret
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param on_attach fun(client:vim.lsp.Client, buffer)
|
---@param on_attach fun(client:vim.lsp.Client, buffer)
|
||||||
---@param name? string
|
---@param name? string
|
||||||
function M.on_attach(on_attach, name)
|
function M.on_attach(on_attach, name)
|
||||||
|
|
@ -107,12 +98,12 @@ function M.on_supports_method(method, fn)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param opts? LazyFormatter| {filter?: (string|lsp.Client.filter)}
|
---@param opts? LazyFormatter| {filter?: (string|vim.lsp.get_clients.Filter)}
|
||||||
function M.formatter(opts)
|
function M.formatter(opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
local filter = opts.filter or {}
|
local filter = opts.filter or {}
|
||||||
filter = type(filter) == "string" and { name = filter } or filter
|
filter = type(filter) == "string" and { name = filter } or filter
|
||||||
---@cast filter lsp.Client.filter
|
---@cast filter vim.lsp.get_clients.Filter
|
||||||
---@type LazyFormatter
|
---@type LazyFormatter
|
||||||
local ret = {
|
local ret = {
|
||||||
name = "LSP",
|
name = "LSP",
|
||||||
|
|
@ -122,7 +113,7 @@ function M.formatter(opts)
|
||||||
M.format(LazyVim.merge({}, filter, { bufnr = buf }))
|
M.format(LazyVim.merge({}, filter, { bufnr = buf }))
|
||||||
end,
|
end,
|
||||||
sources = function(buf)
|
sources = function(buf)
|
||||||
local clients = M.get_clients(LazyVim.merge({}, filter, { bufnr = buf }))
|
local clients = vim.lsp.get_clients(LazyVim.merge({}, filter, { bufnr = buf }))
|
||||||
---@param client vim.lsp.Client
|
---@param client vim.lsp.Client
|
||||||
local ret = vim.tbl_filter(function(client)
|
local ret = vim.tbl_filter(function(client)
|
||||||
return client:supports_method("textDocument/formatting")
|
return client:supports_method("textDocument/formatting")
|
||||||
|
|
@ -137,7 +128,7 @@ function M.formatter(opts)
|
||||||
return LazyVim.merge(ret, opts) --[[@as LazyFormatter]]
|
return LazyVim.merge(ret, opts) --[[@as LazyFormatter]]
|
||||||
end
|
end
|
||||||
|
|
||||||
---@alias lsp.Client.format {timeout_ms?: number, format_options?: table} | lsp.Client.filter
|
---@alias lsp.Client.format {timeout_ms?: number, format_options?: table} | vim.lsp.get_clients.Filter
|
||||||
|
|
||||||
---@param opts? lsp.Client.format
|
---@param opts? lsp.Client.format
|
||||||
function M.format(opts)
|
function M.format(opts)
|
||||||
|
|
|
||||||
|
|
@ -29,10 +29,10 @@ function M.detectors.lsp(buf)
|
||||||
return {}
|
return {}
|
||||||
end
|
end
|
||||||
local roots = {} ---@type string[]
|
local roots = {} ---@type string[]
|
||||||
local clients = LazyVim.lsp.get_clients({ bufnr = buf })
|
local clients = vim.lsp.get_clients({ bufnr = buf })
|
||||||
clients = vim.tbl_filter(function(client)
|
clients = vim.tbl_filter(function(client)
|
||||||
return not vim.tbl_contains(vim.g.root_lsp_ignore or {}, client.name)
|
return not vim.tbl_contains(vim.g.root_lsp_ignore or {}, client.name)
|
||||||
end, clients)
|
end, clients) --[[@as vim.lsp.Client[] ]]
|
||||||
for _, client in pairs(clients) do
|
for _, client in pairs(clients) do
|
||||||
local workspace = client.config.workspace_folders
|
local workspace = client.config.workspace_folders
|
||||||
for _, ws in pairs(workspace or {}) do
|
for _, ws in pairs(workspace or {}) do
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue