CopilotChat.nvim icon indicating copy to clipboard operation
CopilotChat.nvim copied to clipboard

Commit cf02033 breaks neotest

Open fredrikaverpil opened this issue 8 months ago • 6 comments

Hi!

I noticed that after upgrading CopilotChat.nvim, Neotest wouldn't detect any tests anymore. I tracked it down to commit cf02033, added in #1046.

I simply ran a git revert cf02033 locally for CopilotChat.nvim and now tests are detected just fine again.

I haven't had time to dig into why this commit is problematic, and if it comes down to my setup or what the root cause really is. But I figured I'd post about it here in case others are experiencing something similar.

fredrikaverpil avatar Apr 07 '25 06:04 fredrikaverpil

That is very weird. And this breaks without even opening copilot chat or doing anything with it? For now I added to not eagerly require from plugin/CopilotChat.lua, maybe that helps if you want to try latest commit but this looks like bug in either neotest or plenary.nvim to me at least (plenary.nvim has pretty odd behaviour where they are loading the filetype detect stuff on first require, which I guess could cause problems maybe?)

deathbeam avatar Apr 07 '25 06:04 deathbeam

@deathbeam I just updated to the latest commit 16f041e but that unfortunately did not help. Neotest reports "No tests found". I had to revert back again for the tests to be found.

I agree, this seems strange indeed.

fredrikaverpil avatar Apr 07 '25 06:04 fredrikaverpil

And this breaks without even opening copilot chat or doing anything with it?

Yes, I haven't opened CopilotChat.nvim at all, but it is loaded. Here is my config for reference: https://github.com/fredrikaverpil/dotfiles/blob/989012de4f9866f76179cba9ad1376e32713b133/nvim-fredrik/lua/fredrik/plugins/copilot_chat.lua

fredrikaverpil avatar Apr 07 '25 06:04 fredrikaverpil

@deathbeam I know this is not a long-term solution, but by moving the import into the function, the problem with Neotest is gone:

-  local filetype = require('plenary.filetype')

function M.filetype(filename)
+  local filetype = require('plenary.filetype')
  local ft = filetype.detect(filename, {
    fs_access = false,
  })

  if ft == '' then
    return nil
  end
  return ft
end

Would it be ok with you to make this change?

fredrikaverpil avatar May 01 '25 14:05 fredrikaverpil

@deathbeam I know this is not a long-term solution, but by moving the import into the function, the problem with Neotest is gone:

  • local filetype = require('plenary.filetype')

function M.filetype(filename)

  • local filetype = require('plenary.filetype') local ft = filetype.detect(filename, { fs_access = false, })

if ft == '' then return nil end return ft end Would it be ok with you to make this change?

Hmm, sure if you make PR I dont mind. but please add comment next to it explaining why its there (link to this issue might be enough I guess)

deathbeam avatar May 01 '25 14:05 deathbeam

Hey again @deathbeam I managed to reconfigure my lazy.nvim setup so that Neotest calls require("plenary.filetype") before CopilotChat does. This completely fixed the issue for me and now both Neotest and CopilotChat works as expected.

I opened https://github.com/nvim-neotest/neotest/issues/502 and we can see if we get any input from that first, before moving the require statement into the function.

fredrikaverpil avatar May 01 '25 16:05 fredrikaverpil

moving that 'require("plenary.filetype")' inside the function does solve it for me too. We're not getting much traction on this issue on neotest. Maybe commit this change?

ruicsh avatar Jun 15 '25 22:06 ruicsh

Closing, fixed by #1162 (even as a workaround)

deathbeam avatar Jun 16 '25 10:06 deathbeam