Open diegobernardes opened 5 years ago
What linter is complaining about no main function, do you know? Honestly, that seems like a pretty unhelpful linter, since the compiler will tell you that you have no main function.
On Mon, Aug 27, 2018, 5:09 PM Diego Bernardes notifications@github.com wrote:
I'm using vscode. This is the first issue:
can't load package: package github.com/diegobernardes/flare: build constraints exclude all Go files in /Users/diego.bernardes/Projects/go/src/github.com/diegobernardes/flare
Ok, this is because the: // +build mage. So i added the build tag config: "go.buildTags": "mage". Problem solved.
And now the second issue:
github.com/diegobernardes/flare\nruntime.main_main·f http://github.com/diegobernardes/flare%5Cnruntime.main_main%C2%B7f: function main is undeclared in the main package
This one i don't know how to solve it. And a question, maybe it's better work with the current folder name instead of the package main.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/magefile/mage/issues/139, or mute the thread https://github.com/notifications/unsubscribe-auth/ADCcyHLWvrzGLcbJihc3gLCJMtQOj1Jaks5uVHxDgaJpZM4WOpRy .
Ahh, I figured it out. VSCode defaults to "build on save". Which I personally don't like, so I always turn it off. "go.buildOnSave": "off"
I'll put this up on the website at some point for posterity.
@diegobernardes if you want the build-on-save on, I found that this works:
"go.buildTags": "mage vscode"
in the settings, and then create a dummy .go file with
// +build vscode
package main
func main() {}
@gsmcwhirter, yes, that solves 👍
The thing is, the magefile.go
requirement to be at package main
that is the problem. Why it can't work using only the build tags? I really don't know the interns of the package, so I may be saying something that can't work, but it's really just a question.
It's kinda bad to choose between always having a "error" at the magefile.go
and disabling the build on save on the entire project.
In theory it doesn't have to be package main... But that would be a tricky change. We'd have to generate the main file in a different directory and import the current directory. And we'd have to support current uses that do use package main.
I'll have to think about it some more.
I'm seeing a problem that seems related to this. When I open my magefile in vscode, there's no linting or intelliSense. Making any change to the file restores both within a couple of seconds and they remain on even after undoing the change (and saving the unchanged file so git can figure out that it's still the same).
The good state persists even if I close and reopen the magefile within the same session, but is lost if I quit vscode and restart.
I just tried adding "go.buildTags": "mage"
to my settings.json. No change in behavior. Haven't tried the dummy.go trick yet 'cause it feels, well, hack-ish.
I'm running vscode 1.45.1 on darwin 18.7. Gopls is up to date and I'm linting with revive (have tried it with golang-ci, no help)
Any suggestions?
BTW, thanks for creating and maintaining Mage -- it's the bomb. I say that as someone who's been writing (and cursing) Makefiles since the 80's.
I don't get any linter errors the following way:
mage -init
mage
in VS Code Go extension settings ("go.buildTags": "mage"
)
package main
if the magefile is in a directory which doesn't have any Go files with a main()
function, or if it's in a directory that already has a Go file with a package name other than main
magefiles
and move the magefile to it
go.mod
, which you might not want (for example if your project is a library and not an executable, then when other devs import your library you don't want mage and it's dependencies to end up as transitive dependencies their project)go mod init github.com/exampleuser/examplerepo/magefiles
magefiles
directory as root for working on the magefileThis way I don't get any linter or build errors. buildOnSave
is enabled.
This seems related to issue #344. Would it be possible for mage to not rely on package name main
for example? I think that would make Go not complain about lack of main function. Separate go.mod
file seems like a viable workaround though, thanks for sharing.
I'm using vscode. This is the first issue:
Ok, this is because the:
// +build mage
. So i added the build tag config:"go.buildTags": "mage"
. Problem solved.And now the second issue:
This one i don't know how to solve it. And a question, maybe it's better work with the current folder name instead of the
package main
.