mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #13649 from mjlbach/move_from_nvim-lspconfig
LSP: Move workspace/configuration from nvim-lspconfig to core
This commit is contained in:
commit
48caf1df85
@ -755,6 +755,10 @@ start_client({config}) *vim.lsp.start_client()*
|
||||
array.
|
||||
{handlers} Map of language server method names to
|
||||
|lsp-handler|
|
||||
{settings} Map with language server specific
|
||||
settings. These are returned to the language server if
|
||||
requested via `workspace/configuration`. Keys are
|
||||
case-sensitive.
|
||||
{init_options} Values to pass in the initialization
|
||||
request as `initializationOptions` .
|
||||
See `initialize` in the LSP spec.
|
||||
|
@ -148,6 +148,31 @@ M['workspace/applyEdit'] = function(_, _, workspace_edit)
|
||||
}
|
||||
end
|
||||
|
||||
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_configuration
|
||||
M['workspace/configuration'] = function(err, _, params, client_id)
|
||||
local client = vim.lsp.get_client_by_id(client_id)
|
||||
if not client then
|
||||
err_message("LSP[id=", client_id, "] client has shut down after sending the message")
|
||||
end
|
||||
if err then error(vim.inspect(err)) end
|
||||
if not params.items then
|
||||
return {}
|
||||
end
|
||||
|
||||
local result = {}
|
||||
for _, item in ipairs(params.items) do
|
||||
if item.section then
|
||||
local value = util.lookup_section(client.config.settings, item.section) or vim.NIL
|
||||
-- For empty sections with no explicit '' key, return settings as is
|
||||
if value == vim.NIL and item.section == '' then
|
||||
value = client.config.settings or vim.NIL
|
||||
end
|
||||
table.insert(result, value)
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
M['textDocument/publishDiagnostics'] = function(...)
|
||||
return require('vim.lsp.diagnostic').on_publish_diagnostics(...)
|
||||
end
|
||||
|
@ -1422,6 +1422,21 @@ function M.character_offset(buf, row, col)
|
||||
return str_utfindex(line, col)
|
||||
end
|
||||
|
||||
--- Helper function to return nested values in language server settings
|
||||
---
|
||||
--@param settings a table of language server settings
|
||||
--@param section a string indicating the field of the settings table
|
||||
--@returns (table or string) The value of settings accessed via section
|
||||
function M.lookup_section(settings, section)
|
||||
for part in vim.gsplit(section, '.', true) do
|
||||
settings = settings[part]
|
||||
if not settings then
|
||||
return
|
||||
end
|
||||
end
|
||||
return settings
|
||||
end
|
||||
|
||||
M._get_line_byte_from_position = get_line_byte_from_position
|
||||
M._warn_once = warn_once
|
||||
|
||||
|
@ -109,6 +109,23 @@ function tests.basic_init()
|
||||
}
|
||||
end
|
||||
|
||||
function tests.check_workspace_configuration()
|
||||
skeleton {
|
||||
on_init = function(_params)
|
||||
return { capabilities = {} }
|
||||
end;
|
||||
body = function()
|
||||
notify('start')
|
||||
notify('workspace/configuration', { items = {
|
||||
{ section = "testSetting1" };
|
||||
{ section = "testSetting2" };
|
||||
} })
|
||||
expect_notification('workspace/configuration', { true; vim.NIL})
|
||||
notify('shutdown')
|
||||
end;
|
||||
}
|
||||
end
|
||||
|
||||
function tests.basic_check_capabilities()
|
||||
skeleton {
|
||||
on_init = function(params)
|
||||
|
@ -262,6 +262,48 @@ describe('LSP', function()
|
||||
}
|
||||
end)
|
||||
|
||||
it('client should return settings via workspace/configuration handler', function()
|
||||
local expected_callbacks = {
|
||||
{NIL, "shutdown", {}, 1};
|
||||
{NIL, "workspace/configuration", { items = {
|
||||
{ section = "testSetting1" };
|
||||
{ section = "testSetting2" };
|
||||
}}, 1};
|
||||
{NIL, "start", {}, 1};
|
||||
}
|
||||
local client
|
||||
test_rpc_server {
|
||||
test_name = "check_workspace_configuration";
|
||||
on_init = function(_client)
|
||||
client = _client
|
||||
end;
|
||||
on_exit = function(code, signal)
|
||||
eq(0, code, "exit code", fake_lsp_logfile)
|
||||
eq(0, signal, "exit signal", fake_lsp_logfile)
|
||||
end;
|
||||
on_callback = function(err, method, params, client_id)
|
||||
eq(table.remove(expected_callbacks), {err, method, params, client_id}, "expected callback")
|
||||
if method == 'start' then
|
||||
exec_lua([=[
|
||||
local client = vim.lsp.get_client_by_id(TEST_RPC_CLIENT_ID)
|
||||
client.config.settings = {
|
||||
testSetting1 = true;
|
||||
testSetting2 = false;
|
||||
}]=])
|
||||
end
|
||||
if method == 'workspace/configuration' then
|
||||
local result = exec_lua([=[
|
||||
local method, params = ...
|
||||
return require'vim.lsp.handlers'['workspace/configuration'](err, method, params, TEST_RPC_CLIENT_ID)]=], method, params)
|
||||
client.notify('workspace/configuration', result)
|
||||
end
|
||||
if method == 'shutdown' then
|
||||
client.stop()
|
||||
end
|
||||
end;
|
||||
}
|
||||
end)
|
||||
|
||||
it('should verify capabilities sent', function()
|
||||
local expected_callbacks = {
|
||||
{NIL, "shutdown", {}, 1};
|
||||
|
Loading…
Reference in New Issue
Block a user