-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
[reverted] fix(lsp): should support vim.lsp.Config.root_dir as fun
, not only string|nil
#36071
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
Conversation
@atusy you need to run |
thanks! I will |
I also need to fix type inconsistencies... I will make some time later.
|
6a0a396
to
60fb995
Compare
fun
, not only string|nil
Okay, seems like everything is clear. |
Are you able to write a test to exercise this |
I'll try |
@justinmk |
a4cb2df
to
2fa0caf
Compare
runtime/lua/vim/lsp.lua
Outdated
local name ---@type string | ||
workspace_folders(0, function(root_dir) | ||
name = root_dir | ||
end) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need a similar vim.wait
approach here, in case root_dir
is async.
runtime/lua/vim/lsp/health.lua
Outdated
'- Root directories:\n %s', | ||
table.concat( | ||
vim.iter(root_dirs):map(function(x) | ||
vim.fn.fnamemodify(x, ':~') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forgot return
here. i will fix this in a push.
runtime/lua/vim/lsp/health.lua
Outdated
for buf, _ in pairs(client.attached_buffers) do | ||
client.root_dir(buf, function(dir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if there are many attached_buffers
all resolving to the same root, this will show many redundant root dirs.
i will fix this in a push.
Examples: vim.lsp: Active Clients ~ - lua_ls (id: 1) - Version: <Unknown> - Root directories: ~/foo/bar ~/dev/neovim
2fa0caf
to
ff121a2
Compare
backport neovim#36071 * fix(lsp): type of root_dir should be annotated with string|fun|nil * feat(lsp): support root_dir as function in _get_workspace_folders * feat(lsp): let checkhealth support root_dir() function Examples: vim.lsp: Active Clients ~ - lua_ls (id: 1) - Version: <Unknown> - Root directories: ~/foo/bar ~/dev/neovim Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
thanks a lot! |
backport neovim#36071 * fix(lsp): type of root_dir should be annotated with string|fun|nil * feat(lsp): support root_dir as function in _get_workspace_folders * feat(lsp): let checkhealth support root_dir() function Examples: vim.lsp: Active Clients ~ - lua_ls (id: 1) - Version: <Unknown> - Root directories: ~/foo/bar ~/dev/neovim Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
…36141) backport #36071 * fix(lsp): type of root_dir should be annotated with string|fun|nil * feat(lsp): support root_dir as function in _get_workspace_folders * feat(lsp): let checkhealth support root_dir() function Examples: vim.lsp: Active Clients ~ - lua_ls (id: 1) - Version: <Unknown> - Root directories: ~/foo/bar ~/dev/neovim Co-authored-by: atusy <30277794+atusy@users.noreply.github.com>
Isn't the annotation change sort of wrong? While Resolving happens in: neovim/runtime/lua/vim/lsp.lua Lines 503 to 508 in c9b74f8
With this change it is implied that the |
true, and very important. |
On a closer look, none of the changes here make sense to me but maybe I'm missing the problem |
The change I made is related to switching code formatters per project. |
I think @mfussenegger 's suggestion make sense. Just for clarifications, let me explain the backgrounds to open this PR. I am switching formatter by looking at files in the -- This used to be string|nil, but recently it became function.
local root_dir = vim.lsp.get_clients({name = "ts_ls", bufnr = vim.api.nvim_get_current_buf()})[1].root_dir I was surprised because LSP showed |
…unction neovim#36071" This reverts commit 97ab24b. See discussion in neovim#36071
Sounds like there is a call to |
fun
, not only string|nil
fun
, not only string|nil
One thing to add here: We could change local conf = vim.lsp.config.myserver
if type(conf.root_dir) == "function" then
conf.root_dir(bufnr, function(root_dir)
conf.root_dir = root_dir
vim.lsp.start(conf)
end)
else
vim.lsp.start(conf)
end What we shouldn't do because it is breaking is the example you gave with: -- This used to be string|nil, but recently it became function.
local root_dir = vim.lsp.get_clients({name = "ts_ls", bufnr = vim.api.nvim_get_current_buf()})[1].root_dir The exposed But there's also still in the air to revert local conf = vim.lsp.config.myserver
if type(conf) == "function" then
conf(bufnr, function(fullconf)
vim.lsp.start(fullconf)
end)
else
vim.lsp.start(conf)
end Or maybe something like: vim.lsp.get_config(function(conf)
vim.lsp.start(conf)
end) |
…unction" neovim#36183 This reverts commit 97ab24b. See discussion in neovim#36071
This PR improves type annotation of
vim.lsp.Config.root_dir
by allowing function as documented in https://neovim.io/doc/user/lsp.html#lsp-root_dir().The fix also required changes in
vim.lsp._get_workspace_folders
and:checkhealth vim.lsp
.I ran
:cheackhealth vim.lsp
and confirmedroot_dir
as function works in monorepo with ts_ls.