ray-x / go.nvim

G'day Nvimer, Joyful Gopher: Discover the Feature-Rich Go Plugin for Neovim
MIT License
1.91k stars 119 forks source link

JSON style log output from failing test breaks :GoTestFile #405

Closed jhillyerd closed 6 months ago

jhillyerd commented 7 months ago

I'm not sure where the issue lies, but go.nvim could be the culprit, as I removed all my other plugins and still see the issue. It appears that test ouput containing JSON blocks (ie text with { and } in them) triggers the issue.

What I did

To reproduce, create a new go repo with the following files:

main.go

package main

func main() {
    println("hello wrld")
}

main_test.go

package main_test

import (
    "testing"
)

func TestFail(t *testing.T) {
    println(`{"level":"debug","module":"storage","path":"/tmp/inbucket2207906097/mail/88d/88db92/88db9292c772b38311e1778f6f6b18216443abf0/index.gob","time":"2023-11-28T19:00:43-08:00","message":"Index does not yet exist"}`)
    t.Fatal("super fail")
}

Open main_test.go in neovim, and run

:GoTestFile
:q
:GoTestFile

What I expect

I would expect the sequence of commands above to display the failing test output in the quickfix window, close the quickfix window, and then display the output of the re-run test.

What I got

Instead, the second attempt to run the test triggers an error somewhere in Lua land.

Commenting out the println, or removing the leading & trailing {} from the printed string stop the issue from triggering.

vim verbose output:

continuing in BufWinEnter Autocommands for "*"

Executing BufWinEnter Autocommands for "*"
autocommand call s:Highlight_Matching_Pair()

calling <SNR>55_Highlight_Matching_Pair

calling <SNR>55_Remove_Matches

<SNR>55_Remove_Matches returning #0

continuing in <SNR>55_Highlight_Matching_Pair

calling <lambda>19

<lambda>19 returning #0

continuing in <SNR>55_Highlight_Matching_Pair

Exception thrown: Vim(call):E801: ID already taken: 3

<SNR>55_Highlight_Matching_Pair aborted

continuing in BufWinEnter Autocommands for "*"

Exception discarded: Vim(call):E801: ID already taken: 3

BufWinEnter Autocommands for "*"..function <SNR>55_Highlight_Matching_Pair, line 149: Vim(call):E801: ID already taken: 3
stack traceback:
^I[C]: in function 'setqflist'
^I...s/.local/share/nvim/plugged/go.nvim/lua/go/asyncmake.lua:369: in function <...s/.local/share/nvim/plugged/go.nvim/lua/go/asyncmake.lua:264>
ray-x commented 7 months ago

I ran your steps a few times. Does not reproduce

image

jhillyerd commented 7 months ago

I'll try building an empty neovim config w/ go.nvim and see if I can still make it happen, perhaps its a setting in my config or a bug in my version of nvim.

jhillyerd commented 7 months ago

@ray-x I made a brand new nvim config with just go.nvim and treesitter, and the issue still repros on nvim 0.9.4 for me.

I found https://stackoverflow.com/questions/34675677/disable-highlight-matched-parentheses-in-vim-let-loaded-matchparen-1-not-w -- and discovered that adding let g:loaded_matchparen = 1 to init.vim prevents the error. Do you also have matchparen disabled?

In theory set noshowmatch and :NoMatchParen should have similar effect, but didn't work. They robably have to be added to an autocmd and not directly to init.vim

Edit: I've uploaded the minimal config I was experimenting with https://github.com/jhillyerd/minimal-go.nvim

ray-x commented 7 months ago

I am sure the minium vimrc in playground folder dose not have g:loaded_matchparen=1 setting.

I also tried your config but still not able to reproduce

image
jhillyerd commented 7 months ago

Hmm, struggling a bit with the playground. When I do nvim -u ../init_lazy.lua pkg/findAllSubStr_test.go and try to run the tests, it blows up. Perhaps a nvim 0.9.4 compat issue? Edit: still fails on 0.9.1

Error executing Lua callback: ...ed-0.9.4/share/nvim/runtime/lua/vim/treesitter/query.lua:259: query: invalid node type at position 3406 for language lua                           
stack traceback:
[C]: in function '_ts_parse_query'
...ed-0.9.4/share/nvim/runtime/lua/vim/treesitter/query.lua:259: in function 'get'
...4/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:114: in function 'new'
...nwrapped-0.9.4/share/nvim/runtime/lua/vim/treesitter.lua:61: in function '_create_parser'
...nwrapped-0.9.4/share/nvim/runtime/lua/vim/treesitter.lua:131: in function 'get_parser'
...nwrapped-0.9.4/share/nvim/runtime/lua/vim/treesitter.lua:459: in function 'start'
...m/lazy/nvim-treesitter/lua/nvim-treesitter/highlight.lua:20: in function 'attach'
/tmp/nvim/lazy/guihua.lua/lua/guihua/util.lua:274: in function 'highlighter'
/tmp/nvim/lazy/guihua.lua/lua/guihua/sprite.lua:125: in function 'initialize'
/tmp/nvim/lazy/guihua.lua/lua/middleclass.lua:181: in function 'new'
/tmp/nvim/lazy/go.nvim/lua/go/asyncmake.lua:252: in function 'run_test'
/tmp/nvim/lazy/go.nvim/lua/go/gotest.lua:366: in function 'test'
/tmp/nvim/lazy/go.nvim/lua/go/commands.lua:186: in function </tmp/nvim/lazy/go.nvim/lua/go/commands.lua:185>

However the tests will run with init_packer.lua

I am able to get the issue to repro, but it requires me to disable floating terminals run_in_floaterm = false -- so the problem must be specific to the quickfix window.

jhillyerd commented 7 months ago

I was able to repro the ID already taken 3 issue with the Ubuntu snap of neovim 0.9.1, so it does not appear to be specific to 0.9.4 -- and the 0.9.4 was on NixOS, so two different Linux distros as well.

jhillyerd commented 6 months ago

I was able to reproduce this without go.nvim at all, just by running :cexpr system('go test') a couple times, closing the quickfix window in between. I believe it's a bug in nvim itself.