microsoft / vscode-go

An extension for VS Code which provides support for the Go language. We have moved to https://github.com/golang/vscode-go
Other
5.93k stars 647 forks source link

Request textDocument/hover failed. #2667

Closed mrdulin closed 5 years ago

mrdulin commented 5 years ago

This issue confused me for a month. My vscode go extension doesn't work well. For now it seems the intellisense doesn't work.

For example:

package application

import (
    "fmt"
    "serverless-functions-go/domain/models"
    "serverless-functions-go/domain/services"
    "serverless-functions-go/domain/services/adChannel/reports/adPerformance"
    "serverless-functions-go/infrastructure/config"
)

when I hover to the import statement, gopls give me below trace message:

[Trace - 3:07:51 PM] Sending notification 'textDocument/hover' in 1ms.
Params: {"textDocument":{"uri":"file:///Users/ldu020/workspace/github.com/mrdulin/golang/src/serverless-functions-go/application/adPerformanceReport.go"},"position":{"line":4,"character":23}}

[Error - 3:07:51 PM] Request textDocument/hover failed.
  Message: GetAST: unable to check package for file:///Users/ldu020/workspace/github.com/mrdulin/golang/src/serverless-functions-go/application/adPerformanceReport.go: no packages found for file:///Users/ldu020/workspace/github.com/mrdulin/golang/src/serverless-functions-go/application/adPerformanceReport.go
  Code: 0 

Another case, when I hover to a method,

func (uc *AdPerformanceReportUseCase) Get() error {
    googleAccountsForReport, err := uc.googleAccountService.FindGoogleAccountsForReport() // hover this method
    if err != nil {
        return err
    }
}

the gopls give me below trace messages:

[Error - 3:21:36 PM] Request textDocument/codeAction failed.
  Message: GetAST: unable to check package for file:///Users/ldu020/workspace/github.com/mrdulin/golang/src/serverless-functions-go/application/adPerformanceReport.go: no packages found for file:///Users/ldu020/workspace/github.com/mrdulin/golang/src/serverless-functions-go/application/adPerformanceReport.go
  Code: 0 
[Trace - 3:21:36 PM] Sending notification 'textDocument/codeAction' in 1ms.
Params: {"textDocument":{"uri":"file:///Users/ldu020/workspace/github.com/mrdulin/golang/src/serverless-functions-go/application/adPerformanceReport.go"},"range":{"start":{"line":31,"character":12},"end":{"line":31,"character":12}},"context":{"diagnostics":[]}}

[Trace - 3:21:37 PM] Received response 'textDocument/hover - (202)' in 0ms.
Params: {}

[Trace - 3:21:37 PM] Sending notification 'textDocument/hover' in 0ms.
Params: {"textDocument":{"uri":"file:///Users/ldu020/workspace/github.com/mrdulin/golang/src/serverless-functions-go/application/adPerformanceReport.go"},"position":{"line":36,"character":72}}

[Error - 3:21:37 PM] Request textDocument/hover failed.
  Message: GetAST: unable to check package for file:///Users/ldu020/workspace/github.com/mrdulin/golang/src/serverless-functions-go/application/adPerformanceReport.go: no packages found for file:///Users/ldu020/workspace/github.com/mrdulin/golang/src/serverless-functions-go/application/adPerformanceReport.go
  Code: 0 

version

vscode-go: 0.11.4 go: go version go1.12.6 darwin/amd64

Other informations

I set up two GOPATH:

GOPATH="/Users/ldu020/workspace/go:/Users/ldu020/workspace/github.com/mrdulin/golang"

GOPATH: /Users/ldu020/workspace/go is for storing go tools and other global level third-party modules, here is the directory tree:

☁  go  tree -L 2
.
├── bin
│   ├── dep
│   ├── dlv
│   ├── fillstruct
│   ├── go-outline
│   ├── go-symbols
│   ├── goaddimport
│   ├── gocode
│   ├── gocode-gomod
│   ├── godef
│   ├── godoctor
│   ├── gogetdoc
│   ├── goimports
│   ├── golangci-lint
│   ├── golint
│   ├── gometalinter
│   ├── gomodifytags
│   ├── gopkgs
│   ├── goplay
│   ├── gopls
│   ├── gorename
│   ├── goreturns
│   ├── gotests
│   ├── guru
│   ├── impl
│   └── revive
├── pkg
│   ├── darwin_amd64
│   └── mod
└── src
    ├── cloud.google.com
    ├── github.com
    └── golang.org

8 directories, 25 files

GOPATH: /Users/ldu020/workspace/github.com/mrdulin/golang is for storing my project and project level dependencies. Here is my directory tree:

☁  golang [master] tree -L 2                                                                                                                  
.
├── LICENSE
├── README.md
├── bin
│   └── error-stack
├── pkg
│   ├── darwin_amd64
│   └── dep
└── src
    ├── 22-channels
    ├── 23-buffered-channels-worker-pools
    ├── 24-select
    ├── 25-mutex
    ├── 26-oop-in-go
    ├── 29-defer
    ├── 30-error-handling
    ├── 31-custom-errors
    ├── decode-encode
    ├── gcp-cloud-function
    ├── gcp-cloud-run
    ├── gcp-stackdriver
    ├── gcp-storage
    ├── gorm-samples
    ├── goroutine
    ├── handle-form
    ├── http-server
    ├── interface
    ├── log
    ├── method
    ├── postgresql
    ├── rpc
    ├── serverless-functions-go
    └── sqlx-samples

29 directories, 3 files

This issue happens in src/serverless-functions-go project. Hope anyone can help me solve this issue.

I already post an issue https://github.com/golang/go/issues/32762 to official go repo. But it seems they don't think it's a gopls issue and they don't have time to take look at this. I don't know what's going on.

Any try

I try to reinstall all go tools for vscode-go extension at least ten times and reload the vscode window. The issue still there.

Here is my repo for reproducing this issue: https://github.com/mrdulin/golang

stamblerre commented 5 years ago

Sorry for the confusion on the other bug, I was explaining something else to another user--this is a gopls issue and the discussion should be moved back to that issue. I'm sorry I haven't been able to investigate it yet - we do have a lot of different things on our plate so sometimes issues slip through. I will write a follow-up there.

Davo36 commented 5 years ago

I'm also getting these errors:


  Message: GetAST: unable to check package for file:///c:/Users/David/Google%20Drive/Programming/The_Cacophony_Project/audiobait/main.go: no packages found for file:///c:/Users/David/Google%20Drive/Programming/The_Cacophony_Project/audiobait/main.go
  Code: 0 
[Error - 5:59:20 PM] Request textDocument/hover failed.
  Message: GetAST: unable to check package for file:///c:/Users/David/Google%20Drive/Programming/The_Cacophony_Project/audiobait/main.go: no packages found for file:///c:/Users/David/Google%20Drive/Programming/The_Cacophony_Project/audiobait/main.go
  Code: 0 
[Error - 6:08:18 PM] Request textDocument/hover failed.
  Message: GetAST: unable to check package for file:///c:/Users/David/Google%20Drive/Programming/The_Cacophony_Project/audiobait/main.go: no packages found for file:///c:/Users/David/Google%20Drive/Programming/The_Cacophony_Project/audiobait/main.go
  Code: 0 ```
stamblerre commented 5 years ago

@Davo36: Can you please open a separate issue on the Go issue tracker?

ramya-rao-a commented 5 years ago

Please log issues on the Go issue tracker for errors from the language server gopls