diff options
author | Gregory Anders <greg@gpanders.com> | 2024-12-27 10:09:22 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-27 10:09:22 -0600 |
commit | 35247b00a44e838ed7d657a9b94964dc0664d28d (patch) | |
tree | d0c2911358fc4d0c8a905feb888465106fe7ce23 /test/functional/plugin/lsp_spec.lua | |
parent | 6d2c67350ad89abf09c5ddaaf02bcccfc5fc466c (diff) | |
download | rneovim-35247b00a44e838ed7d657a9b94964dc0664d28d.tar.gz rneovim-35247b00a44e838ed7d657a9b94964dc0664d28d.tar.bz2 rneovim-35247b00a44e838ed7d657a9b94964dc0664d28d.zip |
feat(lsp): support function for client root_dir (#31630)
If root_dir is a function it is evaluated when the client is created to
determine the root directory.
This enables dynamically determining the root directory based on e.g.
project or directory structure (example: finding a parent Cargo.toml
file that contains "[workspace]" in a Rust project).
Diffstat (limited to 'test/functional/plugin/lsp_spec.lua')
-rw-r--r-- | test/functional/plugin/lsp_spec.lua | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 1f246b0914..f396c837f9 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -6245,5 +6245,38 @@ describe('LSP', function() end) ) end) + + it('supports a function for root_dir', function() + exec_lua(create_server_definition) + + local tmp1 = t.tmpname(true) + + eq( + 'some_dir', + exec_lua(function() + local server = _G._create_server({ + handlers = { + initialize = function(_, _, callback) + callback(nil, { capabilities = {} }) + end, + }, + }) + + vim.lsp.config('foo', { + cmd = server.cmd, + filetypes = { 'foo' }, + root_dir = function(cb) + cb('some_dir') + end, + }) + vim.lsp.enable('foo') + + vim.cmd.edit(assert(tmp1)) + vim.bo.filetype = 'foo' + + return vim.lsp.get_clients({ bufnr = vim.api.nvim_get_current_buf() })[1].root_dir + end) + ) + end) end) end) |