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: no folding ranges for invalid code #41281

Open
nicholasimon opened this issue Sep 7, 2020 · 13 comments
Open

x/tools/gopls: no folding ranges for invalid code #41281

nicholasimon opened this issue Sep 7, 2020 · 13 comments
Labels

Comments

@nicholasimon
Copy link

@nicholasimon nicholasimon commented Sep 7, 2020

Not sure why this has happened however out of the blue Visual Studio Code is now unfolding all code every time the file is saved. I have tried uninstalling/reinstalling and removing extensions though nothing has worked.

All code is unfolded every single time the file is saved and results in a lot of lost time. I reported the issue in the Visual Studio Issue for Bugs and was told that the issue is with the Go Extension itself. Basically it appears that the Go Extension for VSCode is causing the code to unfold every time the code is saved. See what was said in the VSCode issues report below

I can reproduce.

From debugging I see that the go extension now also registers a folding range provider.
However that provider doesn't work well with incomplete code. It then returns no folding ranges, what results in all folded ranges to go way.
E.g. no ranges returned for that code:

package main
w
import (
"fmt"
"io"
"net/http"

"github.com/microsoft/vscode-remote-try-go/hello"
)

func handle(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, hello.Hello())
}
Can you file the issue against the go extension? https://github.com/golang/vscode-go
Thanks a lot!

Please direct general questions to:

Please review the documentation before filing an issue.
Helpful pages include:

Please answer these questions before submitting your issue. Thanks!

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

  • Run go version to get version of Go
    go version go1.15.1 windows/amd64
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders
    1.48.2
    a0479759d6e9ea56afa657e454193f72aef85bd0
    x64
  • Check your installed extensions to get the version of the VS Code Go extension
    Go 0.16.2
  • Run go env to get the go development environment details
    set GO111MODULE=
    set GOARCH=amd64
    set GOBIN=
    set GOCACHE=C:\Users\nicholasimon\AppData\Local\go-build
    set GOENV=C:\Users\nicholasimon\AppData\Roaming\go\env
    set GOEXE=.exe
    set GOFLAGS=
    set GOHOSTARCH=amd64
    set GOHOSTOS=windows
    set GOINSECURE=
    set GOMODCACHE=C:\Users\nicholasimon\go\pkg\mod
    set GONOPROXY=
    set GONOSUMDB=
    set GOOS=windows
    set GOPATH=C:\Users\nicholasimon\go
    set GOPRIVATE=
    set GOPROXY=https://proxy.golang.org,direct
    set GOROOT=c:\go
    set GOSUMDB=sum.golang.org
    set GOTMPDIR=
    set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
    set GCCGO=gccgo
    set AR=ar
    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\NICHOL~1\AppData\Local\Temp\go-build025678214=/tmp/go-build -gno-record-gcc-switches

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file.
None

Describe the bug

Not sure why this has happened however out of the blue Visual Studio Code is now unfolding all code every time the file is saved. I have tried uninstalling/reinstalling and removing extensions though nothing has worked.

All code is unfolded every single time the file is saved and results in a lot of lost time. I reported the issue in the Visual Studio Issue for Bugs and was told that the issue is with the Go Extensions itself. Basically it appears that the Go Extension for VSCode is causing the code to unfold every time the code is saved. See what was said in the VSCode issues report below

Steps to reproduce the behavior:

Save a folded file, all fold unfold

@hyangah
Copy link
Contributor

@hyangah hyangah commented Sep 8, 2020

@nicholasimon thanks for the issue report. Analyzing incomplete code is tricky. For now, you may try to turn off the autosave option. (e.g "files.autoSave": "off").

@stamblerre I could easily reproduce bothwith the old provider and with the new LSP based provider. Since we are moving towards the LSP-based solution, I want us to focus on the new way ("go.useLanguageServer": true). The LSP spec does not explicitly specify the behavior around incomplete code handling.

  • Is it possible for gopls to preserve some folding ranges when folding range requests came in as results of edit activities with auto save on?
  • Strangely "files.autoSave": "off" trick does not fix this issue when the language server is enabled "go.useLanguageServer":true. Do you know any other way to prevent folding range requests?

EDIT: Just realized we never had any folding range provider without LSP. (see golang/vscode-go#134)
So, this is the gopls (or the LSP client) issue.
I confirmed the problem does not exist with the default folding range provider implemented inside vscode

@nicholasimon
Copy link
Author

@nicholasimon nicholasimon commented Sep 8, 2020

Thanks for letting me know however turning off autosave does nothing. What happens is when I save manually, it unfolds everything below the area of code that I am working on (see image). So everything above remains folded and then everything below is unfolded.

Anyway, just wanted to bring it to your attention, it would be great if it could be fixed in future as it is very, very annoying though I do understand these things take time

Annotation 2020-09-08 162524

@hyangah
Copy link
Contributor

@hyangah hyangah commented Sep 8, 2020

@nicholasimon Thanks! Do me a favor - can you please double check if you have the language server running? When you run "View: Toggle Output", if you see "gopls (server)" channel from the drop down menu, the language server is running.

@nicholasimon
Copy link
Author

@nicholasimon nicholasimon commented Sep 8, 2020

Not at my desk will be back just now and check for you

@nicholasimon
Copy link
Author

@nicholasimon nicholasimon commented Sep 8, 2020

I am not understanding exactly what I need to do.

I ran View: Toggle Output which I did then I navigated to VIEW > OPEN VIEW and you can see the drop down there in the image. Don't think this is what you meant? Sorry if you can just explain what drop down menu when you say "channel from the drop down menu, "

Let me know if this is correct or I should do something else

Annotation 2020-09-08 175941

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Sep 8, 2020

You need to do View -> Output, and then you'll see a drop-down that looks like this on the right-hand side. You're looking for an item that says "gopls (server)".

Screen Shot 2020-09-08 at 12 09 20 PM

Screen Shot 2020-09-08 at 12 08 37 PM

@nicholasimon
Copy link
Author

@nicholasimon nicholasimon commented Sep 8, 2020

Are you on Windows? It is not the same I think, you need to Click VIEW in top menu then OPEN VIEW I found a very similar list and it does not appear that gopls is present in the list

Annotation 2020-09-08 185523
2

@nicholasimon
Copy link
Author

@nicholasimon nicholasimon commented Sep 8, 2020

What exactly is gopls? Am I supposed to have installed this as well? I just installed the Go Extension from VSCode marketplace nothing else. Would it be fixed by installing gopls?

@hyangah
Copy link
Contributor

@hyangah hyangah commented Sep 8, 2020

@nicholasimon `View: Toggle Output" will open "OUTPUT" section at the bottom part of the window, like the following. Then, use the drop down on the pane to find gopls (server). This screenshot was taken from my windows machine.

Screen Shot 2020-09-08 at 1 37 11 PM

If gopls doesn't appear in the list, sorry that I cannot reproduce your issue.
And, our extension does not seem to implement the folding range provider (the implementation is inside the vscode
https://github.com/microsoft/vscode/blob/master/extensions/go/language-configuration.json) at all.

Would it be fixed by installing gopls?

No - see my comment (https://github.com/golang/vscode-go/issues/617#issuecomment-688890175). I could reproduce the exact behavior only when gopls is enabled.

Gopls is the language server this extension launches to provide the intellisense and all the language analysis services. See doc for more info. It is currently opt-in and you don't need to enable it now if you are currently happy without it.

@nicholasimon
Copy link
Author

@nicholasimon nicholasimon commented Sep 8, 2020

Okay there is a screenshot of my Output, I do not see gopls on the list anyway I have read the doc and am going to install it as well as switch from Go Extension to Go Nightly and see if the issue persists.

Annotation 2020-09-08 200739

@nicholasimon
Copy link
Author

@nicholasimon nicholasimon commented Sep 8, 2020

For some reason after installing gopls it is now working perfectly, as it should. Have tested with Go Extension as well as Go Nightly and it works fine. Retains my folding on save as it should, the error therefore must relate something to not having gopls installed or not.

It is now much better, thanks for the help it is appreciated.

@hyangah
Copy link
Contributor

@hyangah hyangah commented Sep 8, 2020

@nicholasimon thanks for trying gopls. Honestly I am now more confused because this problem happens to me only if I use gopls. :-(

@stamblerre if it works with gopls, please feel free to close this issue - maybe some misconfiguration on my side?.
If you observed what I saw, feel free to transfer to the gopls tracker.

@stamblerre stamblerre changed the title Go Extension causes Unfold All on Save x/tools/gopls: no folding ranges for invalid code Sep 9, 2020
@stamblerre stamblerre transferred this issue from golang/vscode-go Sep 9, 2020
@gopherbot gopherbot added this to the Unreleased milestone Sep 9, 2020
@stamblerre stamblerre removed this from the Unreleased milestone Sep 9, 2020
@nicholasimon
Copy link
Author

@nicholasimon nicholasimon commented Sep 9, 2020

That doesn't make sense at all as I had never heard of gopls before you told me so it can't be because of gopls as I have never used or it installed it before. Anyway it is up to you is you want to close the issue. Once again thanks for the help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.