nvim-neotest / neotest-go

MIT License
125 stars 43 forks source link

Fails when Go code is in a subdirectory (e.g. in a polyglot project) #19

Closed mrjones2014 closed 1 year ago

mrjones2014 commented 1 year ago

Not sure if this is an issue with neotest-go or neotest -- let me know if I should move it.

I have a project with multiple languages in use, and my Go code lives under a go/ subdirectory. When running tests with a Go file open, it should try to find the closest go.mod file to the current file, and run the go test command with that directory as its working directory.

Currently it just runs tests in current working directory, which does not work for this use case.

akinsho commented 1 year ago

Hi @mrjones2014,

No idea why this would be the case, nor if it's an issue with neotest or this adapter. Looking at

https://github.com/nvim-neotest/neotest-go/blob/d506f831d03f91a14f47e1ea0011b0f286c4e0d9/lua/neotest-go/init.lua#L294-L304

These files should be detected regardless, I work in a mixed language monorepo and go tests run fine for me 🤷🏿‍♂️ not sure what your exact layout is though.

In any event people tend to investigate and contribute fixes for any issues they encounter themselves, just mentioning since issues opened here are unlikely to advance without the author raising a PR

mrjones2014 commented 1 year ago

In any event people tend to investigate and contribute fixes for any issues they encounter themselves, just mentioning since issues opened here are unlikely to advance without the author raising a PR

Sure, I'm willing to. I might be able to get to it next week or so.

For reference, I'm working in this repo: https://github.com/mrjones2014/op.nvim

And this is the error I get: image

mrjones2014 commented 1 year ago

Interestingly, :lua print(require('neotest-go').root(vim.fn.expand('%'))) does return the correct directory, but I still get the error I screenshotted above 🤔

mrjones2014 commented 1 year ago

Pretty sure this was user error. Moving my go.mod and go.sum to the root, but keeping my Go sources under go/ works.

eterps commented 1 year ago

Hmm, I had a similiar problem, it seems that the does not contain main module error message occurs when you are within a symlinked directory. When I went to the actual directory that message suddenly vanished.

breneser commented 1 year ago

Interestingly, :lua print(require('neotest-go').root(vim.fn.expand('%'))) does return the correct directory, but I still get the error I screenshotted above 🤔

I am having the same problem. I never had this issue with fatih/vim-go plugin.

My setup is as below:

GOPATH=~/projects/core Go code is under ~/projects/core/src/ttx Vim root(pwd) is ~/projects/core

lua print(require('neotest-go').root(vim.fn.expand('%'))) correctly identifies the root as ~/projects/core/src/ttx

When I change cwd in vim doing cd src/ttx the test runs correctly, but it does not If stay in actual project root which is ~/projects/core

It is not an option for me to move go.mod or go.sum out to ~/projects/core

hay-kot commented 1 year ago

@breneser - did you ever find a solution? I'm in the same boat working in a mono-repo.