Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/govim: add config for defining the gopls environment
gopls can be configured with an environment, an environment which is passed to go/packages. For example, setting GOOS and GOARCH, or setting GOFLAGS=-tags=other to set a build tag. Therefore we define a govim config key, "GoplsEnv", for setting this environment. For example: govim#config#Set("GoplsEnv", {"GOFLAGS": "-mod=readonly"}) As part of this add a test that verifies the behaviour of the above setting. Setting of build tags does not current work; that is blocked on golang/go#35548 and will be tested in a follow up PR. Fixes #555
- Loading branch information
Showing
6 changed files
with
111 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
cmd/govim/testdata/scenario_modreadonly/config_set_env_goflags_mod_readonly.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Test that calling govim#config#Set with a value for GoplsEnv of GOFLAGS | ||
# does the right thing. This will necessarily involve a number of checks | ||
# for the various build flags that can be set via GOFLAGS. | ||
|
||
env | ||
vim ex 'e main.go' | ||
errlogmatch -wait 30s 'PublishDiagnostics callback: &protocol.PublishDiagnosticsParams{\n\S+:\s+URI:\s+"file://'$WORK/main.go | ||
vim ex 'copen' | ||
vim ex 'w errors' | ||
vim ex 'cclose' | ||
cmp errors pre.golden | ||
vim ex 'w' | ||
|
||
# Verify go.mod has not changed | ||
cmp go.mod go.mod.golden.pre | ||
|
||
# Change go.mod from outside Vim | ||
exec go get example.com/blah@v1.0.0 | ||
exec go mod tidy | ||
cmp go.mod go.mod.golden.post | ||
|
||
# Verify the diagnostic has been updated | ||
errlogmatch -wait 30s 'PublishDiagnostics callback: &protocol.PublishDiagnosticsParams{\n\S+:\s+URI:\s+"file://'$WORK/main.go | ||
vim ex 'copen' | ||
vim ex 'w errors' | ||
vim ex 'cclose' | ||
cmp errors post.golden | ||
|
||
# Disabled pending resolution to https://github.com/golang/go/issues/34103 | ||
# errlogmatch -count=0 'LogMessage callback: &protocol\.LogMessageParams\{Type:(1|2), Message:".*' | ||
|
||
-- go.mod -- | ||
module mod.com | ||
|
||
go 1.13 | ||
-- go.mod.golden.pre -- | ||
module mod.com | ||
|
||
go 1.13 | ||
-- go.mod.golden.post -- | ||
module mod.com | ||
|
||
go 1.13 | ||
|
||
require example.com/blah v1.0.0 | ||
-- main.go -- | ||
package main | ||
|
||
import "example.com/blah" | ||
|
||
func main() { | ||
println(blah.Name) | ||
} | ||
-- pre.golden -- | ||
main.go|3 col 8| could not import example.com/blah (no package for import example.com/blah) | ||
-- post.golden -- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"GoplsEnv": {"GOFLAGS": "-mod=readonly"} | ||
} |