mage
mage copied to clipboard
Bug: Spurious errors reported by gopls with go1.17 (in vscode)
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.
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 Do you have a workaround?
@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