aboutsummaryrefslogtreecommitdiff
path: root/test/functional/plugin
diff options
context:
space:
mode:
authorMichal Liszcz <liszcz.michal@gmail.com>2023-03-09 15:12:56 +0100
committerGitHub <noreply@github.com>2023-03-09 06:12:56 -0800
commit9ef7297ef142354ace8b1f3f277d0eee3cfdc6d4 (patch)
tree317cfc799191e044e1fc9452ef40ca24376fcbb1 /test/functional/plugin
parentce0fddf5ae334f0c79dcd95b379999e11df1486b (diff)
downloadrneovim-9ef7297ef142354ace8b1f3f277d0eee3cfdc6d4.tar.gz
rneovim-9ef7297ef142354ace8b1f3f277d0eee3cfdc6d4.tar.bz2
rneovim-9ef7297ef142354ace8b1f3f277d0eee3cfdc6d4.zip
feat(lsp): overwrite omnifunc/tagfunc set by ftplugin #22267
Problem: Some built-in ftplugins set omnifunc/tagfunc/formatexpr which causes lsp.lua:set_defaults() to skip setup of defaults for those filetypes. For example the C++ ftplugin has: omnifunc=ccomplete#Complete Last set from /usr/share/nvim/runtime/ftplugin/c.vim line 30 so the changes done in #95c65a6b221fe6e1cf91e8322e7d7571dc511a71 will always be skipped for C++ files. Solution: Overwrite omnifunc/tagfunc/formatexpr options that were set by stock ftplugin. Fixes #21001
Diffstat (limited to 'test/functional/plugin')
-rw-r--r--test/functional/plugin/lsp_spec.lua103
1 files changed, 103 insertions, 0 deletions
diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua
index 5eb367b0b8..56c53a6fed 100644
--- a/test/functional/plugin/lsp_spec.lua
+++ b/test/functional/plugin/lsp_spec.lua
@@ -31,6 +31,11 @@ local fake_lsp_code = lsp_helpers.fake_lsp_code
local fake_lsp_logfile = lsp_helpers.fake_lsp_logfile
local test_rpc_server = lsp_helpers.test_rpc_server
+local function get_buf_option(name, bufnr)
+ bufnr = bufnr or "BUFFER"
+ return exec_lua(string.format("return vim.api.nvim_buf_get_option(%s, '%s')", bufnr, name))
+end
+
-- TODO(justinmk): hangs on Windows https://github.com/neovim/neovim/pull/11837
if skip(is_os('win')) then return end
@@ -313,6 +318,104 @@ describe('LSP', function()
}
end)
+ it('should set default options on attach', function()
+ local client
+ test_rpc_server {
+ test_name = "set_defaults_all_capabilities";
+ on_setup = function()
+ exec_lua [[
+ BUFFER = vim.api.nvim_create_buf(false, true)
+ ]]
+ end;
+ on_init = function(_client)
+ client = _client
+ exec_lua("lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID)")
+ end;
+ on_handler = function(_, _, ctx)
+ if ctx.method == 'test' then
+ eq('v:lua.vim.lsp.tagfunc', get_buf_option("tagfunc"))
+ eq('v:lua.vim.lsp.omnifunc', get_buf_option("omnifunc"))
+ eq('v:lua.vim.lsp.formatexpr()', get_buf_option("formatexpr"))
+ client.stop()
+ end
+ end;
+ on_exit = function(_, _)
+ eq('', get_buf_option("tagfunc"))
+ eq('', get_buf_option("omnifunc"))
+ eq('', get_buf_option("formatexpr"))
+ end;
+ }
+ end)
+
+ it('should overwrite options set by ftplugins', function()
+ local client
+ test_rpc_server {
+ test_name = "set_defaults_all_capabilities";
+ on_setup = function()
+ exec_lua [[
+ vim.api.nvim_command('filetype plugin on')
+ BUFFER_1 = vim.api.nvim_create_buf(false, true)
+ BUFFER_2 = vim.api.nvim_create_buf(false, true)
+ vim.api.nvim_buf_set_option(BUFFER_1, 'filetype', 'man')
+ vim.api.nvim_buf_set_option(BUFFER_2, 'filetype', 'xml')
+ ]]
+ eq('v:lua.require\'man\'.goto_tag', get_buf_option("tagfunc", "BUFFER_1"))
+ eq('xmlcomplete#CompleteTags', get_buf_option("omnifunc", "BUFFER_2"))
+ eq('xmlformat#Format()', get_buf_option("formatexpr", "BUFFER_2"))
+ end;
+ on_init = function(_client)
+ client = _client
+ exec_lua("lsp.buf_attach_client(BUFFER_1, TEST_RPC_CLIENT_ID)")
+ exec_lua("lsp.buf_attach_client(BUFFER_2, TEST_RPC_CLIENT_ID)")
+ end;
+ on_handler = function(_, _, ctx)
+ if ctx.method == 'test' then
+ eq('v:lua.vim.lsp.tagfunc', get_buf_option("tagfunc", "BUFFER_1"))
+ eq('v:lua.vim.lsp.omnifunc', get_buf_option("omnifunc", "BUFFER_2"))
+ eq('v:lua.vim.lsp.formatexpr()', get_buf_option("formatexpr", "BUFFER_2"))
+ client.stop()
+ end
+ end;
+ on_exit = function(_, _)
+ eq('', get_buf_option("tagfunc", "BUFFER_1"))
+ eq('', get_buf_option("omnifunc", "BUFFER_2"))
+ eq('', get_buf_option("formatexpr", "BUFFER_2"))
+ end;
+ }
+ end)
+
+ it('should not overwrite user-defined options', function()
+ local client
+ test_rpc_server {
+ test_name = "set_defaults_all_capabilities";
+ on_setup = function()
+ exec_lua [[
+ BUFFER = vim.api.nvim_create_buf(false, true)
+ vim.api.nvim_buf_set_option(BUFFER, 'tagfunc', 'tfu')
+ vim.api.nvim_buf_set_option(BUFFER, 'omnifunc', 'ofu')
+ vim.api.nvim_buf_set_option(BUFFER, 'formatexpr', 'fex')
+ ]]
+ end;
+ on_init = function(_client)
+ client = _client
+ exec_lua("lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID)")
+ end;
+ on_handler = function(_, _, ctx)
+ if ctx.method == 'test' then
+ eq('tfu', get_buf_option("tagfunc"))
+ eq('ofu', get_buf_option("omnifunc"))
+ eq('fex', get_buf_option("formatexpr"))
+ client.stop()
+ end
+ end;
+ on_exit = function(_, _)
+ eq('tfu', get_buf_option("tagfunc"))
+ eq('ofu', get_buf_option("omnifunc"))
+ eq('fex', get_buf_option("formatexpr"))
+ end;
+ }
+ end)
+
it('should detach buffer on bufwipe', function()
clear()
exec_lua(create_server_definition)