mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-21 20:11:06 +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,
|
||||
2,
|
||||
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
|
||||
local status = require("copilot.status").data.status
|
||||
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 = math.floor(math.min(vim.o.lines * 0.8 - 16, #items + 2) + 0.5) + 16,
|
||||
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",
|
||||
vertical = "down:15,border-top",
|
||||
hidden = "hidden",
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ return {
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
local formatter = LazyVim.lsp.formatter({
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ function M.has(buffer, method)
|
|||
return false
|
||||
end
|
||||
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
|
||||
if client:supports_method(method) then
|
||||
return true
|
||||
|
|
@ -69,7 +69,7 @@ function M.resolve(buffer)
|
|||
end
|
||||
local spec = vim.tbl_extend("force", {}, M.get())
|
||||
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
|
||||
local maps = opts.servers[client.name] and opts.servers[client.name].keys or {}
|
||||
vim.list_extend(spec, maps)
|
||||
|
|
|
|||
|
|
@ -1,15 +1,6 @@
|
|||
---@class lazyvim.util.lsp
|
||||
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 name? string
|
||||
function M.on_attach(on_attach, name)
|
||||
|
|
@ -107,12 +98,12 @@ function M.on_supports_method(method, fn)
|
|||
})
|
||||
end
|
||||
|
||||
---@param opts? LazyFormatter| {filter?: (string|lsp.Client.filter)}
|
||||
---@param opts? LazyFormatter| {filter?: (string|vim.lsp.get_clients.Filter)}
|
||||
function M.formatter(opts)
|
||||
opts = opts or {}
|
||||
local filter = opts.filter or {}
|
||||
filter = type(filter) == "string" and { name = filter } or filter
|
||||
---@cast filter lsp.Client.filter
|
||||
---@cast filter vim.lsp.get_clients.Filter
|
||||
---@type LazyFormatter
|
||||
local ret = {
|
||||
name = "LSP",
|
||||
|
|
@ -122,7 +113,7 @@ function M.formatter(opts)
|
|||
M.format(LazyVim.merge({}, filter, { bufnr = buf }))
|
||||
end,
|
||||
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
|
||||
local ret = vim.tbl_filter(function(client)
|
||||
return client:supports_method("textDocument/formatting")
|
||||
|
|
@ -137,7 +128,7 @@ function M.formatter(opts)
|
|||
return LazyVim.merge(ret, opts) --[[@as LazyFormatter]]
|
||||
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
|
||||
function M.format(opts)
|
||||
|
|
|
|||
|
|
@ -29,10 +29,10 @@ function M.detectors.lsp(buf)
|
|||
return {}
|
||||
end
|
||||
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)
|
||||
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
|
||||
local workspace = client.config.workspace_folders
|
||||
for _, ws in pairs(workspace or {}) do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue