aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Fußenegger <mfussenegger@users.noreply.github.com>2022-06-03 18:16:11 +0200
committerGitHub <noreply@github.com>2022-06-03 18:16:11 +0200
commitc6d747e6a5227e17556c62e16ed054398eb1a89a (patch)
tree67117afbf86c9ee2d951f7be261ccba54d32858e
parent9aba2043351c79cd9bc8fa7b229ee7629ba178f0 (diff)
downloadrneovim-c6d747e6a5227e17556c62e16ed054398eb1a89a.tar.gz
rneovim-c6d747e6a5227e17556c62e16ed054398eb1a89a.tar.bz2
rneovim-c6d747e6a5227e17556c62e16ed054398eb1a89a.zip
feat(lsp): send didChangeConfiguration after init (#18847)
Most LSP servers require the notification to correctly load the settings and for those who don't it doesn't cause any harm. So far this is done in lspconfig, but with the addition of vim.lsp.start it should be part of core.
-rw-r--r--runtime/lua/vim/lsp.lua4
-rw-r--r--test/functional/fixtures/fake-lsp-server.lua13
-rw-r--r--test/functional/plugin/lsp_spec.lua25
3 files changed, 38 insertions, 4 deletions
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua
index 6bf772ed65..361bcec04b 100644
--- a/runtime/lua/vim/lsp.lua
+++ b/runtime/lua/vim/lsp.lua
@@ -1117,6 +1117,10 @@ function lsp.start_client(config)
end
end
+ if next(config.settings) then
+ client.notify('workspace/didChangeConfiguration', { settings = config.settings })
+ end
+
if config.on_init then
local status, err = pcall(config.on_init, client, result)
if not status then
diff --git a/test/functional/fixtures/fake-lsp-server.lua b/test/functional/fixtures/fake-lsp-server.lua
index 86cdf4ef56..9bceb612a5 100644
--- a/test/functional/fixtures/fake-lsp-server.lua
+++ b/test/functional/fixtures/fake-lsp-server.lua
@@ -116,6 +116,19 @@ function tests.basic_init()
}
end
+function tests.basic_init_did_change_configuration()
+ skeleton({
+ on_init = function(_)
+ return {
+ capabilities = {},
+ }
+ end,
+ body = function()
+ expect_notification('workspace/didChangeConfiguration', { settings = { dummy = 1 } })
+ end,
+ })
+end
+
function tests.check_workspace_configuration()
skeleton {
on_init = function(_params)
diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua
index f8d4552330..05ea6f7523 100644
--- a/test/functional/plugin/lsp_spec.lua
+++ b/test/functional/plugin/lsp_spec.lua
@@ -45,10 +45,10 @@ local function clear_notrace()
end
-local function fake_lsp_server_setup(test_name, timeout_ms, options)
+local function fake_lsp_server_setup(test_name, timeout_ms, options, settings)
exec_lua([=[
lsp = require('vim.lsp')
- local test_name, fixture_filename, logfile, timeout, options = ...
+ local test_name, fixture_filename, logfile, timeout, options, settings = ...
TEST_RPC_CLIENT_ID = lsp.start_client {
cmd_env = {
NVIM_LOG_FILE = logfile;
@@ -79,17 +79,18 @@ local function fake_lsp_server_setup(test_name, timeout_ms, options)
allow_incremental_sync = options.allow_incremental_sync or false;
debounce_text_changes = options.debounce_text_changes or 0;
};
+ settings = settings;
on_exit = function(...)
vim.rpcnotify(1, "exit", ...)
end;
}
- ]=], test_name, fake_lsp_code, fake_lsp_logfile, timeout_ms or 1e3, options or {})
+ ]=], test_name, fake_lsp_code, fake_lsp_logfile, timeout_ms or 1e3, options or {}, settings or {})
end
local function test_rpc_server(config)
if config.test_name then
clear_notrace()
- fake_lsp_server_setup(config.test_name, config.timeout_ms or 1e3, config.options)
+ fake_lsp_server_setup(config.test_name, config.timeout_ms or 1e3, config.options, config.settings)
end
local client = setmetatable({}, {
__index = function(_, name)
@@ -298,6 +299,22 @@ describe('LSP', function()
}
end)
+ it('should send didChangeConfiguration after initialize if there are settings', function()
+ test_rpc_server({
+ test_name = 'basic_init_did_change_configuration',
+ on_init = function(client, _)
+ client.stop()
+ end,
+ on_exit = function(code, signal)
+ eq(0, code, 'exit code', fake_lsp_logfile)
+ eq(0, signal, 'exit signal', fake_lsp_logfile)
+ end,
+ settings = {
+ dummy = 1,
+ },
+ })
+ end)
+
it('should succeed with manual shutdown', function()
if isCI() then
pending('hangs the build on CI #14028, re-enable with freeze timeout #14204')