Closed antoineco closed 1 month ago
Hey 👋
Thanks for the detailed report. ~I'm a bit confused. The warning note says you couldn't reproduce this with the minimal config, but you ticked off the checkbox saying you can?~
This could also be a neotest issue. Are you getting the same error with any other adapters?
I see you've added neotest-golang to the minimal config. Does it not occur without it?
(Note: I'm traveling this weekend, so I probably won't get back to this before Tuesday)
I think I managed to narrow the issue down and updated the description.
If I disable the neotest-golang
adapter by commenting require "neotest-golang"
, I can no longer reproduce the issue.
What is confusing to me is that neotest-golang
itself exhibits no problem at all. I can open Go tests and run them without causing an error. Likewise, I can run Rust tests without error when neotest-golang
is out of the picture, but not when the two are enabled.
Additionally, the error occurs only on the first test run. If I retry, the tests run without error.
Hmm, that's very curious indeed. It looks like the error is thrown here.
I'm not sure, but this looks like a neotest issue. Does it happen with any other combination of adapters?
E.g.
Or is it just neotest-go combined with rustaceanvim?
I haven't tried any other combination of adapters yet, but will do and report here ASAP. Enjoy your vacation! 🙌
I observed something quite curious which I think is worth adding.
I cannot reproduce the issue if I run the tests before rust-analyzer has finished indexing the project.
But if I run tests after rust-analyzer is done indexing ([Indexing] (100%)
received through LspProgress
events), the issue occurs consistently in the conditions explained in the description.
Author of neotest-golang here 😄 did you get around to check if this also happens if you e.g. switch out one of the adapters for another one?
I'm using the neotest-golang and neotest-plenary side-by-side in the neotest-golang repo and I'm not seeing any issues:
You can try it out here in the neotest-golang repo if you wish, to see if you get the same issues there. Here's my lua setup: https://github.com/fredrikaverpil/dotfiles/blob/03e93510aa5897b35b5729f17e3dcc323d80e82d/nvim-fredrik/lua/lang/lua.lua
did you get around to check if this also happens if you e.g. switch out one of the adapters for another one?
Same here. I use rustaceanvim together with neotest... -haskell, -busted, and -java, and haven't faced any issues.
I have yet to find time to reproduce this with -golang.
I cannot reproduce the issue if I run the tests before rust-analyzer has finished indexing the project.
This makes me think that it has to be rustaceanvim in combination with another adapter. @antoineco is your example from a cargo project or a standalone file? If the former, could you please provide a project or steps to create the project (including any other files and the cwd).
is your example from a cargo project or a standalone file? If the former, could you please provide a project or steps to create the project (including any other files and the cwd).
I noticed the issue while working on this code specifically: https://github.com/antoineco/adventofcode2023
@fredrikaverpil I tried with neotest-plenary
and neotest-golang
like you suggested.
I don't get the error when neotest-plenary
is loaded (included in the adapters
table), regardless of the timing explained in https://github.com/mrcjkb/rustaceanvim/issues/399#issuecomment-2118680313. But I do as soon as I uncomment neotest-golang
in the configuration below:
{
"nvim-neotest/neotest",
dependencies = {
"nvim-neotest/nvim-nio",
"antoinemadec/FixCursorHold.nvim",
-- adapters
{
"nvim-neotest/neotest-plenary",
"fredrikaverpil/neotest-golang"
}
},
config = function()
require "neotest".setup {
adapters = {
require "neotest-plenary",
--require "neotest-golang",
require "rustaceanvim.neotest"
}
}
end
}
I updated the additional notes in the issue description with this new information.
I just tried running lua/go/rust tests in the neotest-golang repo, and I can't see any issues on my end. I know it doesn't hold a lot of tests so it's nearly a minimal reproducible example of that you should be able to combine multiple adapters like this, without issues.
https://github.com/mrcjkb/rustaceanvim/assets/994357/bf7c6600-0946-4b10-9b9c-05f91be9f659
I took a quick look at the stacktrace you posted. In the Neotest StateTracker.update_running
method, there's a call to the StateTracker.is_test
method, which is crashing because the tree
variable is unexpectedly nil
. I haven't really read all the code and I'm just guessing now, but I would assume this code is related to updating the state of the tests (like if they are running, if they passed, failed or were skipped). For some reason, on your end, it looks like there is a problem with updating one or more tests due to some unknown reason.
I would probably start out with adding in some poor man's debug print statements (like print(vim.inspect(tree))
into the update_running
method (on macOS it's something like ~/.local/share/neovim/lazy/neotest/lua/neotest/consumers/state/tracker.lua
). It would for example be interesting to print the name of the test being updated and the value of tree
. I would also disable other plugins just to see if something else is interfering, perhaps interfering with the AST parsing (seems odd though).
If you still can't find anything, it would be helpful if you could set up a new GitHub repo where you can consistently reproduce the issue.
@fredrikaverpil I cannot reproduce the issue either using your method of opening the Neotest summary and running the tests from there. However, this is not how the issue manifests itself to me.
In the case described here, the problem occurs:
require "neotest".run.run()
(via a keybinding, but that's irrelevant here).:thinking:
I can't reproduce this if I add the adapters in this order:
{
require('rustaceanvim.neotest'),
require('neotest-golang'),
}
but I can if I add them in this order:
{
require('neotest-golang'),
require('rustaceanvim.neotest'),
}
@rcarriga maybe you have some insights?
It looks like it's something related to task management in nvim-nio.
I used nio.control.future()
to wait for the experimental/runnables
LSP response, and the error is thrown when calling future.set(runnables)
.
I've refactored that to use nio.lsp.Client
, but it still results in the same error if neotest-golang is added before rustaceanvim.neotest.
Just having a look, I think this is a race condition issue from when events are processed by the state consumer. For context, the state consumer is basically just providing a way to interact with the state of neotest without having to run async code.
It assumes that events are processed sequentially but there is really no guarantee to that. I've put in a very simple change in a branch fix/consumers-state/wrap-listeners
that might address the issue, but I'll need @antoineco to test if you could? If that doesn't work, it'll likely be a larger fix.
Alternatively you can just disable the consumer by passing
state = {
enabled = false
},
in your neotest config
@rcarriga I just checked out your fix/consumers-state/wrap-listeners
branch and replicated the same procedure as described in this issue, multiple times just to be sure.
Out of my ~10 attempts the issue didn't materialize a single time. I'm fine considering the issue resolved. Thank you very much! 🙌
Have you read the docs and searched existing issues?
Neovim version (nvim -v)
v0.10.0
Operating system/version
Debian 12 (bookworm)
Output of :checkhealth rustaceanvim
How to reproduce the issue
Open the following Rust file using the minimal configuration below:
Type
,tt
to run the nearest test, and observe the issue.Expected behaviour
The test runs without throwing an error.
Actual behaviour
The following error is thrown:
The minimal config used to reproduce this issue.
Additional notes
(keeping this section up to date with the comments)
If I disable the
neotest-golang
adapter by commentingrequire "neotest-golang"
, I can no longer reproduce the issue.neotest-golang
itself exhibits no problem at all. I can open Go tests and run them without causing an error. Likewise, I can run Rust tests without error whenneotest-golang
is out of the picture, but not when the two are enabled.I cannot reproduce the issue with another adapter than
neotest-golang
, such as neotest-plenary or neotest-python. The issue seems to only materialize whenneotest-golang
is included in theadapters
table.The error occurs only on the first test run. If I retry, the tests run without error.
I cannot reproduce the issue if I run the tests before rust-analyzer has finished indexing the project. But if I run tests after rust-analyzer has finished indexing (
[Indexing] (100%)
received throughLspProgress
events), the issue occurs consistently in the conditions explained above.