Skip to content

Commit

Permalink
fix(watch): use old lsp supports method for v0.10.1 (#456)
Browse files Browse the repository at this point in the history
* fix(watch): fixed neotest.watch starting problem

On the version v0.10.1, supports_method is still a table, rather than
a function. Code was trying to call a regular table field as a function,
resulting in following error:

attempt to call field 'supports_method' (a table value)

Now the type of the client.supports_method is checked beforehand,
instead of accessing the method right away.

* fix(watch): edge case in case neither client is found

* fix(watch): instead of type, checking the nvim version instead

Basically 1:1 code @rcasia proposed.
  • Loading branch information
straightchlorine authored Oct 2, 2024
1 parent 48f8b5f commit 245a65e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lua/neotest/consumers/watch/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,20 @@ neotest.watch = {}
local function get_valid_client(bufnr)
local clients = nio.lsp.get_clients({ bufnr = bufnr })
for _, client in ipairs(clients) do
local has_definition_support = client.supports_method
and client.supports_method("textDocument/definition")
local has_definition_support
if nio.fn.has("nvim-0.10.1") == 0 then
-- for compatibility with Neovim versions earlier than v0.10.1
or client.server_capabilities.definitionProvider
has_definition_support = client.server_capabilities ~= nil
and client.server_capabilities.definitionProvider
else
has_definition_support = client.supports_method.textDocument_definition({ bufnr = bufnr })
end

if has_definition_support then
logger.debug("Found client", client.name, "for watch")
return client
else
logger.debug("Client for watch not found")
end
end
end
Expand Down

0 comments on commit 245a65e

Please sign in to comment.