mage icon indicating copy to clipboard operation
mage copied to clipboard

Bug: Spurious errors reported by gopls with go1.17 (in vscode)

Open Michael-F-Ellis opened this issue 2 years ago • 3 comments

Bug Description This is likely gopls problem rather than a mage problem but it seems worth posting here in hopes someone knows a workaround.

I've filed a thorough report at

  • https://github.com/golang/vscode-go/issues/1852

and created a minimal repository that reproduces the problem when opened in vscode

  • https://github.com/Michael-F-Ellis/magegopls

Briefly, the problem arises when putting a magefile in a package directory. It seems that the latest gopls doesn't take the go:build mage directive into account and then chokes on seeing a file with package main among the package files. On the other hand, go vet, go build and mage are perfectly happy with the situation and run without errors or warnings.

Changing the magefile package name to match the package pacifies gopls, but then mage no longer works.

Michael-F-Ellis avatar Oct 21 '21 18:10 Michael-F-Ellis

This is likely because you have added the "mage" tag to gopls, so it includes the mage files with the rest of the files it analyzes. This is a common problem, and one we hope to fix with #395

natefinch avatar Dec 17 '21 19:12 natefinch

@natefinch Do you have a workaround?

guiyomh avatar Mar 02 '22 10:03 guiyomh

@guiyomh with the recent release which adds support for the magefiles directory you could put your mage files there, no need for the tag. See https://magefile.org/magefiles/#magefiles-directory for more details

perrito666 avatar Mar 18 '22 13:03 perrito666