magefile / mage

a Make/rake-like dev tool using Go
https://magefile.org
Apache License 2.0
4.02k stars 250 forks source link

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

Open Michael-F-Ellis opened 2 years ago

Michael-F-Ellis commented 2 years ago

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

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

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.

natefinch commented 2 years ago

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

guiyomh commented 2 years ago

@natefinch Do you have a workaround?

perrito666 commented 2 years ago

@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