Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: follow upstream deprecate non-method clients functions #3443

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions lua/lspconfig/configs.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local util = require 'lspconfig.util'
local async = require 'lspconfig.async'
local util = require('lspconfig.util')
local async = require('lspconfig.async')
local api, validate, lsp, uv, fn = vim.api, vim.validate, vim.lsp, (vim.uv or vim.loop), vim.fn
local tbl_deep_extend = vim.tbl_deep_extend

Expand Down Expand Up @@ -30,13 +30,13 @@ end
---@param config_name string
---@param config_def table Config definition read from `lspconfig.configs.<name>`.
function configs.__newindex(t, config_name, config_def)
validate {
validate({
name = { config_name, 's' },
default_config = { config_def.default_config, 't' },
on_new_config = { config_def.on_new_config, 'f', true },
on_attach = { config_def.on_attach, 'f', true },
commands = { config_def.commands, 't', true },
}
})

if config_def.default_config.deprecate then
vim.deprecate(
Expand All @@ -50,10 +50,10 @@ function configs.__newindex(t, config_name, config_def)

if config_def.commands then
for k, v in pairs(config_def.commands) do
validate {
validate({
['command.name'] = { k, 's' },
['command.fn'] = { v[1], 'f' },
}
})
end
else
config_def.commands = {}
Expand All @@ -70,7 +70,7 @@ function configs.__newindex(t, config_name, config_def)
function M.setup(user_config)
local lsp_group = api.nvim_create_augroup('lspconfig', { clear = false })

validate {
validate({
cmd = {
user_config.cmd,
{ 'f', 't' },
Expand All @@ -81,13 +81,13 @@ function configs.__newindex(t, config_name, config_def)
on_new_config = { user_config.on_new_config, 'f', true },
on_attach = { user_config.on_attach, 'f', true },
commands = { user_config.commands, 't', true },
}
})
if user_config.commands then
for k, v in pairs(user_config.commands) do
validate {
validate({
['command.name'] = { k, 's' },
['command.fn'] = { v[1], 'f' },
}
})
end
end

Expand Down Expand Up @@ -192,7 +192,7 @@ function configs.__newindex(t, config_name, config_def)
local reload = false
if M.manager then
for _, client in ipairs(M.manager:clients()) do
client.stop(true)
util.client_proxy(client).stop(true)
end
reload = true
M.manager = nil
Expand Down
4 changes: 2 additions & 2 deletions lua/lspconfig/configs/basedpyright.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ local function organize_imports()
name = 'basedpyright',
}
for _, client in ipairs(clients) do
client.request('workspace/executeCommand', params, nil, 0)
util.client_proxy(client).request('workspace/executeCommand', params, nil, 0)
end
end

Expand All @@ -36,7 +36,7 @@ local function set_python_path(path)
else
client.config.settings = vim.tbl_deep_extend('force', client.config.settings, { python = { pythonPath = path } })
end
client.notify('workspace/didChangeConfiguration', { settings = nil })
util.client_proxy(client).notify('workspace/didChangeConfiguration', { settings = nil })
end
end

Expand Down
13 changes: 7 additions & 6 deletions lua/lspconfig/configs/clangd.lua
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
local util = require 'lspconfig.util'
local util = require('lspconfig.util')
local client_proxy = util.client_proxy

-- https://clangd.llvm.org/extensions.html#switch-between-sourceheader
local function switch_source_header(bufnr)
bufnr = util.validate_bufnr(bufnr)
local clangd_client = util.get_active_client_by_name(bufnr, 'clangd')
local params = { uri = vim.uri_from_bufnr(bufnr) }
if clangd_client then
clangd_client.request('textDocument/switchSourceHeader', params, function(err, result)
client_proxy(clangd_client).request('textDocument/switchSourceHeader', params, function(err, result)
if err then
error(tostring(err))
end
if not result then
print 'Corresponding file cannot be determined'
print('Corresponding file cannot be determined')
return
end
vim.api.nvim_command('edit ' .. vim.uri_to_fname(result))
end, bufnr)
else
print 'method textDocument/switchSourceHeader is not supported by any servers active on the current buffer'
print('method textDocument/switchSourceHeader is not supported by any servers active on the current buffer')
end
end

local function symbol_info()
local bufnr = vim.api.nvim_get_current_buf()
local clangd_client = util.get_active_client_by_name(bufnr, 'clangd')
if not clangd_client or not clangd_client.supports_method 'textDocument/symbolInfo' then
if not clangd_client or not client_proxy(clangd_client).supports_method('textDocument/symbolInfo') then
return vim.notify('Clangd client not found', vim.log.levels.ERROR)
end
local params = vim.lsp.util.make_position_params()
clangd_client.request('textDocument/symbolInfo', params, function(err, res)
client_proxy(clangd_client).request('textDocument/symbolInfo', params, function(err, res)
if err or #res == 0 then
-- Clangd always returns an error, there is not reason to parse it
return
Expand Down
10 changes: 5 additions & 5 deletions lua/lspconfig/configs/denols.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
local util = require 'lspconfig.util'
local util = require('lspconfig.util')
local lsp = vim.lsp

local function buf_cache(bufnr, client)
local params = {
command = 'deno.cache',
arguments = { {}, vim.uri_from_bufnr(bufnr) },
}
client.request('workspace/executeCommand', params, function(err, _result, ctx)
util.client_proxy(client).request('workspace/executeCommand', params, function(err, _, ctx)
if err then
local uri = ctx.params.arguments[2]
vim.api.nvim_err_writeln('cache command failed for ' .. vim.uri_to_fname(uri))
Expand Down Expand Up @@ -40,7 +40,7 @@ local function virtual_text_document(uri, client)
uri = uri,
},
}
local result = client.request_sync('deno/virtualTextDocument', params)
local result = util.client_proxy(client).request_sync('deno/virtualTextDocument', params)
virtual_text_document_handler(uri, result, client)
end

Expand All @@ -52,7 +52,7 @@ local function denols_handler(err, result, ctx, config)
local client = vim.lsp.get_client_by_id(ctx.client_id)
for _, res in pairs(result) do
local uri = res.uri or res.targetUri
if uri:match '^deno:' then
if uri:match('^deno:') then
virtual_text_document(uri, client)
res['uri'] = uri
res['targetUri'] = uri
Expand Down Expand Up @@ -96,7 +96,7 @@ return {
commands = {
DenolsCache = {
function()
local clients = util.get_lsp_clients { bufnr = 0, name = 'denols' }
local clients = util.get_lsp_clients({ bufnr = 0, name = 'denols' })
if #clients > 0 then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is stylua doing this? not required by our style guide.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like a bug of stylua . just run stylua ./ in shell

buf_cache(0, clients[#clients])
end
Expand Down
12 changes: 6 additions & 6 deletions lua/lspconfig/configs/ds_pinyin_lsp.lua
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
local util = require 'lspconfig.util'
local util = require('lspconfig.util')

local bin_name = 'ds-pinyin-lsp'
if vim.fn.has 'win32' == 1 then
if vim.fn.has('win32') == 1 then
bin_name = bin_name .. '.exe'
end

local function ds_pinyin_lsp_off(bufnr)
bufnr = util.validate_bufnr(bufnr)
local ds_pinyin_lsp_client = util.get_active_client_by_name(bufnr, 'ds_pinyin_lsp')
if ds_pinyin_lsp_client then
ds_pinyin_lsp_client.notify('$/turn/completion', {
util.client_proxy(ds_pinyin_lsp_client).notify('$/turn/completion', {
['completion_on'] = false,
})
else
vim.notify 'notification $/turn/completion is not supported by any servers active on the current buffer'
vim.notify('notification $/turn/completion is not supported by any servers active on the current buffer')
end
end

local function ds_pinyin_lsp_on(bufnr)
bufnr = util.validate_bufnr(bufnr)
local ds_pinyin_lsp_client = util.get_active_client_by_name(bufnr, 'ds_pinyin_lsp')
if ds_pinyin_lsp_client then
ds_pinyin_lsp_client.notify('$/turn/completion', {
util.client_proxy(ds_pinyin_lsp_client).notify('$/turn/completion', {
['completion_on'] = true,
})
else
vim.notify 'notification $/turn/completion is not supported by any servers active on the current buffer'
vim.notify('notification $/turn/completion is not supported by any servers active on the current buffer')
end
end

Expand Down
17 changes: 9 additions & 8 deletions lua/lspconfig/configs/eslint.lua
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
local util = require 'lspconfig.util'
local util = require('lspconfig.util')
local lsp = vim.lsp

local function fix_all(opts)
opts = opts or {}

local eslint_lsp_client = util.get_active_client_by_name(opts.bufnr, 'eslint')
if eslint_lsp_client == nil then
local client = util.get_active_client_by_name(opts.bufnr, 'eslint')
if client == nil then
return
end

client = util.client_proxy(client)
local request
if opts.sync then
request = function(bufnr, method, params)
eslint_lsp_client.request_sync(method, params, nil, bufnr)
client.request_sync(method, params, nil, bufnr)
end
else
request = function(bufnr, method, params)
eslint_lsp_client.request(method, params, nil, bufnr)
client.request(method, params, nil, bufnr)
end
end

Expand Down Expand Up @@ -135,9 +136,9 @@ return {
return
end
local sysname = vim.uv.os_uname().sysname
if sysname:match 'Windows' then
if sysname:match('Windows') then
os.execute(string.format('start %q', result.url))
elseif sysname:match 'Linux' then
elseif sysname:match('Linux') then
os.execute(string.format('xdg-open %q', result.url))
else
os.execute(string.format('open %q', result.url))
Expand All @@ -163,7 +164,7 @@ return {
commands = {
EslintFixAll = {
function()
fix_all { sync = true, bufnr = 0 }
fix_all({ sync = true, bufnr = 0 })
end,
description = 'Fix all eslint problems for this buffer',
},
Expand Down
14 changes: 7 additions & 7 deletions lua/lspconfig/configs/julials.lua
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
local util = require 'lspconfig.util'
local util = require('lspconfig.util')

local root_files = { 'Project.toml', 'JuliaProject.toml' }

local function activate_env(path)
assert(vim.fn.has 'nvim-0.10' == 1, 'requires Nvim 0.10 or newer')
assert(vim.fn.has('nvim-0.10') == 1, 'requires Nvim 0.10 or newer')
local bufnr = vim.api.nvim_get_current_buf()
local julials_clients = vim.lsp.get_clients { bufnr = bufnr, name = 'julials' }
local julials_clients = vim.lsp.get_clients({ bufnr = bufnr, name = 'julials' })
assert(
#julials_clients > 0,
'method julia/activateenvironment is not supported by any servers active on the current buffer'
)
local function _activate_env(environment)
if environment then
for _, julials_client in ipairs(julials_clients) do
julials_client.notify('julia/activateenvironment', { envPath = environment })
util.client_proxy(julials_client).notify('julia/activateenvironment', { envPath = environment })
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely not in favor of this PR if it requires client_proxy in the configs themselves. That just introduces even more migration later.

If there's a way to make it transparent to configs, that's fine. Otherwise we should just wait until we can bump the minimum required Nvim to 0.11

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. The current command design is too fragile. The client is necessary here. So it is better to provide a default wrapper function with the client and bufnr as the parameter so that we can easily handle any upstream changes on the client object internally.

      switch_source_header(client, bufnr),   

vim.notify('Julia environment activated: \n`' .. environment .. '`', vim.log.levels.INFO)
end
Expand All @@ -35,16 +35,16 @@ local function activate_env(path)
_activate_env(path)
else
local depot_paths = vim.env.JULIA_DEPOT_PATH
and vim.split(vim.env.JULIA_DEPOT_PATH, vim.fn.has 'win32' == 1 and ';' or ':')
or { vim.fn.expand '~/.julia' }
and vim.split(vim.env.JULIA_DEPOT_PATH, vim.fn.has('win32') == 1 and ';' or ':')
or { vim.fn.expand('~/.julia') }
local environments = {}
vim.list_extend(environments, vim.fs.find(root_files, { type = 'file', upward = true, limit = math.huge }))
for _, depot_path in ipairs(depot_paths) do
local depot_env = vim.fs.joinpath(vim.fs.normalize(depot_path), 'environments')
vim.list_extend(
environments,
vim.fs.find(function(name, env_path)
return vim.tbl_contains(root_files, name) and string.sub(env_path, #depot_env + 1):match '^/[^/]*$'
return vim.tbl_contains(root_files, name) and string.sub(env_path, #depot_env + 1):match('^/[^/]*$')
end, { path = depot_env, type = 'file', limit = math.huge })
)
end
Expand Down
4 changes: 2 additions & 2 deletions lua/lspconfig/configs/pyright.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ local function organize_imports()
name = 'pyright',
}
for _, client in ipairs(clients) do
client.request('workspace/executeCommand', params, nil, 0)
util.client_proxy(client).request('workspace/executeCommand', params, nil, 0)
end
end

Expand All @@ -36,7 +36,7 @@ local function set_python_path(path)
else
client.config.settings = vim.tbl_deep_extend('force', client.config.settings, { python = { pythonPath = path } })
end
client.notify('workspace/didChangeConfiguration', { settings = nil })
util.client_proxy(client).notify('workspace/didChangeConfiguration', { settings = nil })
end
end

Expand Down
2 changes: 1 addition & 1 deletion lua/lspconfig/configs/rust_analyzer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local function reload_workspace(bufnr)
local clients = util.get_lsp_clients { bufnr = bufnr, name = 'rust_analyzer' }
for _, client in ipairs(clients) do
vim.notify 'Reloading Cargo Workspace'
client.request('rust-analyzer/reloadWorkspace', nil, function(err)
util.client_proxy(client).request('rust-analyzer/reloadWorkspace', nil, function(err)
if err then
error(tostring(err))
end
Expand Down
3 changes: 2 additions & 1 deletion lua/lspconfig/configs/texlab.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local util = require 'lspconfig.util'
local client_proxy = util.client_proxy

local function client_with_fn(fn)
return function()
Expand All @@ -7,7 +8,7 @@ local function client_with_fn(fn)
if not client then
return vim.notify(('texlab client not found in bufnr %d'):format(bufnr), vim.log.levels.ERROR)
end
fn(client, bufnr)
fn(client_proxy(client), bufnr)
end
end

Expand Down
Loading
Loading