Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

vscode reports "//+build ignore" as error #1601

Closed
hex2010 opened this issue Apr 1, 2018 · 8 comments
Closed

vscode reports "//+build ignore" as error #1601

hex2010 opened this issue Apr 1, 2018 · 8 comments

Comments

@hex2010
Copy link

hex2010 commented Apr 1, 2018

Steps to Reproduce:

  1. create a new main package
  2. add//+build ignore
  3. vscode reports "can't load package: package ... build constraints exclude all Go files in ...."

code:

//+build ignore

package main

func main() {}
@ramya-rao-a
Copy link
Contributor

You need to update the go.buildTags setting so that the Go extension will know which build tags to use when building your code. Add the below in your settings file:

"go.buildTags": "ignore"

@hex2010
Copy link
Author

hex2010 commented Apr 4, 2018

added "go.buildTags": "ignore" to workspace settings, error raise other place:

//+build ignore

package main

import (
	"crypto/x509"  // <- error here
...

found packages tls (alert.go) and main (generate_cert.go) in /go/src/crypto/tls

@hex2010
Copy link
Author

hex2010 commented Apr 4, 2018

ok. I found the solution: rename the tag to "ignore1" and add it to go.buildTags, errors gone

EDIT:

sorry, I reload the workspace, error appear again:

can't build package  example/cpp because it contains C++ files (example.cpp,test.cpp) but it's not using cgo nor SWIG

I think this package should not be compiled at all

@ramya-rao-a
Copy link
Contributor

What is the purpose of the ignore build tag here?
You want to ignore the current package and not build it?

@hex2010
Copy link
Author

hex2010 commented Apr 5, 2018

this directory is not a "package" but a c++ project, golang files in it are all tool scripts, should run with go run xxxx.go, not for go build.

@ramya-rao-a
Copy link
Contributor

Ok, in that case we shouldnt add "ignore" to the `go.buildTags" setting.

I am not sure how to move forward here.

The error "can't load package: package ... build constraints exclude all Go files in ...." is indeed correct, as you dont want the current file to be built. You are using the "ignore" build constraint to exclude the Go files in the current folder. Since there is no way to exclude files from being built by the Go extension, I am not sure how to proceed other than ignoring the error.

Do you have any suggestions?

@defjosiah
Copy link

defjosiah commented Apr 10, 2018

Running into a similar issue here, I have a folder called:
# $GOPATH/github.com/user/myproject/
integration_test/
--integration_test_suite.go
--integration_test.go

And I'm getting the error:

go build github.com/user/myproject/integration_test: no non-test Go files in /home/go/src/github.com/user/myproject/integration_test

Maybe add a folder ignore option to the go extension? And then check it here (https://github.com/Microsoft/vscode-go/blob/master/src/goBuild.ts#L51)?

@ramya-rao-a
Copy link
Contributor

The April Iteration Plan for VS Code has an item for "Problems view support to exclude errors for some files/folders". Getting the ignore support from the core is better than the Go extension implementing its own.

Closing this issue in favor of the upstream feature.

@vscodebot vscodebot bot locked and limited conversation to collaborators May 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants