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/internal/lsp: doesn't work with VS Code on Windows #30967

Closed
ChrisHines opened this issue Mar 21, 2019 · 10 comments
Closed

x/tools/internal/lsp: doesn't work with VS Code on Windows #30967

ChrisHines opened this issue Mar 21, 2019 · 10 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Milestone

Comments

@ChrisHines
Copy link
Contributor

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

$ go version
go version go1.12.1 windows/amd64

VS Code About Box:
Version: 1.32.3 (user setup)
Commit: a3db5be9b5c6ba46bb7555ec5d60178ecc2eaae4
Date: 2019-03-14T23:43:35.476Z
Electron: 3.1.6
Chrome: 66.0.3359.181
Node.js: 10.2.0
V8: 6.6.346.32
OS: Windows_NT x64 10.0.17134

Go Extension for VS Code: 0.9.2

golang.org/x/tools: commit b6b7807791df8aa3e230578a98256106c4f912ab (Mon Mar 18 19:56:56 2019 +0000)

Does this issue reproduce with the latest release?

Yes, on Windows, but not on a Mac with the same versions of all the components shown above and the same go.* VS Code configuration entries shown below.

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

go env Output
$ go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Chris\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\Chris\Go
set GOPROXY=
set GORACE=
set GOROOT=C:\Go
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\Chris\AppData\Local\Temp\go-build162316554=/tmp/go-build -gno-record-gcc-switches

VS Code config (go.* entries):

// go
"go.useLanguageServer": true,
"go.alternateTools": {
    "go-langserver": "gopls"
},
"go.languageServerExperimentalFeatures": {
    "format": true,
    "autoComplete": true,
    "goToDefinition": true,
    "hover": true,
    "signatureHelp": true,
    "goToTypeDefinition": true
},
"go.buildOnSave": "off",
"go.vetOnSave": "off",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
    "source.organizeImports": true
},
"go.lintTool": "gometalinter",
"go.lintFlags": [
    "--disable-all",
    "--enable=golint",
    "--enable=staticcheck",
    "--deadline=60s"
],
// "go.docsTool": "gogetdoc",
// "go.buildOnSave": "package",
"go.useCodeSnippetsOnFunctionSuggestWithoutType": true,
"go.testFlags": [
    "-v"
],
"go.coverOnSingleTest": true,

What did you do?

Tried to use gopls with VSCode on Windows

  1. Create a project directory outside GOPATH
  2. Create a file in the project directory containing:
package main

import "fmt"

func main() {
	fmt.Println("Hello, world!")
}
  1. Open the project folder in VS Code and hover the mouse over "Println".

What did you expect to see?

A popup showing information about the fmt.Println function.

What did you see instead?

Nothing in the editor panel.

But also, VS Code's go-langserver output panel logged the following details showing several errors:

[Trace - 10:47:59 PM] Sending request 'initialize - (0)'.
Params: {"processId":32060,"rootPath":"c:\\Users\\Chris\\proj\\test-proj","rootUri":"file:///c%3A/Users/Chris/proj/test-proj","capabilities":{"workspace":{"applyEdit":true,"workspaceEdit":{"documentChanges":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]}},"executeCommand":{"dynamicRegistration":true},"configuration":true,"workspaceFolders":true},"textDocument":{"publishDiagnostics":{"relatedInformation":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},"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"]}},"definition":{"dynamicRegistration":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]}},"codeAction":{"dynamicRegistration":true,"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},"documentLink":{"dynamicRegistration":true},"typeDefinition":{"dynamicRegistration":true},"implementation":{"dynamicRegistration":true},"colorProvider":{"dynamicRegistration":true}}},"initializationOptions":{"funcSnippetEnabled":false,"gocodeCompletionEnabled":true},"trace":"off","workspaceFolders":[{"uri":"file:///c%3A/Users/Chris/proj/test-proj","name":"test-proj"}]}


[Trace - 10:47:59 PM] Received response 'initialize - (0)' in 1ms.
Params: {"capabilities":{"textDocumentSync":{"openClose":true,"change":1},"hoverProvider":true,"completionProvider":{"triggerCharacters":["."]},"signatureHelpProvider":{"triggerCharacters":["(",","]},"definitionProvider":true,"codeActionProvider":true,"documentFormattingProvider":true,"documentRangeFormattingProvider":true,"typeDefinitionProvider":true},"custom":null}


[Trace - 10:47:59 PM] Sending notification 'initialized'.
Params: {}


[Trace - 10:47:59 PM] Sending notification 'textDocument/didOpen'.
Params: {"textDocument":{"uri":"file:///c%3A/Users/Chris/proj/test-proj/main.go","languageId":"go","version":1,"text":"package main\r\n\r\nimport \"fmt\"\r\n\r\nfunc main() {\r\n\tfmt.Println(\"Hello, world!\")\r\n}\r\n"}}


[Trace - 10:48:00 PM] Sending request 'textDocument/codeAction - (1)'.
Params: {"textDocument":{"uri":"file:///c%3A/Users/Chris/proj/test-proj/main.go"},"range":{"start":{"line":2,"character":11},"end":{"line":2,"character":11}},"context":{"diagnostics":[]}}


[Error - 10:48:00 PM] send textDocument/codeAction#1 no file information for file:///c%3A/Users/Chris/proj/test-proj/main.go


[Error - 10:48:00 PM] Request textDocument/codeAction failed.
  Message: no file information for file:///c%3A/Users/Chris/proj/test-proj/main.go
  Code: 0 
[Trace - 10:48:00 PM] Sending request 'textDocument/codeAction - (2)'.
Params: {"textDocument":{"uri":"file:///c%3A/Users/Chris/proj/test-proj/main.go"},"range":{"start":{"line":2,"character":11},"end":{"line":2,"character":11}},"context":{"diagnostics":[]}}


[Error - 10:48:00 PM] send textDocument/codeAction#2 no file information for file:///c%3A/Users/Chris/proj/test-proj/main.go


[Error - 10:48:00 PM] Request textDocument/codeAction failed.
  Message: no file information for file:///c%3A/Users/Chris/proj/test-proj/main.go
  Code: 0 
[Trace - 10:48:45 PM] Sending request 'textDocument/codeAction - (3)'.
Params: {"textDocument":{"uri":"file:///c%3A/Users/Chris/proj/test-proj/main.go"},"range":{"start":{"line":0,"character":0},"end":{"line":7,"character":0}},"context":{"diagnostics":[]}}


[Error - 10:48:45 PM] send textDocument/codeAction#3 no file information for file:///c%3A/Users/Chris/proj/test-proj/main.go


[Error - 10:48:45 PM] Request textDocument/codeAction failed.
  Message: no file information for file:///c%3A/Users/Chris/proj/test-proj/main.go
  Code: 0 
[Trace - 10:59:52 PM] Sending request 'textDocument/codeAction - (4)'.
Params: {"textDocument":{"uri":"file:///c%3A/Users/Chris/proj/test-proj/main.go"},"range":{"start":{"line":0,"character":0},"end":{"line":0,"character":0}},"context":{"diagnostics":[]}}


[Error - 10:59:52 PM] send textDocument/codeAction#4 no file information for file:///c%3A/Users/Chris/proj/test-proj/main.go


[Error - 10:59:52 PM] Request textDocument/codeAction failed.
  Message: no file information for file:///c%3A/Users/Chris/proj/test-proj/main.go
  Code: 0 
[Trace - 10:59:52 PM] Sending request 'textDocument/codeAction - (5)'.
Params: {"textDocument":{"uri":"file:///c%3A/Users/Chris/proj/test-proj/main.go"},"range":{"start":{"line":0,"character":0},"end":{"line":7,"character":0}},"context":{"diagnostics":[]}}


[Error - 10:59:52 PM] send textDocument/codeAction#5 no file information for file:///c%3A/Users/Chris/proj/test-proj/main.go


[Error - 10:59:52 PM] Request textDocument/codeAction failed.
  Message: no file information for file:///c%3A/Users/Chris/proj/test-proj/main.go
  Code: 0 
[Trace - 10:59:52 PM] Sending request 'textDocument/hover - (6)'.
Params: {"textDocument":{"uri":"file:///c%3A/Users/Chris/proj/test-proj/main.go"},"position":{"line":5,"character":29}}


[Error - 10:59:52 PM] send textDocument/hover#6 no file information for file:///c%3A/Users/Chris/proj/test-proj/main.go


[Error - 10:59:52 PM] Request textDocument/hover failed.
  Message: no file information for file:///c%3A/Users/Chris/proj/test-proj/main.go
  Code: 0 
[Trace - 11:01:04 PM] Sending request 'textDocument/hover - (7)'.
Params: {"textDocument":{"uri":"file:///c%3A/Users/Chris/proj/test-proj/main.go"},"position":{"line":5,"character":9}}


[Error - 11:01:04 PM] send textDocument/hover#7 no file information for file:///c%3A/Users/Chris/proj/test-proj/main.go


[Error - 11:01:04 PM] Request textDocument/hover failed.
  Message: no file information for file:///c%3A/Users/Chris/proj/test-proj/main.go
  Code: 0 
@gopherbot gopherbot added this to the Unreleased milestone Mar 21, 2019
@ALTree ALTree added gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Mar 21, 2019
@zippoxer
Copy link

zippoxer commented Mar 21, 2019

Can confirm the same on Windows 10, Visual Studio Code 1.32.3 and Go 1.12.1.

I have the following file under a directory gotest:

package main

import "fmt"

func main() {
	fmt.Println("hey")
}

And when I try anything that invokes gopls, it says "no file information for main.go" with code 0.

I tried placing the gotest directory under GOPATH as well as outside of it, and I get the same error.

I'm using the VSCode settings recommended in the wiki.

@stamblerre
Copy link
Contributor

Handling the filepath escaping on Windows has proven to be fairly confusing - I thought we got it right at some point, but looks like we didn't. I'll try to investigate when I have access to a Windows machine, which will be early next week.

@stamblerre stamblerre self-assigned this Mar 22, 2019
@ianthehat ianthehat added OS-Windows gopls Issues related to the Go language server, gopls. and removed gopls Issues related to the Go language server, gopls. labels Mar 22, 2019
@gopherbot
Copy link

Change https://golang.org/cl/169703 mentions this issue: internal/lsp: fix tiny bug in getting files by basename

@redxio
Copy link

redxio commented Apr 17, 2019

@stamblerre I have tried the latest gopls with go get -u, This issue still exists.

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

go version go1.12.4 windows/amd64

What version of VS Code are you using?

Version: 1.33.1 (user setup)
Commit: 51b0b28134d51361cf996d2f0a1c698247aeabd8
Date: 2019-04-11T08:27:14.102Z
Electron: 3.1.6
Chrome: 66.0.3359.181
Node.js: 10.2.0
V8: 6.6.346.32
OS: Windows_NT x64 10.0.17763

Does this issue reproduce with the latest gopls release?

yes

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

go env Output
$ go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\HBO-OFFICE-PC0\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=E:\go
set GOPROXY=
set GORACE=
set GOROOT=D:\Go
set GOTMPDIR=
set GOTOOLDIR=D:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\HBO-OF~1\AppData\Local\Temp\go-build052030434=/tmp/go-build -gno-record-gcc-switches

VS Code Settings related to gopls

"go.useLanguageServer": true,
    "go.alternateTools": {
        "go-langserver": "gopls"
    },
    "go.languageServerExperimentalFeatures": {
        "format": true,
        "autoComplete": true,
        "diagnostics": true,
        "goToDefinition": true,
        "hover": true,
        "signatureHelp": true,
        "goToTypeDefinition": true
    },
    "go.buildOnSave": "off",
    "go.vetOnSave": "off",
    "[go]": {
        "editor.snippetSuggestions": "none",
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
            "source.organizeImports": true
        },
    }

What did you do?

Tried to use gopls with VSCode on Windows

  1. Create a project directory outside GOPATH

  2. Create two files in the project directory containing:

main.go

package main

import (
	"fmt"
)

func main() {
	hello()
}

hello.go

package main

func hello() {
	fmt.Println("Hello, world!")
}
  1. Open two files in VS Code and hover the mouse over "Println", "hello" etc.

What did you expect to see?

gopls was working properly

What did you see instead?

here is go-langserver output:

[Error - 上午10:26:11] Request textDocument/codeAction failed.
  Message: no file information for file:///e:/MyGoProjects/HelloWorld/main.go
  Code: 0 
[Error - 上午10:26:12] Request textDocument/hover failed.
  Message: no file information for file:///e:/MyGoProjects/HelloWorld/main.go
  Code: 0 
[Error - 上午10:26:16] Request textDocument/hover failed.
  Message: no file information for file:///e:/MyGoProjects/HelloWorld/main.go
  Code: 0 
[Error - 上午10:26:19] Request textDocument/codeAction failed.
  Message: no file information for file:///e:/MyGoProjects/HelloWorld/hello.go
  Code: 0 
[Error - 上午10:26:19] Request textDocument/codeAction failed.
  Message: no file information for file:///e:/MyGoProjects/HelloWorld/hello.go
  Code: 0 
[Error - 上午10:26:19] Request textDocument/hover failed.
  Message: no file information for file:///e:/MyGoProjects/HelloWorld/hello.go
  Code: 0 

@stamblerre
Copy link
Contributor

@NzKSO: gopls will only work in either your $GOPATH or in module mode. If you don't have a go.mod file in the directory that is outside of your $GOPATH, it won't work.

@redxio
Copy link

redxio commented Apr 17, 2019

@stamblerre gopls still doesn't work even if I enable go module for projects that are outside $GOPATH, the go-langserver output is same as previous.

@Robula
Copy link

Robula commented Apr 18, 2019

Why is this closed? This is still happening, at least on macOS/VSCode using gopls

@stamblerre
Copy link
Contributor

@Robula: I'm not sure what you are referring to - the issue was about gopls not working on Windows. If you are having an issue on a Mac, please file a bug describing the error you see.

@divmgl
Copy link

divmgl commented Apr 30, 2019

Do we have a separate issue? gopls is not working whatsoever on macOS.

@stamblerre
Copy link
Contributor

@divmgl: do you mind opening a separate issue in the Go issue tracker so that I can help you diagnose your problem? gopls has definitely been working on MacOS.

@golang golang locked and limited conversation to collaborators Apr 29, 2020
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. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Projects
None yet
Development

No branches or pull requests

9 participants