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

gopls and current path #2579

Closed
pierrre opened this issue Jun 18, 2019 · 5 comments
Closed

gopls and current path #2579

pierrre opened this issue Jun 18, 2019 · 5 comments

Comments

@pierrre
Copy link

pierrre commented Jun 18, 2019

Go version: go1.12.6 linux/amd64
VSCode version: 1.35.1
VSCode Go version: 0.11.0
Gopls version: the latest available at this time (da514acc4774e511ba0c2955844e655a5b20938c, I've installed it through vscode-go)

The language server doesn't work at all for me.
For each interaction with the editor, I see a lot of errors in the "gopls" logs:

[Error - 09:02:15] unable to check package for file:///home/pierre/gosrc/github.com/company/project/main.go: go/packages.Load: no packages found for /home/pierre/gosrc/github.com/company/project/main.go
[Error - 09:02:15] unable to check package for file:///home/pierre/gosrc/github.com/company/project/main.go: go/packages.Load: no packages found for /home/pierre/gosrc/github.com/company/project/main.go
[Error - 09:02:15] Request textDocument/codeAction failed.
  Message: no token file for file:///home/pierre/gosrc/github.com/company/project/main.go
  Code: 0 
[Error - 09:02:15] unable to check package for file:///home/pierre/gosrc/github.com/company/project/main.go: go/packages.Load: no packages found for /home/pierre/gosrc/github.com/company/project/main.go
[Error - 09:02:15] unable to check package for file:///home/pierre/gosrc/github.com/company/project/main.go: go/packages.Load: no packages found for /home/pierre/gosrc/github.com/company/project/main.go
[Error - 09:02:15] Request textDocument/documentLink failed.
  Message: no AST for file:///home/pierre/gosrc/github.com/company/project/main.go
  Code: 0 
[Error - 09:02:15] unable to check package for file:///home/pierre/gosrc/github.com/company/project/main.go: go/packages.Load: no packages found for /home/pierre/gosrc/github.com/company/project/main.go
[Error - 09:02:15] unable to check package for file:///home/pierre/gosrc/github.com/company/project/main.go: go/packages.Load: no packages found for /home/pierre/gosrc/github.com/company/project/main.go
[Error - 09:02:15] unable to check package for file:///home/pierre/gosrc/github.com/company/project/main.go: go/packages.Load: no packages found for /home/pierre/gosrc/github.com/company/project/main.go
[Error - 09:02:15] Request textDocument/codeAction failed.
  Message: no file information for file:///home/pierre/gosrc/github.com/company/project/main.go
  Code: 0 

I can reproduce the issue using the command line (call gopls manually).
If my current directory is not inside the project, I get the same error message.
If my current directory is inside the current project, it works fine.

My VSCode config:

{
	"window.titleBarStyle": "custom",
	"workbench.colorTheme": "Default Dark+",
	"workbench.startupEditor": "none",
	"workbench.settings.editor": "json",
	"workbench.settings.useSplitJSON": true,
	"workbench.list.horizontalScrolling": true,

	"editor.fontFamily": "'Source Code Pro'",
	"editor.fontSize": 12,
	"terminal.integrated.fontSize": 12,
	"editor.lineHeight": 14,
	"editor.renderWhitespace": "boundary",
	"editor.wordWrap": "on",
	"editor.insertSpaces": false,
	"editor.smoothScrolling": true,

	"files.enableTrash": false,
	"files.autoSave": "onFocusChange",
	"files.trimTrailingWhitespace": true,
	"files.insertFinalNewline": true,
	"files.trimFinalNewlines": true,
	"files.associations": {
		"Gopkg.lock": "toml",
		"Dockerfile*": "dockerfile"
	},

	"search.usePCRE2": true,
	"search.location": "panel",

	"go.goroot": "/home/pierre/.gimme/versions/go1.12.6.src",
	"go.gopath": "/home/pierre/go",
	"go.useLanguageServer": true,
	"go.formatTool": "goimports",
	"go.autocompleteUnimportedPackages": true,
	"go.buildOnSave": "package",
	"go.buildFlags": [
		"-gcflags=-e"
	],
	"go.testOnSave": true,
	"go.testFlags": [
		"-short"
	],
	"go.coverOnSave": true,
	"go.coverageDecorator": {
		"type": "gutter",
		"coveredGutterStyle": "blockgreen",
		"uncoveredGutterStyle": "blockred"
	},
	"go.vetOnSave": "off",
	"go.lintOnSave": "package",
	"go.lintTool": "golangci-lint"
}
@pierrre pierrre changed the title gopls and absolute path gopls and current path Jun 18, 2019
@goltvn
Copy link

goltvn commented Jun 18, 2019

mine is also seems broken - cant get any compiler info if its active, if i disable it i get compiler info again.

https://www.dropbox.com/s/w3njtkekp3cf92m/2019-06-18_14-23-13.mp4?dl=0

@pierrre
Copy link
Author

pierrre commented Jun 18, 2019

I've found a workaround.

In my current workflow, I'm opening the directory /home/pierre/gosrc (which is NOT my GOPATH) in my vscode workspace.
When I try to use gopls, it fails.

However, if I open a new window, containing only 1 single project, it works !
So I guess that vscode-go runs the commands relatively to the root directory of the workspace.

But I can't work like this, I need to have quick access to all my projects.

@pierrre
Copy link
Author

pierrre commented Jun 18, 2019

PS: maybe there is an acceptable workflow:

  • open a new vscode workspace
  • add each project as a root directory in my workspace

@stamblerre
Copy link
Contributor

@pierrre: If you are using modules, you will have to use the approach of multiple workspace folders. The editor notifies gopls where the module root is, so if you open a directory above the module root, gopls will not work correctly.

@pierrre
Copy link
Author

pierrre commented Jun 19, 2019

OK thank you, I'm closing this issue, and will follow golang/go#32394

@pierrre pierrre closed this as completed Jun 19, 2019
@vscodebot vscodebot bot locked and limited conversation to collaborators Aug 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants