mirror of
https://github.com/neovim/nvim-lspconfig
synced 2024-09-16 14:24:07 +02:00
refactor: move all old get_clients to new compatible (#3159)
This commit is contained in:
parent
39106f0b71
commit
a284b14b3a
8 changed files with 15 additions and 15 deletions
|
@ -16,7 +16,7 @@ local function organize_imports()
|
||||||
arguments = { vim.uri_from_bufnr(0) },
|
arguments = { vim.uri_from_bufnr(0) },
|
||||||
}
|
}
|
||||||
|
|
||||||
local clients = vim.lsp.get_active_clients {
|
local clients = util.get_lsp_clients {
|
||||||
bufnr = vim.api.nvim_get_current_buf(),
|
bufnr = vim.api.nvim_get_current_buf(),
|
||||||
name = 'basedpyright',
|
name = 'basedpyright',
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ local function organize_imports()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function set_python_path(path)
|
local function set_python_path(path)
|
||||||
local clients = vim.lsp.get_active_clients {
|
local clients = util.get_lsp_clients {
|
||||||
bufnr = vim.api.nvim_get_current_buf(),
|
bufnr = vim.api.nvim_get_current_buf(),
|
||||||
name = 'basedpyright',
|
name = 'basedpyright',
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ return {
|
||||||
commands = {
|
commands = {
|
||||||
DenolsCache = {
|
DenolsCache = {
|
||||||
function()
|
function()
|
||||||
local clients = vim.lsp.get_active_clients { bufnr = 0, name = 'denols' }
|
local clients = util.get_lsp_clients { bufnr = 0, name = 'denols' }
|
||||||
if #clients > 0 then
|
if #clients > 0 then
|
||||||
buf_cache(0, clients[#clients])
|
buf_cache(0, clients[#clients])
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,7 +15,7 @@ return {
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if fname:sub(1, #mod_cache) == mod_cache then
|
if fname:sub(1, #mod_cache) == mod_cache then
|
||||||
local clients = vim.lsp.get_active_clients { name = 'gopls' }
|
local clients = util.get_lsp_clients { name = 'gopls' }
|
||||||
if #clients > 0 then
|
if #clients > 0 then
|
||||||
return clients[#clients].config.root_dir
|
return clients[#clients].config.root_dir
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,7 +16,7 @@ local function organize_imports()
|
||||||
arguments = { vim.uri_from_bufnr(0) },
|
arguments = { vim.uri_from_bufnr(0) },
|
||||||
}
|
}
|
||||||
|
|
||||||
local clients = vim.lsp.get_active_clients {
|
local clients = util.get_lsp_clients {
|
||||||
bufnr = vim.api.nvim_get_current_buf(),
|
bufnr = vim.api.nvim_get_current_buf(),
|
||||||
name = 'pyright',
|
name = 'pyright',
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ local function organize_imports()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function set_python_path(path)
|
local function set_python_path(path)
|
||||||
local clients = vim.lsp.get_active_clients {
|
local clients = util.get_lsp_clients {
|
||||||
bufnr = vim.api.nvim_get_current_buf(),
|
bufnr = vim.api.nvim_get_current_buf(),
|
||||||
name = 'pyright',
|
name = 'pyright',
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ local async = require 'lspconfig.async'
|
||||||
|
|
||||||
local function reload_workspace(bufnr)
|
local function reload_workspace(bufnr)
|
||||||
bufnr = util.validate_bufnr(bufnr)
|
bufnr = util.validate_bufnr(bufnr)
|
||||||
local clients = vim.lsp.get_active_clients { name = 'rust_analyzer', bufnr = bufnr }
|
local clients = util.get_lsp_clients { bufnr = bufnr, name = 'rust_analyzer' }
|
||||||
for _, client in ipairs(clients) do
|
for _, client in ipairs(clients) do
|
||||||
vim.notify 'Reloading Cargo Workspace'
|
vim.notify 'Reloading Cargo Workspace'
|
||||||
client.request('rust-analyzer/reloadWorkspace', nil, function(err)
|
client.request('rust-analyzer/reloadWorkspace', nil, function(err)
|
||||||
|
@ -26,7 +26,7 @@ local function is_library(fname)
|
||||||
|
|
||||||
for _, item in ipairs { toolchains, registry, git_registry } do
|
for _, item in ipairs { toolchains, registry, git_registry } do
|
||||||
if util.path.is_descendant(item, fname) then
|
if util.path.is_descendant(item, fname) then
|
||||||
local clients = vim.lsp.get_active_clients { name = 'rust_analyzer' }
|
local clients = util.get_lsp_clients { name = 'rust_analyzer' }
|
||||||
return #clients > 0 and clients[#clients].config.root_dir or nil
|
return #clients > 0 and clients[#clients].config.root_dir or nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
local api, fn, lsp = vim.api, vim.fn, vim.lsp
|
local api, fn = vim.api, vim.fn
|
||||||
local windows = require 'lspconfig.ui.windows'
|
local windows = require 'lspconfig.ui.windows'
|
||||||
local util = require 'lspconfig.util'
|
local util = require 'lspconfig.util'
|
||||||
|
|
||||||
|
@ -188,8 +188,8 @@ return function()
|
||||||
-- These options need to be cached before switching to the floating
|
-- These options need to be cached before switching to the floating
|
||||||
-- buffer.
|
-- buffer.
|
||||||
local original_bufnr = api.nvim_get_current_buf()
|
local original_bufnr = api.nvim_get_current_buf()
|
||||||
local buf_clients = lsp.get_active_clients { bufnr = original_bufnr }
|
local buf_clients = util.get_lsp_clients { bufnr = original_bufnr }
|
||||||
local clients = lsp.get_active_clients()
|
local clients = util.get_lsp_clients()
|
||||||
local buffer_filetype = vim.bo.filetype
|
local buffer_filetype = vim.bo.filetype
|
||||||
local fname = api.nvim_buf_get_name(original_bufnr)
|
local fname = api.nvim_buf_get_name(original_bufnr)
|
||||||
|
|
||||||
|
|
|
@ -266,7 +266,7 @@ function M.tbl_flatten(t)
|
||||||
return nvim_ten and vim.iter(t):flatten(math.huge):totable() or vim.tbl_flatten(t)
|
return nvim_ten and vim.iter(t):flatten(math.huge):totable() or vim.tbl_flatten(t)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_lsp_clients(filter)
|
function M.get_lsp_clients(filter)
|
||||||
return nvim_ten and lsp.get_clients(filter) or lsp.get_active_clients(filter)
|
return nvim_ten and lsp.get_clients(filter) or lsp.get_active_clients(filter)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -342,7 +342,7 @@ function M.insert_package_json(config_files, field, fname)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.get_active_clients_list_by_ft(filetype)
|
function M.get_active_clients_list_by_ft(filetype)
|
||||||
local clients = get_lsp_clients()
|
local clients = M.get_lsp_clients()
|
||||||
local clients_list = {}
|
local clients_list = {}
|
||||||
for _, client in pairs(clients) do
|
for _, client in pairs(clients) do
|
||||||
local filetypes = client.config.filetypes or {}
|
local filetypes = client.config.filetypes or {}
|
||||||
|
@ -388,7 +388,7 @@ end
|
||||||
|
|
||||||
function M.get_active_client_by_name(bufnr, servername)
|
function M.get_active_client_by_name(bufnr, servername)
|
||||||
--TODO(glepnir): remove this for loop when we want only support 0.10+
|
--TODO(glepnir): remove this for loop when we want only support 0.10+
|
||||||
for _, client in pairs(get_lsp_clients { bufnr = bufnr }) do
|
for _, client in pairs(M.get_lsp_clients { bufnr = bufnr }) do
|
||||||
if client.name == servername then
|
if client.name == servername then
|
||||||
return client
|
return client
|
||||||
end
|
end
|
||||||
|
|
|
@ -135,7 +135,7 @@ api.nvim_create_user_command('LspStop', function(info)
|
||||||
end
|
end
|
||||||
|
|
||||||
if not server_id then
|
if not server_id then
|
||||||
local servers_on_buffer = lsp.get_active_clients { bufnr = current_buf }
|
local servers_on_buffer = require('lspconfig.util').get_lsp_clients { bufnr = current_buf }
|
||||||
for _, client in ipairs(servers_on_buffer) do
|
for _, client in ipairs(servers_on_buffer) do
|
||||||
if client.attached_buffers[current_buf] then
|
if client.attached_buffers[current_buf] then
|
||||||
client.stop(force)
|
client.stop(force)
|
||||||
|
|
Loading…
Reference in a new issue