x/tools/gopls: support dynamic switching based on active editor with single build tag #65089
Labels
FeatureRequest
Issues asking for a new feature that does not need a proposal.
gopls/metadata
Issues related to metadata loading in gopls
gopls
Issues related to the Go language server, gopls.
Tools
This label describes issues relating to any tools in the x/tools repository.
Milestone
gopls version
go env
What did you do?
To reproduce, consider a package
cipher
with three files:In
rot13.go
we have a template (empty implementation) that is supposed to fail tests:In
rot13_sol.go
we have an implementation (details excluded) that is supposed to pass tests:In
rot13_test.go
we have tests:From the command line, I can test that the template version fails because the
solution
tag is not set:Similarly, the
rot13_sol.go
version passes the tests because thesolution
tag is set:This approach is convenient because I can keep the template, test, and solution in the same folder.
What did you see happen?
With VSCode, I can do:
To enable compilation of the
rot13_sol.go
file, and switch to-tags=!solution
to enable compilation of therot13.go
file.However, it is not possible to avoid the error:
It is also annoying to have to switch the build tag in the configuration to take advantage of gopls, e.g., to rename a field or type.
What did you expect to see?
For this simple case with a single build tag, it should be possible to dynamically switch between compiling for the build tag and its negation based on the active editor window, removing the error from source files whose tag is the negation.
I'm opening this issue separately from the global issue about improving build tags support (#29202) to find out if this is a common enough pattern that makes it worth fixing on its own.
It seems unlikely that we will get support for advanced constraints like
//go:build (solution || experiment)
because of the complexity involved, at least in the near term. So one question would be if users would expect this to work too and thus become confused when it doesn't. One counter-argument is that detecting such constraints and providing an appropriate error message should be possible.Editor and settings
No response
Logs
No response
The text was updated successfully, but these errors were encountered: