Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vscode-go sets GOFLAGS, breaking go modules #1595

Closed
trapgate opened this issue Jun 28, 2021 · 16 comments
Closed

vscode-go sets GOFLAGS, breaking go modules #1595

trapgate opened this issue Jun 28, 2021 · 16 comments

Comments

@trapgate
Copy link

What version of Go, VS Code & VS Code Go extension are you using?

  • Run go version to get version of Go from the VS Code integrated terminal.
    • go version go1.16.5 linux/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    • golang.org/x/tools/gopls v0.7.0
      golang.org/x/tools/gopls@v0.7.0 h1:JQBHW81Gsyim6iDjUwGoPeSpXrSqwen3isPJLfDfaYU=
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • 1.57.1
      507ce72a4466fbb27b715c3722558bb15afa9f48
      x64
  • Check your installed extensions to get the version of the VS Code Go extension
    • v0.26.0
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.

Checking configured tools....
GOBIN: undefined
toolsGopath:
gopath: /home/geoff/go
GOROOT: /usr/lib/go
PATH: /usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/snap/bin:/home/geoff/bin:/home/geoff/.local/bin:/home/geoff/go/bin:/home/geoff/mygo/bin

gopkgs: /home/geoff/mygo/bin/gopkgs installed
go-outline: /home/geoff/mygo/bin/go-outline installed
gotests: /home/geoff/mygo/bin/gotests installed
gomodifytags: /home/geoff/mygo/bin/gomodifytags installed
impl: /home/geoff/mygo/bin/impl installed
goplay: /home/geoff/mygo/bin/goplay installed
dlv: /home/geoff/mygo/bin/dlv installed
dlv-dap: dlv-dap not installed
staticcheck: /home/geoff/mygo/bin/staticcheck installed
gopls: /home/geoff/mygo/bin/gopls installed

go env
Workspace Folder (go-libvirt): /home/geoff/do/go-libvirt
GO111MODULE="auto"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/geoff/.cache/go-build"
GOENV="/home/geoff/.config/go/env"
GOEXE=""
GOFLAGS="-mod=vendor"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/geoff/go/pkg/mod"
GONOPROXY=".internal.digitalocean.com,github.com/digitalocean"
GONOSUMDB="
.internal.digitalocean.com,github.com/digitalocean"
GOOS="linux"
GOPATH="/home/geoff/go"
GOPRIVATE="*.internal.digitalocean.com,github.com/digitalocean"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.5"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="0"
GOMOD="/home/geoff/do/go-libvirt/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1435964199=/tmp/go-build -gno-record-gcc-switches"

Share the Go related settings you have added/edited

{
"go.coverOnSave": true,
"go.coverOnSingleTest": true,
"go.autocompleteUnimportedPackages": true,
"go.testOnSave": true,
"go.useLanguageServer": true,
],
"go.coverageDecorator": {
"type": "highlight",
"coveredHighlightColor": "rgba(32,64,64,0.4)",
"uncoveredHighlightColor": "rgba(128,64,64,0.2)",
"coveredGutterStyle": "slashblue",
"uncoveredGutterStyle": "slashyellow"
},
"go.coverOnSingleTestFile": true,
"go.toolsEnvVars": {
},
"go.toolsManagement.autoUpdate": true,
}

Describe the bug

I work on some repos that are go modules, for example, https://github.com/digitalocean/go-libvirt.

If I launch vscode at the root of one of those repos, vscode throws an error from gopls: 'Inconsistent vendoring detected. Please re-run "go mode vendor".'

This happens because vscode-go has set GOFLAGS=-mod=vendor. It only does this if GOFLAGS is not set when vscode is started; if I launch vscode with GOFLAGS="" code, all is well.

This problem happens with any go module that doesn't use vendoring. You can observe it easily enough by launching from a shell with no GOFLAGS set, then running echo $GOFLAGS from vscode's built-in terminal.

It's possible something in my environment is causing this, but I haven't found anything.

Steps to reproduce the behavior:

Clone https://github.com/digitalocean/go-libvirt
Ensure GOFLAGS is not set in your terminal.
Launch vscode in the go-libvirt project directory. You should get an "inconsistent vendoring" error.
Verify that GOFLAGS is set in vscode.
Exit and restart vscode with GOFLAGS="", the issue should be gone.

@gopherbot gopherbot added this to the Untriaged milestone Jun 28, 2021
@stamblerre
Copy link
Contributor

I am not able to reproduce this. I would not expect -mod=vendor to be added unless the repository has a vendor directory.

Can you please share your language server logs? Information on how to capture them can be found here.

@stamblerre stamblerre added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jun 28, 2021
@stamblerre stamblerre modified the milestones: Untriaged, Backlog Jun 28, 2021
@trapgate
Copy link
Author

trapgate commented Jun 28, 2021

Sure:

[Info  - 3:53:23 PM] 2021/06/28 15:53:23 go env for /home/geoff/do/go-libvirt
(root /home/geoff/do/go-libvirt)
(go version go version go1.16.5 linux/amd64)
(valid build configuration = true)
(build flags: [])
GONOSUMDB=*.internal.digitalocean.com,github.com/digitalocean
GOFLAGS=-mod=vendor
GOMOD=/home/geoff/do/go-libvirt/go.mod
GOPROXY=https://proxy.golang.org,direct
GO111MODULE=
GOINSECURE=
GOMODCACHE=/home/geoff/mygo/pkg/mod
GONOPROXY=*.internal.digitalocean.com,github.com/digitalocean
GOPATH=/home/geoff/mygo
GOCACHE=/home/geoff/.cache/go-build
GOROOT=/usr/lib/go
GOPRIVATE=*.internal.digitalocean.com,github.com/digitalocean
GOSUMDB=sum.golang.org


[Error - 3:53:23 PM] 2021/06/28 15:53:23 go/packages.Load: err: exit status 1: stderr: go: inconsistent vendoring in /home/geoff/do/go-libvirt:
	github.com/stretchr/testify@v1.6.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/tools@v0.1.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt

	To ignore the vendor directory, use -mod=readonly or -mod=mod.
	To sync the vendor directory, run:
		go mod vendor

	snapshot=0
	directory=/home/geoff/do/go-libvirt
	query=[builtin github.com/digitalocean/go-libvirt/...]
	packages=0

[Error - 3:53:23 PM] 2021/06/28 15:53:23 initial workspace load failed: err: exit status 1: stderr: go: inconsistent vendoring in /home/geoff/do/go-libvirt:
	github.com/stretchr/testify@v1.6.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/tools@v0.1.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt

	To ignore the vendor directory, use -mod=readonly or -mod=mod.
	To sync the vendor directory, run:
		go mod vendor
: packages.Load error

[Error - 3:53:23 PM] 2021/06/28 15:53:23 diagnosing go.mod: err: exit status 1: stderr: go: inconsistent vendoring in /home/geoff/do/go-libvirt:
	github.com/stretchr/testify@v1.6.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/tools@v0.1.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt

	To ignore the vendor directory, use -mod=readonly or -mod=mod.
	To sync the vendor directory, run:
		go mod vendor
: packages.Load error

[Error - 3:53:23 PM] 2021/06/28 15:53:23 errors loading workspace: err: exit status 1: stderr: go: inconsistent vendoring in /home/geoff/do/go-libvirt:
	github.com/stretchr/testify@v1.6.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/tools@v0.1.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt

	To ignore the vendor directory, use -mod=readonly or -mod=mod.
	To sync the vendor directory, run:
		go mod vendor
: packages.Load error
	snapshot=0
	directory=file:///home/geoff/do/go-libvirt

[Error - 3:53:23 PM] 2021/06/28 15:53:23 failed to compute document links: err: exit status 1: stderr: go: inconsistent vendoring in /home/geoff/do/go-libvirt:
	github.com/stretchr/testify@v1.6.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/tools@v0.1.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt

	To ignore the vendor directory, use -mod=readonly or -mod=mod.
	To sync the vendor directory, run:
		go mod vendor
: packages.Load error
	URI=file:///home/geoff/do/go-libvirt/libvirt.go

[Error - 3:53:23 PM] 2021/06/28 15:53:23 go/packages.Load: err: exit status 1: stderr: go: inconsistent vendoring in /home/geoff/do/go-libvirt:
	github.com/stretchr/testify@v1.6.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/tools@v0.1.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt

	To ignore the vendor directory, use -mod=readonly or -mod=mod.
	To sync the vendor directory, run:
		go mod vendor

	snapshot=1
	directory=/home/geoff/do/go-libvirt
	query=[file=/home/geoff/do/go-libvirt/libvirt.go]
	packages=0

[Error - 3:53:23 PM] 2021/06/28 15:53:23 go/packages.Load: err: exit status 1: stderr: go: inconsistent vendoring in /home/geoff/do/go-libvirt:
	github.com/stretchr/testify@v1.6.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/tools@v0.1.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt

	To ignore the vendor directory, use -mod=readonly or -mod=mod.
	To sync the vendor directory, run:
		go mod vendor

	snapshot=1
	directory=/home/geoff/do/go-libvirt
	query=[file=/home/geoff/do/go-libvirt/libvirt.go]
	packages=0

[Error - 3:53:24 PM] 2021/06/28 15:53:24 go/packages.Load: err: exit status 1: stderr: go: inconsistent vendoring in /home/geoff/do/go-libvirt:
	github.com/stretchr/testify@v1.6.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/tools@v0.1.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt

	To ignore the vendor directory, use -mod=readonly or -mod=mod.
	To sync the vendor directory, run:
		go mod vendor

	snapshot=1
	directory=/home/geoff/do/go-libvirt
	query=[file=/home/geoff/do/go-libvirt/libvirt.go]
	packages=0

[Error - 3:53:24 PM] 2021/06/28 15:53:24 failed to compute document links: err: exit status 1: stderr: go: inconsistent vendoring in /home/geoff/do/go-libvirt:
	github.com/stretchr/testify@v1.6.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/tools@v0.1.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt

	To ignore the vendor directory, use -mod=readonly or -mod=mod.
	To sync the vendor directory, run:
		go mod vendor
: packages.Load error
	URI=file:///home/geoff/do/go-libvirt/libvirt.go

[Error - 3:53:24 PM] 2021/06/28 15:53:24 diagnosing go.mod: err: exit status 1: stderr: go: inconsistent vendoring in /home/geoff/do/go-libvirt:
	github.com/stretchr/testify@v1.6.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/tools@v0.1.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt

	To ignore the vendor directory, use -mod=readonly or -mod=mod.
	To sync the vendor directory, run:
		go mod vendor
: packages.Load error

[Error - 3:53:24 PM] 2021/06/28 15:53:24 errors loading workspace: err: exit status 1: stderr: go: inconsistent vendoring in /home/geoff/do/go-libvirt:
	github.com/stretchr/testify@v1.6.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/tools@v0.1.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt

	To ignore the vendor directory, use -mod=readonly or -mod=mod.
	To sync the vendor directory, run:
		go mod vendor
: packages.Load error
	snapshot=1
	directory=file:///home/geoff/do/go-libvirt

[Error - 3:53:24 PM] 2021/06/28 15:53:24 go/packages.Load: err: exit status 1: stderr: go: inconsistent vendoring in /home/geoff/do/go-libvirt:
	github.com/stretchr/testify@v1.6.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/tools@v0.1.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt

	To ignore the vendor directory, use -mod=readonly or -mod=mod.
	To sync the vendor directory, run:
		go mod vendor

	snapshot=1
	directory=/home/geoff/do/go-libvirt
	query=[file=/home/geoff/do/go-libvirt/libvirt.go]
	packages=0

[Error - 3:53:24 PM] 2021/06/28 15:53:24 DocumentSymbols failed: getting file for DocumentSymbols: err: exit status 1: stderr: go: inconsistent vendoring in /home/geoff/do/go-libvirt:
	github.com/stretchr/testify@v1.6.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/tools@v0.1.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt

	To ignore the vendor directory, use -mod=readonly or -mod=mod.
	To sync the vendor directory, run:
		go mod vendor
: packages.Load error
	URI=file:///home/geoff/do/go-libvirt/libvirt.go

[Trace - 15:53:39.498 PM] Sending request 'initialize - (0)'.
Params: {"processId":845211,"clientInfo":{"name":"Visual Studio Code","version":"1.57.1"},"locale":"en-us","rootPath":"/home/geoff/do/go-libvirt","rootUri":"file:///home/geoff/do/go-libvirt","capabilities":{"workspace":{"applyEdit":true,"workspaceEdit":{"documentChanges":true,"resourceOperations":["create","rename","delete"],"failureHandling":"textOnlyTransactional","normalizesLineEndings":true,"changeAnnotationSupport":{"groupsOnLabel":true}},"didChangeConfiguration":{"dynamicRegistration":true},"didChangeWatchedFiles":{"dynamicRegistration":true},"symbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"tagSupport":{"valueSet":[1]}},"codeLens":{"refreshSupport":true},"executeCommand":{"dynamicRegistration":true},"configuration":true,"workspaceFolders":true,"semanticTokens":{"refreshSupport":true},"fileOperations":{"dynamicRegistration":true,"didCreate":true,"didRename":true,"didDelete":true,"willCreate":true,"willRename":true,"willDelete":true}},"textDocument":{"publishDiagnostics":{"relatedInformation":true,"versionSupport":false,"tagSupport":{"valueSet":[1,2]},"codeDescriptionSupport":true,"dataSupport":true},"synchronization":{"dynamicRegistration":true,"willSave":true,"willSaveWaitUntil":true,"didSave":true},"completion":{"dynamicRegistration":true,"contextSupport":true,"completionItem":{"snippetSupport":true,"commitCharactersSupport":true,"documentationFormat":["markdown","plaintext"],"deprecatedSupport":true,"preselectSupport":true,"tagSupport":{"valueSet":[1]},"insertReplaceSupport":true,"resolveSupport":{"properties":["documentation","detail","additionalTextEdits"]},"insertTextModeSupport":{"valueSet":[1,2]}},"completionItemKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]}},"hover":{"dynamicRegistration":true,"contentFormat":["markdown","plaintext"]},"signatureHelp":{"dynamicRegistration":true,"signatureInformation":{"documentationFormat":["markdown","plaintext"],"parameterInformation":{"labelOffsetSupport":true},"activeParameterSupport":true},"contextSupport":true},"definition":{"dynamicRegistration":true,"linkSupport":true},"references":{"dynamicRegistration":true},"documentHighlight":{"dynamicRegistration":true},"documentSymbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"hierarchicalDocumentSymbolSupport":true,"tagSupport":{"valueSet":[1]},"labelSupport":true},"codeAction":{"dynamicRegistration":true,"isPreferredSupport":true,"disabledSupport":true,"dataSupport":true,"resolveSupport":{"properties":["edit"]},"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}},"honorsChangeAnnotations":false},"codeLens":{"dynamicRegistration":true},"formatting":{"dynamicRegistration":true},"rangeFormatting":{"dynamicRegistration":true},"onTypeFormatting":{"dynamicRegistration":true},"rename":{"dynamicRegistration":true,"prepareSupport":true,"prepareSupportDefaultBehavior":1,"honorsChangeAnnotations":true},"documentLink":{"dynamicRegistration":true,"tooltipSupport":true},"typeDefinition":{"dynamicRegistration":true,"linkSupport":true},"implementation":{"dynamicRegistration":true,"linkSupport":true},"colorProvider":{"dynamicRegistration":true},"foldingRange":{"dynamicRegistration":true,"rangeLimit":5000,"lineFoldingOnly":true},"declaration":{"dynamicRegistration":true,"linkSupport":true},"selectionRange":{"dynamicRegistration":true},"callHierarchy":{"dynamicRegistration":true},"semanticTokens":{"dynamicRegistration":true,"tokenTypes":["namespace","type","class","enum","interface","struct","typeParameter","parameter","variable","property","enumMember","event","function","method","macro","keyword","modifier","comment","string","number","regexp","operator"],"tokenModifiers":["declaration","definition","readonly","static","deprecated","abstract","async","modification","documentation","defaultLibrary"],"formats":["relative"],"requests":{"range":true,"full":{"delta":true}},"multilineTokenSupport":false,"overlappingTokenSupport":false},"linkedEditingRange":{"dynamicRegistration":true}},"window":{"showMessage":{"messageActionItem":{"additionalPropertiesSupport":true}},"showDocument":{"support":true},"workDoneProgress":true},"general":{"regularExpressions":{"engine":"ECMAScript","version":"ES2020"},"markdown":{"parser":"marked","version":"1.1.0"}}},"initializationOptions":{},"trace":"off","workspaceFolders":[{"uri":"file:///home/geoff/do/go-libvirt","name":"go-libvirt"}]}


[Trace - 15:53:39.500 PM] Received response 'initialize - (0)' in 1ms.
Result: {"capabilities":{"textDocumentSync":{"openClose":true,"change":2,"save":{}},"completionProvider":{"triggerCharacters":["."],"completionItem":{}},"hoverProvider":true,"signatureHelpProvider":{"triggerCharacters":["(",","]},"definitionProvider":true,"typeDefinitionProvider":true,"implementationProvider":true,"referencesProvider":true,"documentHighlightProvider":true,"documentSymbolProvider":true,"codeActionProvider":{"codeActionKinds":["quickfix","refactor.extract","refactor.rewrite","source.fixAll","source.organizeImports"]},"codeLensProvider":{},"documentLinkProvider":{},"workspaceSymbolProvider":true,"documentFormattingProvider":true,"documentOnTypeFormattingProvider":{"firstTriggerCharacter":""},"renameProvider":{"prepareProvider":true},"foldingRangeProvider":true,"executeCommandProvider":{"commands":["gopls.add_dependency","gopls.add_import","gopls.apply_fix","gopls.check_upgrades","gopls.gc_details","gopls.generate","gopls.generate_gopls_mod","gopls.go_get_package","gopls.list_known_packages","gopls.regenerate_cgo","gopls.remove_dependency","gopls.run_tests","gopls.start_debugging","gopls.test","gopls.tidy","gopls.toggle_gc_details","gopls.update_go_sum","gopls.upgrade_dependency","gopls.vendor","gopls.workspace_metadata"]},"callHierarchyProvider":true,"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":"workspace/didChangeWorkspaceFolders"}}},"serverInfo":{"name":"gopls","version":"{\"path\":\"golang.org/x/tools/gopls\",\"version\":\"v0.7.0\",\"sum\":\"h1:JQBHW81Gsyim6iDjUwGoPeSpXrSqwen3isPJLfDfaYU=\",\"deps\":[{\"path\":\"github.com/BurntSushi/toml\",\"version\":\"v0.3.1\",\"sum\":\"h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=\"},{\"path\":\"github.com/google/go-cmp\",\"version\":\"v0.5.5\",\"sum\":\"h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=\"},{\"path\":\"github.com/sergi/go-diff\",\"version\":\"v1.1.0\",\"sum\":\"h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=\"},{\"path\":\"golang.org/x/mod\",\"version\":\"v0.4.2\",\"sum\":\"h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=\"},{\"path\":\"golang.org/x/sync\",\"version\":\"v0.0.0-20210220032951-036812b2e83c\",\"sum\":\"h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=\"},{\"path\":\"golang.org/x/sys\",\"version\":\"v0.0.0-20210510120138-977fb7262007\",\"sum\":\"h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE=\"},{\"path\":\"golang.org/x/tools\",\"version\":\"v0.1.3-0.20210608163600-9ed039809d4c\",\"sum\":\"h1:Pv9gNyJFYVdpUAVZYJ1BDSU4eGgXQ+0f3DIGAdolO5s=\"},{\"path\":\"golang.org/x/xerrors\",\"version\":\"v0.0.0-20200804184101-5ec99f83aff1\",\"sum\":\"h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=\"},{\"path\":\"honnef.co/go/tools\",\"version\":\"v0.2.0\",\"sum\":\"h1:ws8AfbgTX3oIczLPNPCu5166oBg9ST2vNs0rcht+mDE=\"},{\"path\":\"mvdan.cc/gofumpt\",\"version\":\"v0.1.1\",\"sum\":\"h1:bi/1aS/5W00E2ny5q65w9SnKpWEF/UIOqDYBILpo9rA=\"},{\"path\":\"mvdan.cc/xurls/v2\",\"version\":\"v2.2.0\",\"sum\":\"h1:NSZPykBXJFCetGZykLAxaL6SIpvbVy/UFEniIfHAa8A=\"}]}"}}


[Trace - 15:53:39.503 PM] Sending notification 'initialized'.
Params: {}


[Trace - 15:53:39.503 PM] Received request 'window/workDoneProgress/create - (1)'.
Params: {"token":"5577006791947779410"}


[Trace - 15:53:39.503 PM] Sending notification 'textDocument/didOpen'.
Params: {"textDocument":{"uri":"file:///home/geoff/do/go-libvirt/libvirt.go","languageId":"go","version":1,"text":"// Copyright 2018 The go-libvirt Authors.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//   http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage libvirt\n\n// We'll use c-for-go to extract the consts and typedefs from the libvirt\n// sources so we don't have to duplicate them here.\n//go:generate scripts/gen-consts.sh\n\nimport (\n\t\"bytes\"\n\t\"context\"\n\t\"encoding/json\"\n\t\"errors\"\n\t\"fmt\"\n\t\"net\"\n\t\"sync\"\n\t\"time\"\n\n\t\"github.com/digitalocean/go-libvirt/internal/constants\"\n\t\"github.com/digitalocean/go-libvirt/internal/event\"\n\txdr \"github.com/digitalocean/go-libvirt/internal/go-xdr/xdr2\"\n\t\"github.com/digitalocean/go-libvirt/socket\"\n)\n\n// ErrEventsNotSupported is returned by Events() if event streams\n// are unsupported by either QEMU or libvirt.\nvar ErrEventsNotSupported = errors.New(\"event monitor is not supported\")\n\n// ConnectURI defines a type for driver URIs for libvirt\n// the defined constants are *not* exhaustive as there are also options\n// e.g. to connect remote via SSH\ntype ConnectURI string\n\nconst (\n\t// QEMUSystem connects to a QEMU system mode daemon\n\tQEMUSystem ConnectURI = \"qemu:///system\"\n\t// QEMUSession connects to a QEMU session mode daemon (unprivileged)\n\tQEMUSession ConnectURI = \"qemu:///session\"\n\t// XenSystem connects to a Xen system mode daemon\n\tXenSystem ConnectURI = \"xen:///system\"\n\t//TestDefault connect to default mock driver\n\tTestDefault ConnectURI = \"test:///default\"\n\n\t// disconnectedTimeout is how long to wait for disconnect cleanup to\n\t// complete\n\tdisconnectTimeout = 5 * time.Second\n)\n\n// Libvirt implements libvirt's remote procedure call protocol.\ntype Libvirt struct {\n\t// socket connection\n\tsocket *socket.Socket\n\t// closed after cleanup complete following the underlying connection to\n\t// libvirt being disconnected.\n\tdisconnected chan struct{}\n\n\t// method callbacks\n\tcmux      sync.RWMutex\n\tcallbacks map[int32]chan response\n\n\t// event listeners\n\temux   sync.RWMutex\n\tevents map[int32]*event.Stream\n\n\t// next request serial number\n\ts int32\n}\n\n// DomainEvent represents a libvirt domain event.\ntype DomainEvent struct {\n\tCallbackID   int32\n\tDomain       Domain\n\tEvent        string\n\tSeconds      uint64\n\tMicroseconds uint32\n\tPadding      uint8\n\tDetails      []byte\n}\n\n// GetCallbackID returns the callback ID of a QEMU domain event.\nfunc (de DomainEvent) GetCallbackID() int32 {\n\treturn de.CallbackID\n}\n\n// GetCallbackID returns the callback ID of a libvirt lifecycle event.\nfunc (m DomainEventCallbackLifecycleMsg) GetCallbackID() int32 {\n\treturn m.CallbackID\n}\n\n// qemuError represents a QEMU process error.\ntype qemuError struct {\n\tError struct {\n\t\tClass       string `json:\"class\"`\n\t\tDescription string `json:\"desc\"`\n\t} `json:\"error\"`\n}\n\n// Capabilities returns an XML document describing the host's capabilties.\nfunc (l *Libvirt) Capabilities() ([]byte, error) {\n\tcaps, err := l.ConnectGetCapabilities()\n\treturn []byte(caps), err\n}\n\n// called at connection time, authenticating with all supported auth types\nfunc (l *Libvirt) authenticate() error {\n\t// libvirt requires that we call auth-list prior to connecting,\n\t// even when no authentication is used.\n\tresp, err := l.AuthList()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tfor _, auth := range resp {\n\t\tswitch auth {\n\t\tcase constants.AuthNone:\n\t\tcase constants.AuthPolkit:\n\t\t\t_, err := l.AuthPolkit()\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\tdefault:\n\t\t\tcontinue\n\t\t}\n\t\tbreak\n\t}\n\treturn nil\n}\n\n// ConnectToURI establishes communication with the specified libvirt driver\n// The underlying libvirt socket connection must be previously established.\nfunc (l *Libvirt) ConnectToURI(uri ConnectURI) error {\n\tpayload := struct {\n\t\tPadding [3]byte\n\t\tName    string\n\t\tFlags   uint32\n\t}{\n\t\tPadding: [3]byte{0x1, 0x0, 0x0},\n\t\tName:    string(uri),\n\t\tFlags:   0,\n\t}\n\n\tbuf, err := encode(&payload)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\terr = l.authenticate()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t_, err = l.request(constants.ProcConnectOpen, constants.Program, buf)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\treturn nil\n}\n\n// Connect establishes communication with the libvirt server.\n// The underlying libvirt socket connection must be previously established.\nfunc (l *Libvirt) Connect() error {\n\treturn l.ConnectToURI(QEMUSystem)\n}\n\n// Disconnect shuts down communication with the libvirt server and closes the\n// underlying net.Conn.\nfunc (l *Libvirt) Disconnect() error {\n\t// Ordering is important here. We want to make sure the connection is closed\n\t// before unsubscribing and deregistering the events and requests, to\n\t// prevent new requests from racing.\n\t_, err := l.request(constants.ProcConnectClose, constants.Program, nil)\n\tif err != nil {\n\t\treturn err\n\t}\n\terr = l.socket.Disconnect()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t// wait for the listen goroutine to detect the lost connection and clean up\n\t// to happen once it returns.  Safeguard with a timeout.\n\t// Things not fully cleaned up is better than a deadlock.\n\tselect {\n\tcase <-l.disconnected:\n\tcase <-time.After(disconnectTimeout):\n\t}\n\n\treturn err\n}\n\n// Domains returns a list of all domains managed by libvirt.\n//\n// Deprecated: use ConnectListAllDomains instead.\nfunc (l *Libvirt) Domains() ([]Domain, error) {\n\t// these are the flags as passed by `virsh list --all`\n\tflags := ConnectListDomainsActive | ConnectListDomainsInactive\n\tdomains, _, err := l.ConnectListAllDomains(1, flags)\n\treturn domains, err\n}\n\n// DomainState returns state of the domain managed by libvirt.\n//\n// Deprecated: use DomainGetState instead.\nfunc (l *Libvirt) DomainState(dom string) (DomainState, error) {\n\td, err := l.lookup(dom)\n\tif err != nil {\n\t\treturn DomainNostate, err\n\t}\n\n\tstate, _, err := l.DomainGetState(d, 0)\n\treturn DomainState(state), err\n}\n\n// SubscribeQEMUEvents streams domain events until the provided context is\n// cancelled. If a problem is encountered setting up the event monitor\n// connection an error will be returned. Errors encountered during streaming\n// will cause the returned event channel to be closed. QEMU domain events.\nfunc (l *Libvirt) SubscribeQEMUEvents(ctx context.Context, dom string) (<-chan DomainEvent, error) {\n\td, err := l.lookup(dom)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tcallbackID, err := l.QEMUConnectDomainMonitorEventRegister([]Domain{d}, nil, 0)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tstream := event.NewStream(constants.QEMUProgram, callbackID)\n\tl.addStream(stream)\n\tch := make(chan DomainEvent)\n\tgo func() {\n\t\tctx, cancel := context.WithCancel(ctx)\n\t\tdefer cancel()\n\t\tdefer l.unsubscribeQEMUEvents(stream)\n\t\tdefer stream.Shutdown()\n\t\tdefer close(ch)\n\n\t\tfor {\n\t\t\tselect {\n\t\t\tcase ev, ok := <-stream.Recv():\n\t\t\t\tif !ok {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tch <- *ev.(*DomainEvent)\n\t\t\tcase <-ctx.Done():\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t}()\n\n\treturn ch, nil\n}\n\n// unsubscribeQEMUEvents stops the flow of events from QEMU through libvirt.\nfunc (l *Libvirt) unsubscribeQEMUEvents(stream *event.Stream) error {\n\terr := l.QEMUConnectDomainMonitorEventDeregister(stream.CallbackID)\n\tl.removeStream(stream.CallbackID)\n\n\treturn err\n}\n\n// SubscribeEvents allows the caller to subscribe to any of the event types\n// supported by libvirt. The events will continue to be streamed until the\n// caller cancels the provided context. After canceling the context, callers\n// should wait until the channel is closed to be sure they're collected all the\n// events.\nfunc (l *Libvirt) SubscribeEvents(ctx context.Context, eventID DomainEventID,\n\tdom OptDomain) (<-chan interface{}, error) {\n\n\tcallbackID, err := l.ConnectDomainEventCallbackRegisterAny(int32(eventID), nil)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tstream := event.NewStream(constants.QEMUProgram, callbackID)\n\tl.addStream(stream)\n\n\tch := make(chan interface{})\n\tgo func() {\n\t\tctx, cancel := context.WithCancel(ctx)\n\t\tdefer cancel()\n\t\tdefer l.unsubscribeEvents(stream)\n\t\tdefer stream.Shutdown()\n\t\tdefer func() { close(ch) }()\n\n\t\tfor {\n\t\t\tselect {\n\t\t\tcase ev, ok := <-stream.Recv():\n\t\t\t\tif !ok {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tch <- ev\n\t\t\tcase <-ctx.Done():\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t}()\n\n\treturn ch, nil\n}\n\n// unsubscribeEvents stops the flow of the specified events from libvirt. There\n// are two steps to this process: a call to libvirt to deregister our callback,\n// and then removing the callback from the list used by the `Route` function. If\n// the deregister call fails, we'll return the error, but still remove the\n// callback from the list. That's ok; if any events arrive after this point, the\n// Route function will drop them when it finds no registered handler.\nfunc (l *Libvirt) unsubscribeEvents(stream *event.Stream) error {\n\terr := l.ConnectDomainEventCallbackDeregisterAny(stream.CallbackID)\n\tl.removeStream(stream.CallbackID)\n\n\treturn err\n}\n\n// LifecycleEvents streams lifecycle events until the provided context is\n// cancelled. If a problem is encountered setting up the event monitor\n// connection, an error will be returned. Errors encountered during streaming\n// will cause the returned event channel to be closed.\nfunc (l *Libvirt) LifecycleEvents(ctx context.Context) (<-chan DomainEventLifecycleMsg, error) {\n\tcallbackID, err := l.ConnectDomainEventCallbackRegisterAny(int32(DomainEventIDLifecycle), nil)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tstream := event.NewStream(constants.Program, callbackID)\n\tl.addStream(stream)\n\n\tch := make(chan DomainEventLifecycleMsg)\n\n\tgo func() {\n\t\tctx, cancel := context.WithCancel(ctx)\n\t\tdefer cancel()\n\t\tdefer l.unsubscribeEvents(stream)\n\t\tdefer stream.Shutdown()\n\t\tdefer func() { close(ch) }()\n\n\t\tfor {\n\t\t\tselect {\n\t\t\tcase ev, ok := <-stream.Recv():\n\t\t\t\tif !ok {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tch <- ev.(*DomainEventCallbackLifecycleMsg).Msg\n\t\t\tcase <-ctx.Done():\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t}()\n\n\treturn ch, nil\n}\n\n// Run executes the given QAPI command against a domain's QEMU instance.\n// For a list of available QAPI commands, see:\n//\thttp://git.qemu.org/?p=qemu.git;a=blob;f=qapi-schema.json;hb=HEAD\nfunc (l *Libvirt) Run(dom string, cmd []byte) ([]byte, error) {\n\td, err := l.lookup(dom)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tpayload := struct {\n\t\tDomain  Domain\n\t\tCommand []byte\n\t\tFlags   uint32\n\t}{\n\t\tDomain:  d,\n\t\tCommand: cmd,\n\t\tFlags:   0,\n\t}\n\n\tbuf, err := encode(&payload)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tres, err := l.request(constants.QEMUProcDomainMonitorCommand, constants.QEMUProgram, buf)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\t// check for QEMU process errors\n\tif err = getQEMUError(res); err != nil {\n\t\treturn nil, err\n\t}\n\n\tr := bytes.NewReader(res.Payload)\n\tdec := xdr.NewDecoder(r)\n\tdata, _, err := dec.DecodeFixedOpaque(int32(r.Len()))\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\t// drop QMP control characters from start of line, and drop\n\t// any trailing NULL characters from the end\n\treturn bytes.TrimRight(data[4:], \"\\x00\"), nil\n}\n\n// Secrets returns all secrets managed by the libvirt daemon.\n//\n// Deprecated: use ConnectListAllSecrets instead.\nfunc (l *Libvirt) Secrets() ([]Secret, error) {\n\tsecrets, _, err := l.ConnectListAllSecrets(1, 0)\n\treturn secrets, err\n}\n\n// StoragePool returns the storage pool associated with the provided name.\n// An error is returned if the requested storage pool is not found.\n//\n// Deprecated: use StoragePoolLookupByName instead.\nfunc (l *Libvirt) StoragePool(name string) (StoragePool, error) {\n\treturn l.StoragePoolLookupByName(name)\n}\n\n// StoragePools returns a list of defined storage pools. Pools are filtered by\n// the provided flags. See StoragePools*.\n//\n// Deprecated: use ConnectListAllStoragePools instead.\nfunc (l *Libvirt) StoragePools(flags ConnectListAllStoragePoolsFlags) ([]StoragePool, error) {\n\tpools, _, err := l.ConnectListAllStoragePools(1, flags)\n\treturn pools, err\n}\n\n// Undefine undefines the domain specified by dom, e.g., 'prod-lb-01'.\n// The flags argument allows additional options to be specified such as\n// cleaning up snapshot metadata. For more information on available\n// flags, see DomainUndefine*.\n//\n// Deprecated: use DomainUndefineFlags instead.\nfunc (l *Libvirt) Undefine(dom string, flags DomainUndefineFlagsValues) error {\n\td, err := l.lookup(dom)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\treturn l.DomainUndefineFlags(d, flags)\n}\n\n// Destroy destroys the domain specified by dom, e.g., 'prod-lb-01'.\n// The flags argument allows additional options to be specified such as\n// allowing a graceful shutdown with SIGTERM than SIGKILL.\n// For more information on available flags, see DomainDestroy*.\n//\n// Deprecated: use DomainDestroyFlags instead.\nfunc (l *Libvirt) Destroy(dom string, flags DomainDestroyFlagsValues) error {\n\td, err := l.lookup(dom)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\treturn l.DomainDestroyFlags(d, flags)\n}\n\n// XML returns a domain's raw XML definition, akin to `virsh dumpxml <domain>`.\n// See DomainXMLFlag* for optional flags.\n//\n// Deprecated: use DomainGetXMLDesc instead.\nfunc (l *Libvirt) XML(dom string, flags DomainXMLFlags) ([]byte, error) {\n\td, err := l.lookup(dom)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\txml, err := l.DomainGetXMLDesc(d, flags)\n\treturn []byte(xml), err\n}\n\n// DefineXML defines a domain, but does not start it.\n//\n// Deprecated: use DomainDefineXMLFlags instead.\nfunc (l *Libvirt) DefineXML(x []byte, flags DomainDefineFlags) error {\n\t_, err := l.DomainDefineXMLFlags(string(x), flags)\n\treturn err\n}\n\n// Version returns the version of the libvirt daemon.\n//\n// Deprecated: use ConnectGetLibVersion instead.\nfunc (l *Libvirt) Version() (string, error) {\n\tver, err := l.ConnectGetLibVersion()\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\t// The version is provided as an int following this formula:\n\t// version * 1,000,000 + minor * 1000 + micro\n\t// See src/libvirt-host.c # virConnectGetLibVersion\n\tmajor := ver / 1000000\n\tver %= 1000000\n\tminor := ver / 1000\n\tver %= 1000\n\tmicro := ver\n\n\tversionString := fmt.Sprintf(\"%d.%d.%d\", major, minor, micro)\n\treturn versionString, nil\n}\n\n// Shutdown shuts down a domain. Note that the guest OS may ignore the request.\n// If flags is set to 0 then the hypervisor will choose the method of shutdown it considers best.\n//\n// Deprecated: use DomainShutdownFlags instead.\nfunc (l *Libvirt) Shutdown(dom string, flags DomainShutdownFlagValues) error {\n\td, err := l.lookup(dom)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\treturn l.DomainShutdownFlags(d, flags)\n}\n\n// Reboot reboots the domain. Note that the guest OS may ignore the request.\n// If flags is set to zero, then the hypervisor will choose the method of shutdown it considers best.\n//\n// Deprecated: use DomainReboot instead.\nfunc (l *Libvirt) Reboot(dom string, flags DomainRebootFlagValues) error {\n\td, err := l.lookup(dom)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\treturn l.DomainReboot(d, flags)\n}\n\n// Reset resets domain immediately without any guest OS shutdown\n//\n// Deprecated: use DomainReset instead.\nfunc (l *Libvirt) Reset(dom string) error {\n\td, err := l.lookup(dom)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\treturn l.DomainReset(d, 0)\n}\n\n// BlockLimit contains a name and value pair for a Get/SetBlockIOTune limit. The\n// Name field is the name of the limit (to see a list of the limits that can be\n// applied, execute the 'blkdeviotune' command on a VM in virsh). Callers can\n// use the QEMUBlockIO... constants below for the Name value. The Value field is\n// the limit to apply.\ntype BlockLimit struct {\n\tName  string\n\tValue uint64\n}\n\n// SetBlockIOTune changes the per-device block I/O tunables within a guest.\n// Parameters are the name of the VM, the name of the disk device to which the\n// limits should be applied, and 1 or more BlockLimit structs containing the\n// actual limits.\n//\n// The limits which can be applied here are enumerated in the QEMUBlockIO...\n// constants above, and you can also see the full list by executing the\n// 'blkdeviotune' command on a VM in virsh.\n//\n// Example usage:\n//  SetBlockIOTune(\"vm-name\", \"vda\", BlockLimit{libvirt.QEMUBlockIOWriteBytesSec, 1000000})\n//\n// Deprecated: use DomainSetBlockIOTune instead.\nfunc (l *Libvirt) SetBlockIOTune(dom string, disk string, limits ...BlockLimit) error {\n\td, err := l.lookup(dom)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tparams := make([]TypedParam, len(limits))\n\tfor ix, limit := range limits {\n\t\ttpval := NewTypedParamValueUllong(limit.Value)\n\t\tparams[ix] = TypedParam{Field: limit.Name, Value: *tpval}\n\t}\n\n\treturn l.DomainSetBlockIOTune(d, disk, params, uint32(DomainAffectLive))\n}\n\n// GetBlockIOTune returns a slice containing the current block I/O tunables for\n// a disk.\n//\n// Deprecated: use DomainGetBlockIOTune instead.\nfunc (l *Libvirt) GetBlockIOTune(dom string, disk string) ([]BlockLimit, error) {\n\td, err := l.lookup(dom)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tlims, _, err := l.DomainGetBlockIOTune(d, []string{disk}, 32, uint32(TypedParamStringOkay))\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tvar limits []BlockLimit\n\n\t// now decode each of the returned TypedParams. To do this we read the field\n\t// name and type, then use the type information to decode the value.\n\tfor _, lim := range lims {\n\t\tvar l BlockLimit\n\t\tname := lim.Field\n\t\tswitch lim.Value.I.(type) {\n\t\tcase uint64:\n\t\t\tl = BlockLimit{Name: name, Value: lim.Value.I.(uint64)}\n\t\t}\n\t\tlimits = append(limits, l)\n\t}\n\n\treturn limits, nil\n}\n\n// lookup returns a domain as seen by libvirt.\nfunc (l *Libvirt) lookup(name string) (Domain, error) {\n\treturn l.DomainLookupByName(name)\n}\n\n// getQEMUError checks the provided response for QEMU process errors.\n// If an error is found, it is extracted an returned, otherwise nil.\nfunc getQEMUError(r response) error {\n\tpl := bytes.NewReader(r.Payload)\n\tdec := xdr.NewDecoder(pl)\n\n\ts, _, err := dec.DecodeString()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tvar e qemuError\n\tif err = json.Unmarshal([]byte(s), &e); err != nil {\n\t\treturn err\n\t}\n\n\tif e.Error.Description != \"\" {\n\t\treturn errors.New(e.Error.Description)\n\t}\n\n\treturn nil\n}\n\nfunc (l *Libvirt) waitAndDisconnect() {\n\t// wait for the socket to indicate if/when it's been disconnected\n\t<-l.socket.Disconnected()\n\n\t// close event streams\n\tl.removeAllStreams()\n\n\t// Deregister all callbacks to prevent blocking on clients with\n\t// outstanding requests\n\tl.deregisterAll()\n\n\tclose(l.disconnected)\n}\n\n// New configures a new Libvirt RPC connection.\nfunc New(conn net.Conn) *Libvirt {\n\tl := &Libvirt{\n\t\ts:            0,\n\t\tdisconnected: make(chan struct{}),\n\t\tcallbacks:    make(map[int32]chan response),\n\t\tevents:       make(map[int32]*event.Stream),\n\t}\n\n\t// this starts the listening and routing\n\t// TODO:  The connection and listen goroutine should be moved to the\n\t//  Connect function, but this is going to impact the exported API, so\n\t//  trying to do as much as possible before doing that.\n\tl.socket = socket.New(conn, l)\n\n\tgo l.waitAndDisconnect()\n\n\treturn l\n}\n"}}


[Trace - 15:53:39.504 PM] Sending response 'window/workDoneProgress/create - (1)' in 0ms.
Result: 


[Trace - 15:53:39.504 PM] Received notification '$/progress'.
Params: {"token":"5577006791947779410","value":{"kind":"begin","title":"Setting up workspace","message":"Loading packages..."}}


[Trace - 15:53:39.504 PM] Received request 'workspace/configuration - (2)'.
Params: {"items":[{"scopeUri":"file:///home/geoff/do/go-libvirt","section":"gopls"}]}


[Trace - 15:53:39.506 PM] Sending response 'workspace/configuration - (2)' in 1ms.
Result: [{}]


[Trace - 15:53:39.519 PM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2021/06/28 15:53:39 go env for /home/geoff/do/go-libvirt\n(root /home/geoff/do/go-libvirt)\n(go version go version go1.16.5 linux/amd64)\n(valid build configuration = true)\n(build flags: [])\nGONOPROXY=*.internal.digitalocean.com,github.com/digitalocean\nGOINSECURE=\nGOROOT=/usr/lib/go\nGOFLAGS=-mod=vendor\nGOMODCACHE=/home/geoff/mygo/pkg/mod\nGOPRIVATE=*.internal.digitalocean.com,github.com/digitalocean\nGOCACHE=/home/geoff/.cache/go-build\nGOMOD=/home/geoff/do/go-libvirt/go.mod\nGOPATH=/home/geoff/mygo\nGO111MODULE=\nGONOSUMDB=*.internal.digitalocean.com,github.com/digitalocean\nGOPROXY=https://proxy.golang.org,direct\nGOSUMDB=sum.golang.org\n\n"}


[Info  - 3:53:39 PM] 2021/06/28 15:53:39 go env for /home/geoff/do/go-libvirt
(root /home/geoff/do/go-libvirt)
(go version go version go1.16.5 linux/amd64)
(valid build configuration = true)
(build flags: [])
GONOPROXY=*.internal.digitalocean.com,github.com/digitalocean
GOINSECURE=
GOROOT=/usr/lib/go
GOFLAGS=-mod=vendor
GOMODCACHE=/home/geoff/mygo/pkg/mod
GOPRIVATE=*.internal.digitalocean.com,github.com/digitalocean
GOCACHE=/home/geoff/.cache/go-build
GOMOD=/home/geoff/do/go-libvirt/go.mod
GOPATH=/home/geoff/mygo
GO111MODULE=
GONOSUMDB=*.internal.digitalocean.com,github.com/digitalocean
GOPROXY=https://proxy.golang.org,direct
GOSUMDB=sum.golang.org


[Trace - 15:53:39.524 PM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"2021/06/28 15:53:39 go/packages.Load: err: exit status 1: stderr: go: inconsistent vendoring in /home/geoff/do/go-libvirt:\n\tgithub.com/stretchr/testify@v1.6.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt\n\tgolang.org/x/tools@v0.1.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt\n\n\tTo ignore the vendor directory, use -mod=readonly or -mod=mod.\n\tTo sync the vendor directory, run:\n\t\tgo mod vendor\n\n\tsnapshot=0\n\tdirectory=/home/geoff/do/go-libvirt\n\tquery=[builtin github.com/digitalocean/go-libvirt/...]\n\tpackages=0\n"}


[Error - 3:53:39 PM] 2021/06/28 15:53:39 go/packages.Load: err: exit status 1: stderr: go: inconsistent vendoring in /home/geoff/do/go-libvirt:
	github.com/stretchr/testify@v1.6.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/tools@v0.1.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt

	To ignore the vendor directory, use -mod=readonly or -mod=mod.
	To sync the vendor directory, run:
		go mod vendor

	snapshot=0
	directory=/home/geoff/do/go-libvirt
	query=[builtin github.com/digitalocean/go-libvirt/...]
	packages=0

[Trace - 15:53:39.524 PM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"2021/06/28 15:53:39 initial workspace load failed: err: exit status 1: stderr: go: inconsistent vendoring in /home/geoff/do/go-libvirt:\n\tgithub.com/stretchr/testify@v1.6.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt\n\tgolang.org/x/tools@v0.1.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt\n\n\tTo ignore the vendor directory, use -mod=readonly or -mod=mod.\n\tTo sync the vendor directory, run:\n\t\tgo mod vendor\n: packages.Load error\n"}


[Trace - 15:53:39.524 PM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"2021/06/28 15:53:39 diagnosing go.mod: err: exit status 1: stderr: go: inconsistent vendoring in /home/geoff/do/go-libvirt:\n\tgithub.com/stretchr/testify@v1.6.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt\n\tgolang.org/x/tools@v0.1.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt\n\n\tTo ignore the vendor directory, use -mod=readonly or -mod=mod.\n\tTo sync the vendor directory, run:\n\t\tgo mod vendor\n: packages.Load error\n"}


[Trace - 15:53:39.524 PM] Received notification '$/progress'.
Params: {"token":"5577006791947779410","value":{"kind":"end","message":"Finished loading packages."}}


[Error - 3:53:39 PM] 2021/06/28 15:53:39 initial workspace load failed: err: exit status 1: stderr: go: inconsistent vendoring in /home/geoff/do/go-libvirt:
	github.com/stretchr/testify@v1.6.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/tools@v0.1.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt

	To ignore the vendor directory, use -mod=readonly or -mod=mod.
	To sync the vendor directory, run:
		go mod vendor
: packages.Load error

[Error - 3:53:39 PM] 2021/06/28 15:53:39 diagnosing go.mod: err: exit status 1: stderr: go: inconsistent vendoring in /home/geoff/do/go-libvirt:
	github.com/stretchr/testify@v1.6.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/tools@v0.1.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt

	To ignore the vendor directory, use -mod=readonly or -mod=mod.
	To sync the vendor directory, run:
		go mod vendor
: packages.Load error

[Trace - 15:53:39.524 PM] Received request 'client/registerCapability - (3)'.
Params: {"registrations":[{"id":"workspace/didChangeWatchedFiles-0","method":"workspace/didChangeWatchedFiles","registerOptions":{"watchers":[{"globPattern":"**/*.{go,mod,sum}","kind":7},{"globPattern":"**/*.*tmpl","kind":7}]}}]}


[Trace - 15:53:39.525 PM] Sending response 'client/registerCapability - (3)' in 0ms.
Result: 


[Trace - 15:53:39.525 PM] Received request 'client/registerCapability - (4)'.
Params: {"registrations":[{"id":"workspace/didChangeConfiguration","method":"workspace/didChangeConfiguration"},{"id":"workspace/didChangeWorkspaceFolders","method":"workspace/didChangeWorkspaceFolders"}]}


[Trace - 15:53:39.525 PM] Sending response 'client/registerCapability - (4)' in 0ms.
Result: 


[Trace - 15:53:39.531 PM] Received request 'window/workDoneProgress/create - (5)'.
Params: {"token":"8674665223082153551"}


[Trace - 15:53:39.531 PM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"2021/06/28 15:53:39 errors loading workspace: err: exit status 1: stderr: go: inconsistent vendoring in /home/geoff/do/go-libvirt:\n\tgithub.com/stretchr/testify@v1.6.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt\n\tgolang.org/x/tools@v0.1.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt\n\n\tTo ignore the vendor directory, use -mod=readonly or -mod=mod.\n\tTo sync the vendor directory, run:\n\t\tgo mod vendor\n: packages.Load error\n\tsnapshot=0\n\tdirectory=file:///home/geoff/do/go-libvirt\n"}


[Error - 3:53:39 PM] 2021/06/28 15:53:39 errors loading workspace: err: exit status 1: stderr: go: inconsistent vendoring in /home/geoff/do/go-libvirt:
	github.com/stretchr/testify@v1.6.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/tools@v0.1.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt

	To ignore the vendor directory, use -mod=readonly or -mod=mod.
	To sync the vendor directory, run:
		go mod vendor
: packages.Load error
	snapshot=0
	directory=file:///home/geoff/do/go-libvirt

[Trace - 15:53:39.531 PM] Sending response 'window/workDoneProgress/create - (5)' in 0ms.
Result: 


[Trace - 15:53:39.531 PM] Received notification '$/progress'.
Params: {"token":"8674665223082153551","value":{"kind":"begin","title":"Error loading workspace","message":"err: exit status 1: stderr: go: inconsistent vendoring in /home/geoff/do/go-libvirt: \tgithub.com/stretchr/testify@v1.6.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt \tgolang.org/x/tools@v0.1.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt  \tTo ignore the vendor directory, use -mod=readonly or -mod=mod. \tTo sync the vendor directory, run: \t\tgo mod vendor : packages.Load error"}}


[Trace - 15:53:39.532 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {"uri":"file:///home/geoff/do/go-libvirt/go.mod","diagnostics":[{"range":{"start":{"line":0,"character":0},"end":{"line":0,"character":41}},"severity":1,"source":"go list","message":"Inconsistent vendoring detected. Please re-run \"go mod vendor\".\nSee https://github.com/golang/go/issues/39164 for more detail on this issue."}]}


[Trace - 15:53:39.539 PM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"2021/06/28 15:53:39 go/packages.Load: err: exit status 1: stderr: go: inconsistent vendoring in /home/geoff/do/go-libvirt:\n\tgithub.com/stretchr/testify@v1.6.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt\n\tgolang.org/x/tools@v0.1.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt\n\n\tTo ignore the vendor directory, use -mod=readonly or -mod=mod.\n\tTo sync the vendor directory, run:\n\t\tgo mod vendor\n\n\tsnapshot=1\n\tdirectory=/home/geoff/do/go-libvirt\n\tquery=[file=/home/geoff/do/go-libvirt/libvirt.go]\n\tpackages=0\n"}


[Error - 3:53:39 PM] 2021/06/28 15:53:39 go/packages.Load: err: exit status 1: stderr: go: inconsistent vendoring in /home/geoff/do/go-libvirt:
	github.com/stretchr/testify@v1.6.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/tools@v0.1.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt

	To ignore the vendor directory, use -mod=readonly or -mod=mod.
	To sync the vendor directory, run:
		go mod vendor

	snapshot=1
	directory=/home/geoff/do/go-libvirt
	query=[file=/home/geoff/do/go-libvirt/libvirt.go]
	packages=0

[Trace - 15:53:39.790 PM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"2021/06/28 15:53:39 diagnosing go.mod: err: exit status 1: stderr: go: inconsistent vendoring in /home/geoff/do/go-libvirt:\n\tgithub.com/stretchr/testify@v1.6.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt\n\tgolang.org/x/tools@v0.1.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt\n\n\tTo ignore the vendor directory, use -mod=readonly or -mod=mod.\n\tTo sync the vendor directory, run:\n\t\tgo mod vendor\n: packages.Load error\n"}


[Error - 3:53:39 PM] 2021/06/28 15:53:39 diagnosing go.mod: err: exit status 1: stderr: go: inconsistent vendoring in /home/geoff/do/go-libvirt:
	github.com/stretchr/testify@v1.6.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/tools@v0.1.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt

	To ignore the vendor directory, use -mod=readonly or -mod=mod.
	To sync the vendor directory, run:
		go mod vendor
: packages.Load error

[Trace - 15:53:39.795 PM] Received notification '$/progress'.
Params: {"token":"8674665223082153551","value":{"kind":"report","message":"err: exit status 1: stderr: go: inconsistent vendoring in /home/geoff/do/go-libvirt: \tgithub.com/stretchr/testify@v1.6.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt \tgolang.org/x/tools@v0.1.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt  \tTo ignore the vendor directory, use -mod=readonly or -mod=mod. \tTo sync the vendor directory, run: \t\tgo mod vendor : packages.Load error"}}


[Trace - 15:53:39.796 PM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"2021/06/28 15:53:39 errors loading workspace: err: exit status 1: stderr: go: inconsistent vendoring in /home/geoff/do/go-libvirt:\n\tgithub.com/stretchr/testify@v1.6.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt\n\tgolang.org/x/tools@v0.1.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt\n\n\tTo ignore the vendor directory, use -mod=readonly or -mod=mod.\n\tTo sync the vendor directory, run:\n\t\tgo mod vendor\n: packages.Load error\n\tsnapshot=1\n\tdirectory=file:///home/geoff/do/go-libvirt\n"}


[Error - 3:53:39 PM] 2021/06/28 15:53:39 errors loading workspace: err: exit status 1: stderr: go: inconsistent vendoring in /home/geoff/do/go-libvirt:
	github.com/stretchr/testify@v1.6.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/tools@v0.1.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt

	To ignore the vendor directory, use -mod=readonly or -mod=mod.
	To sync the vendor directory, run:
		go mod vendor
: packages.Load error
	snapshot=1
	directory=file:///home/geoff/do/go-libvirt

@stamblerre
Copy link
Contributor

Hm yeah does look like GOFLAGS is in there. Are you sure that those are your full VS Code settings--is it possible that you also have workspace specific settings?

@trapgate
Copy link
Author

trapgate commented Jun 28, 2021

I checked that, yeah - workspace settings are empty except for the gopls settings I just added:

{
    "go.languageServerFlags": [
        "-rpc.trace"
      ]
}

@stamblerre
Copy link
Contributor

What is the output of go env GOFLAGS in the VS Code integrated terminal?
Does this happen for other repositories, or just for this one?

@trapgate
Copy link
Author

$ go env GOFLAGS                                                                     Mon 28 Jun 2021 04:03:53 PM EDT
-mod=vendor

I get this when working with any go repo that is a module, and doesn't vendor dependencies.

@stamblerre
Copy link
Contributor

And just to confirm, when you are in a regular terminal and cd into any Go repo that doesn't vendor dependencies and run go env GOFLAGS, you get nothing?

@trapgate
Copy link
Author

Correct. This is from the terminal that launched vscode:

$ go env GOFLAGS

@stamblerre
Copy link
Contributor

Thanks for confirming. This is stumping me a bit, since there shouldn't be a place where the extension manipulates the value of GOFLAGS. In the meantime, you can set GOFLAGS in the "go.toolsEnvVars" setting as a workaround.

@stamblerre stamblerre added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Jun 28, 2021
@stamblerre stamblerre modified the milestones: Backlog, On Deck Jun 28, 2021
@hyangah
Copy link
Contributor

hyangah commented Jul 12, 2021

The go extension inherits the environment variables VS Code sees. Can you check if the VS Code is launched with clean environment variables setting, and if not, make sure to start vscode from the clean environment? (e.g. shell without the GOFLAGS environment variable set, and also make sure the GOENV file (e.g. "/home/geoff/.config/go/env") is empty, ...)

You can inspect the environment variables VS Code sees from Developer Tools (Command palette -> "Developers: Toggle Developer Tools" and querying process.env.

Screen Shot 2021-07-12 at 4 11 10 PM

The extension itself doesn't -mod=vendor to GOFLAGS.

@hyangah hyangah added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jul 12, 2021
@trapgate
Copy link
Author

trapgate commented Jul 12, 2021

After a little poking around, I have a little more information about this. Yes, I'm launching vscode from a terminal without goflags set.

image

The problem happens when there's more than one instance of vscode running. I normally have an instance of vscode running with a project open that DOES have GOFLAGS set. I'm using direnv for this, so vscode is getting the GOFLAGS value right from the terminal that started it.

Once my first instance of vscode is running, if I start a new terminal, cd into a project that does not have GOFLAGS set (and verify this with echo $GOFLAGS before starting vscode), and launch vscode with code ., the new vscode instance will be started with GOFLAGS=-mod=vendor, just like the running instance has it. If I override GOFLAGS on the command line and start the new instance of vscode with GOFLAGS="" code ., the new instance will get an empty GOFLAGS. If I exit the instance of vscode that has GOFLAGS=-mod=vendor and start the second instance again with code ., it will not get GOFLAGS set.

So it appears that the new vscode instance is getting at least some of its envars from the running instance. That might be expected behavior, but it comes as a surprise to me.

To reproduce this simply, create a pair of empty directories, like ~/a and ~/b. Then cd ~/a && GOFLAGS="-mod=vendor" code .', then cd ~/b && code .. Both instances of vscode will have GOFLAGS=-mod=vendor`.

This means that this bug, if it is a bug, is in vscode itself, and not the go plugin.

@trapgate
Copy link
Author

It looks like this is a duplicate of microsoft/vscode#15452

@hyangah
Copy link
Contributor

hyangah commented Jul 19, 2021

Thanks @trapgate for investigating it and sharing the info further.
I filed #1630 for UI/UX improvement.
Closing - I don't see anything immediately actionable from this extension.

@hyangah hyangah closed this as completed Jul 19, 2021
@hyangah hyangah removed the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jul 19, 2021
@cbrom
Copy link

cbrom commented Feb 17, 2022

Removing gopls from setting.json did the trick for me.

@coseyo
Copy link

coseyo commented Aug 26, 2022

Removing gopls from setting.json did the trick for me.

good to me, thanks!

@zoelabbb
Copy link

Removing gopls from setting.json did the trick for me.

I already do this, but still the same

@golang golang locked and limited conversation to collaborators Mar 29, 2024
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

7 participants