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

x/tools/gopls: import organization not working #43904

Closed
bokunodev opened this issue Jan 25, 2021 · 23 comments
Closed

x/tools/gopls: import organization not working #43904

bokunodev opened this issue Jan 25, 2021 · 23 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@bokunodev
Copy link

bokunodev commented Jan 25, 2021

What version of Go are you using (go version)?

$ go version
go version go1.15.7 linux/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN="/home/bokuno/go/go/bin"
GOCACHE="/home/bokuno/go/cache/go-build"
GOENV="/home/bokuno/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/bokuno/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/bokuno/go/path"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,https://index.golang.org,direct"
GOROOT="/home/bokuno/go/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/bokuno/go/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O3"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O3"
CGO_FFLAGS="-g -O3"
CGO_LDFLAGS="-g -O3"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build673743594=/tmp/go-build -gno-record-gcc-switches"

What did you do?

open a directory with a go.mod file in vscode/codium

What did you expect to see?

auto import works fine.

What did you see instead?

[Error - 3:00:54 PM] Request textDocument/definition failed.
  Message: no object found for ident server: no object found
  Code: 0

Sublime LSP works fine. is there any on how vscode/codium handle directory, compare to sublime ?

gopls & gopls (server) logs
6-gopls (server).log
7-gopls.log

settings.json.txt
Screenshot_2021-01-26_02-43-29

@gopherbot gopherbot added the gopls Issues related to the Go language server, gopls. label Jan 25, 2021
@stamblerre
Copy link
Contributor

You will need to remove the -logfile flag from your VS Code settings that you shared on the other issue. It's not necessary if you're getting the log from the output channel. Once you've done that, please share a new version of the gopls (server) logs.

@stamblerre stamblerre changed the title gopls auto import didnt work. x/tools/gopls: import organization not working Jan 25, 2021
@stamblerre stamblerre added this to the gopls/v1.0.0 milestone Jan 25, 2021
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Jan 25, 2021
@bokunodev
Copy link
Author

New version

[Trace - 03:03:34.896 AM] Sending request 'initialize - (0)'.
Params: {"processId":36765,"clientInfo":{"name":"vscode","version":"1.52.1"},"rootPath":"/home/bokuno/Public/sandbox","rootUri":"file:///home/bokuno/Public/sandbox","capabilities":{"workspace":{"applyEdit":true,"workspaceEdit":{"documentChanges":true,"resourceOperations":["create","rename","delete"],"failureHandling":"textOnlyTransactional"},"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]}},"executeCommand":{"dynamicRegistration":true},"configuration":true,"workspaceFolders":true,"semanticTokens":{"refreshSupport":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"]}},"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"]}}},"codeLens":{"dynamicRegistration":true},"formatting":{"dynamicRegistration":true},"rangeFormatting":{"dynamicRegistration":true},"onTypeFormatting":{"dynamicRegistration":true},"rename":{"dynamicRegistration":true,"prepareSupport":true,"prepareSupportDefaultBehavior":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","member","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}}}},"window":{"workDoneProgress":true}},"initializationOptions":{},"trace":"verbose","workspaceFolders":[{"uri":"file:///home/bokuno/Public/sandbox","name":"sandbox"}]}


[Trace - 03:03:34.898 AM] Received response 'initialize - (0)' in 2ms.
Result: {"capabilities":{"textDocumentSync":{"openClose":true,"change":2,"save":{}},"completionProvider":{"triggerCharacters":["."]},"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.generate","gopls.fill_struct","gopls.regenerate_cgo","gopls.test","gopls.tidy","gopls.update_go_sum","gopls.undeclared_name","gopls.go_get_package","gopls.add_dependency","gopls.upgrade_dependency","gopls.remove_dependency","gopls.vendor","gopls.extract_variable","gopls.extract_function","gopls.gc_details","gopls.generate_gopls_mod"]},"callHierarchyProvider":true,"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":"workspace/didChangeWorkspaceFolders"}}},"serverInfo":{"name":"gopls","version":"{\"path\":\"golang.org/x/tools/gopls\",\"version\":\"(devel)\",\"deps\":[{\"path\":\"github.com/BurntSushi/toml\",\"version\":\"v0.3.1\",\"sum\":\"h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=\"},{\"path\":\"github.com/google/go-cmp\",\"version\":\"v0.5.4\",\"sum\":\"h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=\"},{\"path\":\"github.com/sergi/go-diff\",\"version\":\"v1.1.0\",\"sum\":\"h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=\"},{\"path\":\"golang.org/x/mod\",\"version\":\"v0.4.0\",\"sum\":\"h1:8pl+sMODzuvGJkmj2W4kZihvVb5mKm8pB/X44PIQHv8=\"},{\"path\":\"golang.org/x/sync\",\"version\":\"v0.0.0-20201020160332-67f06af15bc9\",\"sum\":\"h1:SQFwaSi55rU7vdNs9Yr0Z324VNlrF+0wMqRXT4St8ck=\"},{\"path\":\"golang.org/x/sys\",\"version\":\"v0.0.0-20210119212857-b64e53b001e4\",\"sum\":\"h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k=\"},{\"path\":\"golang.org/x/tools\",\"version\":\"v0.0.0-20210104081019-d8d6ddbec6ee\",\"replace\":{\"path\":\"../\"}},{\"path\":\"golang.org/x/xerrors\",\"version\":\"v0.0.0-20200804184101-5ec99f83aff1\",\"sum\":\"h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=\"},{\"path\":\"honnef.co/go/tools\",\"version\":\"v0.0.1-2020.1.6\",\"sum\":\"h1:W18jzjh8mfPez+AwGLxmOImucz/IFjpNlrKVnaj2YVc=\"},{\"path\":\"mvdan.cc/gofumpt\",\"version\":\"v0.1.0\",\"sum\":\"h1:hsVv+Y9UsZ/mFZTxJZuHVI6shSQCtzZ11h1JEFPAZLw=\"},{\"path\":\"mvdan.cc/xurls/v2\",\"version\":\"v2.2.0\",\"sum\":\"h1:NSZPykBXJFCetGZykLAxaL6SIpvbVy/UFEniIfHAa8A=\"}]}"}}


[Trace - 03:03:34.979 AM] Sending notification 'initialized'.
Params: {}


[Trace - 03:03:34.982 AM] Received request 'window/workDoneProgress/create - (1)'.
Params: {"token":"5577006791947779410"}


[Trace - 03:03:34.984 AM] Sending response 'window/workDoneProgress/create - (1)' in 1ms.
Result: 


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


[Trace - 03:03:34.984 AM] Received request 'workspace/configuration - (2)'.
Params: {"items":[{"scopeUri":"file:///home/bokuno/Public/sandbox","section":"gopls"}]}


[Trace - 03:03:34.992 AM] Sending response 'workspace/configuration - (2)' in 8ms.
Result: [{}]


[Trace - 03:03:35.226 AM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2021/01/26 03:03:35 go env for /home/bokuno/Public/sandbox\n(root /home/bokuno/Public/sandbox)\n(go version go version go1.15.7 linux/amd64)\n(valid build configuration = true)\n(build flags: [])\nGOPATH=/home/bokuno/go/path\nGOFLAGS=\nGOROOT=/home/bokuno/go/go\nGOCACHE=/home/bokuno/go/cache/go-build\nGOINSECURE=\nGOMOD=/home/bokuno/Public/sandbox/go.mod\nGOMODCACHE=/home/bokuno/go/pkg/mod\nGOPRIVATE=\nGO111MODULE=on\nGONOPROXY=\nGONOSUMDB=\nGOPROXY=https://proxy.golang.org,https://index.golang.org,direct\nGOSUMDB=sum.golang.org\n\n"}


[Info  - 3:03:35 AM] 2021/01/26 03:03:35 go env for /home/bokuno/Public/sandbox
(root /home/bokuno/Public/sandbox)
(go version go version go1.15.7 linux/amd64)
(valid build configuration = true)
(build flags: [])
GOPATH=/home/bokuno/go/path
GOFLAGS=
GOROOT=/home/bokuno/go/go
GOCACHE=/home/bokuno/go/cache/go-build
GOINSECURE=
GOMOD=/home/bokuno/Public/sandbox/go.mod
GOMODCACHE=/home/bokuno/go/pkg/mod
GOPRIVATE=
GO111MODULE=on
GONOPROXY=
GONOSUMDB=
GOPROXY=https://proxy.golang.org,https://index.golang.org,direct
GOSUMDB=sum.golang.org


[Trace - 03:03:35.728 AM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2021/01/26 03:03:35 go/packages.Load\n\tsnapshot=0\n\tdirectory=/home/bokuno/Public/sandbox\n\tquery=[builtin sandbox/...]\n\tpackages=3\n"}


[Info  - 3:03:35 AM] 2021/01/26 03:03:35 go/packages.Load
	snapshot=0
	directory=/home/bokuno/Public/sandbox
	query=[builtin sandbox/...]
	packages=3

[Trace - 03:03:35.942 AM] Sending notification 'textDocument/didOpen'.
Params: {"textDocument":{"uri":"file:///home/bokuno/Public/sandbox/cmd/main.go","languageId":"go","version":1,"text":"package main\n\nimport (\n\t\"flag\"\n)\n\nvar (\n\taddr = flag.String(\"addr\", \":8080\", \"address to bind\")\n\tcert = flag.String(\"cert\", \"\", \"path to ssl cert file\")\n\tkey  = flag.String(\"key\", \"\", \"path to ssl key file\")\n\tfile = flag.String(\"file\", \"\", \"path to config.json\")\n)\n\nfunc main() {\n\tflag.Parse()\n\n\tapp := server.New(*addr, *cert, *key)\n\tapp.ListenAndServe()\n}\n"}}


[Trace - 03:03:35.942 AM] Sending request 'textDocument/documentLink - (1)'.
Params: {"textDocument":{"uri":"file:///home/bokuno/Public/sandbox/cmd/main.go"}}


[Trace - 03:03:35.942 AM] Sending request 'textDocument/codeAction - (2)'.
Params: {"textDocument":{"uri":"file:///home/bokuno/Public/sandbox/cmd/main.go"},"range":{"start":{"line":0,"character":0},"end":{"line":0,"character":0}},"context":{"diagnostics":[]}}


[Trace - 03:03:35.942 AM] Sending request 'textDocument/documentSymbol - (3)'.
Params: {"textDocument":{"uri":"file:///home/bokuno/Public/sandbox/cmd/main.go"}}


[Trace - 03:03:35.943 AM] Sending request 'textDocument/documentHighlight - (4)'.
Params: {"textDocument":{"uri":"file:///home/bokuno/Public/sandbox/cmd/main.go"},"position":{"line":16,"character":10}}


[Trace - 03:03:36.042 AM] Received notification '$/progress'.
Params: {"token":"5577006791947779410","value":{"kind":"end","message":"Finished loading packages."}}


[Trace - 03:03:36.046 AM] Received request 'client/registerCapability - (3)'.
Params: {"registrations":[{"id":"workspace/didChangeWatchedFiles-0","method":"workspace/didChangeWatchedFiles","registerOptions":{"watchers":[{"globPattern":"{/home/bokuno/Public/sandbox/cmd,/home/bokuno/Public/sandbox/server}","kind":7},{"globPattern":"**/*.{go,mod,sum}","kind":7}]}}]}


[Trace - 03:03:36.049 AM] Sending response 'client/registerCapability - (3)' in 3ms.
Result: 


[Trace - 03:03:36.051 AM] Received request 'client/registerCapability - (4)'.
Params: {"registrations":[{"id":"workspace/didChangeConfiguration","method":"workspace/didChangeConfiguration"},{"id":"workspace/didChangeWorkspaceFolders","method":"workspace/didChangeWorkspaceFolders"}]}


[Trace - 03:03:36.116 AM] Sending response 'client/registerCapability - (4)' in 64ms.
Result: 


[Trace - 03:03:36.116 AM] Sending request 'textDocument/foldingRange - (5)'.
Params: {"textDocument":{"uri":"file:///home/bokuno/Public/sandbox/cmd/main.go"}}


[Trace - 03:03:36.261 AM] Sending notification '$/cancelRequest'.
Params: {"id":5}


[Trace - 03:03:36.573 AM] Sending request 'textDocument/codeAction - (6)'.
Params: {"textDocument":{"uri":"file:///home/bokuno/Public/sandbox/cmd/main.go"},"range":{"start":{"line":16,"character":10},"end":{"line":16,"character":10}},"context":{"diagnostics":[]}}


[Trace - 03:03:36.574 AM] Sending notification '$/cancelRequest'.
Params: {"id":2}


[Trace - 03:03:36.575 AM] Sending request 'textDocument/codeLens - (7)'.
Params: {"textDocument":{"uri":"file:///home/bokuno/Public/sandbox/cmd/main.go"}}


[Trace - 03:03:36.575 AM] Sending request 'textDocument/foldingRange - (8)'.
Params: {"textDocument":{"uri":"file:///home/bokuno/Public/sandbox/cmd/main.go"}}


[Trace - 03:03:36.916 AM] Received notification 'textDocument/publishDiagnostics'.
Params: {"uri":"file:///home/bokuno/Public/sandbox/cmd/main.go","version":1,"diagnostics":[{"range":{"start":{"line":16,"character":8},"end":{"line":16,"character":18}},"severity":1,"source":"compiler","message":"undeclared name: server"}]}


[Trace - 03:03:36.920 AM] Received response 'textDocument/documentLink - (1)' in 978ms.
Result: [{"range":{"start":{"line":3,"character":2},"end":{"line":3,"character":6}},"target":"https://pkg.go.dev/flag?utm_source=gopls"}]


[Error - Received] 03:03:37.515 AM #2 JSON RPC cancelled


[Trace - 03:03:37.556 AM] Received response 'textDocument/documentHighlight - (4)' in 1613ms.
Result: [{"range":{"start":{"line":16,"character":8},"end":{"line":16,"character":14}},"kind":1}]


[Error - Received] 03:03:37.556 AM #5 JSON RPC cancelled


[Trace - 03:03:37.560 AM] Received response 'textDocument/documentSymbol - (3)' in 1617ms.
Result: [{"name":"addr","detail":"*string","kind":13,"range":{"start":{"line":6,"character":0},"end":{"line":11,"character":1}},"selectionRange":{"start":{"line":7,"character":1},"end":{"line":7,"character":5}}},{"name":"cert","detail":"*string","kind":13,"range":{"start":{"line":6,"character":0},"end":{"line":11,"character":1}},"selectionRange":{"start":{"line":8,"character":1},"end":{"line":8,"character":5}}},{"name":"key","detail":"*string","kind":13,"range":{"start":{"line":6,"character":0},"end":{"line":11,"character":1}},"selectionRange":{"start":{"line":9,"character":1},"end":{"line":9,"character":4}}},{"name":"file","detail":"*string","kind":13,"range":{"start":{"line":6,"character":0},"end":{"line":11,"character":1}},"selectionRange":{"start":{"line":10,"character":1},"end":{"line":10,"character":5}}},{"name":"main","detail":"()","kind":12,"range":{"start":{"line":13,"character":0},"end":{"line":18,"character":1}},"selectionRange":{"start":{"line":13,"character":5},"end":{"line":13,"character":9}}}]


[Trace - 03:03:37.654 AM] Received response 'textDocument/codeAction - (6)' in 1080ms.
Result: null


[Trace - 03:03:37.655 AM] Received response 'textDocument/codeLens - (7)' in 1080ms.
Result: null


[Trace - 03:03:37.656 AM] Received response 'textDocument/foldingRange - (8)' in 1080ms.
Result: [{"startLine":2,"startCharacter":8,"endLine":3,"endCharacter":7,"kind":"imports"},{"startLine":6,"startCharacter":5,"endLine":10,"endCharacter":54},{"startLine":13,"startCharacter":13,"endLine":17,"endCharacter":21}]


[Trace - 03:03:37.733 AM] Sending request 'textDocument/codeAction - (9)'.
Params: {"textDocument":{"uri":"file:///home/bokuno/Public/sandbox/cmd/main.go"},"range":{"start":{"line":16,"character":10},"end":{"line":16,"character":10}},"context":{"diagnostics":[{"range":{"start":{"line":16,"character":8},"end":{"line":16,"character":18}},"message":"undeclared name: server","severity":1,"source":"compiler"}]}}


[Trace - 03:03:37.734 AM] Sending notification '$/cancelRequest'.
Params: {"id":6}


[Trace - 03:03:38.199 AM] Received response 'textDocument/codeAction - (9)' in 466ms.
Result: null

@stamblerre
Copy link
Contributor

To start, it looks like you might be using an unstable version of gopls (the latest is v0.6.4). Can you please try updating your gopls version? You can do so by opening the Command Palette (Ctrl+Shift+P) and selecting "Go: Install/Update Tools".

@bokunodev
Copy link
Author

bokunodev commented Jan 25, 2021

like I said, there's nothing wrong with gopls.
because everything works fine with the sublime text LSP.

I do it anyway and the problem persists.

Tools environment: GOPATH=/home/bokuno/go/path, GOBIN=/home/bokuno/go/go/bin
Installing 1 tool at the configured GOBIN: /home/bokuno/go/go/bin in module mode.
  gopls

Installing golang.org/x/tools/gopls (/home/bokuno/go/go/bin/gopls) SUCCEEDED

All tools successfully installed. You are ready to Go :).

@stamblerre
Copy link
Contributor

I've tried to reproduce this, but I haven't been able to. Is this project public / can you share a project that we can use to repro this issue?

@stamblerre stamblerre added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jan 26, 2021
@bokunodev
Copy link
Author

bokunodev commented Jan 26, 2021

sure, its just a dummy sandbox
also, if i execute gopls imports cmd/main.go from within the dir, the import succed. but not from the outside.

sandbox.tar.gz

@heschi
Copy link
Contributor

heschi commented Jan 27, 2021

Sorry, I still can't reproduce this. I removed the sandbox/server import, opened the directory containing sandbox and everything worked fine in vscode. I also tried with gopls imports.

My only suggestion is to try reproducing in as minimal an environment as possible.

@bokunodev
Copy link
Author

bokunodev commented Jan 27, 2021

may i know, how do you setup your vscode ?
do i need any other tool besides gopls ?
like gocode, guru etc. to make it work ?
because I can't get it to work no matter what.
-
I've tried go-nightly and go (stable) and none of them seem to work.
-
also, my Sublime invoke the oldgoimports command onsave.
because Sublime LSP does support organize imports yet.
and that's why auto import is working in Sublime text.

@stamblerre
Copy link
Contributor

I am also unable to reproduce this, but you shouldn't need any tools other than gopls. Now may be the moment to add some additional logging to better understand the problem. Can you please set the following in your VS Code settings.json:

"gopls": {
	"verboseOutput": true
}

If that doesn't clarify the problem, I may have to ask you to add some additional logging statements and rebuild gopls with them.

@bokunodev
Copy link
Author

bokunodev commented Feb 6, 2021

i just try it in a windows and it works as expected.
but somehow, i cant get it to works in linux (debian & arch).

@stamblerre
Copy link
Contributor

@bokunodev: Can you share the logs with verbose output when you try it on Linux?

@bokunodev
Copy link
Author

bokunodev commented Feb 6, 2021

i just noticed, vcode in windows and linux, they have different output.
this part:

// windows
[Info  - 4:11:44 PM] 2021/02/06 16:11:44 go env for D:\gosandbox\p1
(root D:\gosandbox\p1)
(go version go version go1.15.8 windows/386)
(valid build configuration = true)
(build flags: [])
GO111MODULE=
GOCACHE=C:\Users\user\AppData\Local\go-build
GOFLAGS=
GOROOT=D:\Go
GOINSECURE=
GONOSUMDB=
GOPRIVATE=
GOPROXY=https://proxy.golang.org,direct
GOSUMDB=sum.golang.org
GOMOD=D:\gosandbox\p1\go.mod // <--- in windows the value is path to go.mod file
GOMODCACHE=C:\Users\user\go\pkg\mod
GONOPROXY=
GOPATH=C:\Users\user\go

// archlinux
[Info  - 11:34:43 PM] 2021/02/06 23:34:43 go env for /home/boku/Public/go-example
(root /home/boku/Public/go-example/example)
(go version go version go1.16rc1 linux/amd64)
(valid build configuration = true)
(build flags: [])
GOCACHE=/home/boku/go/cache/go-build
GOMOD=/dev/null // <--- in linux the value is /dev/null (ALWAYS) ? why is that ? 
GO111MODULE=
GONOPROXY=
GOPATH=/home/boku/go/path
GOSUMDB=sum.golang.org
GOMODCACHE=/home/boku/go/pkg/mod
GONOSUMDB=
GOPRIVATE=
GOINSECURE=
GOPROXY=https://proxy.golang.org,https://index.golang.org,direct
GOROOT=/home/boku/go/go
GOFLAGS=

archlinux.log
windows.log

@stamblerre
Copy link
Contributor

So it sounds like you may have some misconfiguration of your environment on Linux. Is there a go.mod file in the /home/boku/Public/go-example/example directory?

@bokunodev
Copy link
Author

bokunodev commented Feb 9, 2021

@stamblerre the example folder is the same as the previously attached screenshot. I just changed the name and re-initialized the go module

out.mp4

@stamblerre
Copy link
Contributor

I just noticed this discrepancy:

[Info  - 11:34:43 PM] 2021/02/06 23:34:43 go env for /home/boku/Public/go-example
(root /home/boku/Public/go-example/example)

Can you try opening the /home/boku/Public/go-example/example directory instead of the /home/boku/Public/go-example directory?

@bokunodev
Copy link
Author

bokunodev commented Feb 9, 2021

i tried before and i just did.
and the result is still the same, success on windows, failed on linux.
-
this discussion lead us nowhere.

@stamblerre
Copy link
Contributor

Can you please share a log when you run from the /home/boku/Public/go-example/example directory? gopls has special handling when you're running from a directory that contains a module in a subdirectory, so I wonder if there's a bug in that handling.

@bokunodev
Copy link
Author

bokunodev commented Feb 9, 2021

@stamblerre
what command i should run ? vscode $PWD or gopls serve ??
what logs? what commands should I run? is the file I attached above not the correct log?
please, don't give me incomplete instructions.

@stamblerre
Copy link
Contributor

The logs should be the same as the ones you shared above - https://github.com/golang/vscode-go/blob/master/docs/troubleshooting.md#collect-extension-logs includes full instructions.

My request is that you open VS Code from the /home/boku/Public/go-example/example directory, trigger import organization, and share the resulting log file. If you open VS Code from the command-line, the command should be code /home/boku/Public/go-example/example.

@bokunodev
Copy link
Author

bokunodev commented Feb 9, 2021

we are running in a circle

simplescreenrecorder-2021-02-10_03.11.22.mp4

4-gopls (server).log.txt
5-gopls.log.txt
exthost.log

@stamblerre
Copy link
Contributor

Thank you for bearing with us. These types of issues can be tricky to diagnose and logs are critical to our understanding.

It looks like goimports is operating in GOPATH-mode even though you have a go.mod file in your workspace. We're not entirely clear on why that's happening, so @heschik will upload a change with additional logging, and we will ask you to rebuild gopls with this extra logging once that is available.

In the meantime, we noticed that a few of your environment variables appear to be misconfigured. Specifically, it looks like your GOPATH is set to a directory that does not exist:

Params: {"type":3,"message":"2021/02/10 03:11:54 skipping nonexistent directory: /home/boku/go/path/src\n"}

Typically, GOMODCACHE defaults to $GOPATH/pkg/mod, so if you create that directory, that might save you from having to configure GOMODCACHE separately. Also, GOPROXY=https://proxy.golang.org,https://index.golang.org,direct should not include https://index.golang.org (you can remove that environment variable entirely, since https://proxy.golang.org,direct is already the default value. Finally, GOFLAGS should be a "space-separated list of -flag=value settings" (https://tip.golang.org/cmd/go/#hdr-Environment_variables), so I think GOFLAGS=-trimpath -v is not valid.

I don't expect that making these corrections will resolve the problem, but please let us know if it does. We will follow up with additional logging soon.

@bokunodev
Copy link
Author

bokunodev commented Feb 10, 2021

i think i found the culprit.
i though empty enviromen variable and unset enviroment variable should behave the same.
but anyway, this problem is solved.
i think this is related to the use of os.Environ

simplescreenrecorder-2021-02-10_08.31.37.mp4

@stamblerre
Copy link
Contributor

Ok, I'm glad to hear that solved the issue. OK to close this now?

@stamblerre stamblerre removed this from the gopls/v1.0.0 milestone Feb 10, 2021
@golang golang locked and limited conversation to collaborators Feb 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants