-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
Comments
@nicholasimon thanks for the issue report. Analyzing incomplete code is tricky. For now, you may try to turn off the autosave option. (e.g @stamblerre I could easily reproduce
EDIT: Just realized we never had any folding range provider without LSP. (see golang/vscode-go#134) |
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 |
@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. |
Not at my desk will be back just now and check for you |
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 |
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? |
@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. If
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. |
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. |
@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?. |
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. |
Change https://golang.org/cl/291569 mentions this issue: |
Change https://golang.org/cl/299569 mentions this issue: |
In the presence of parse errors, gopls may fail to compute foldingRanges correctly and return only partial results. Partial results can confuse editors and cause to drop still valid, previously known folding ranges information. Currently, LSP does not allow a way for the server to tell clients the server is not ready for answering to the request. VSCode foldingRange API allows registered foldingRange provider to opt out of the folding range computation by providing undefined. https://code.visualstudio.com/api/references/vscode-api#FoldingRangeProvider "Returns a list of folding ranges or null and undefined if the provider does not want to participate or was cancelled." But, LSP currently does not disginguish undefined/null and empty results. Raising an error may be an option, but some LSP clients may not handle errors in user-friendly ways. Thus gopls devs want to avoid raising errors here. With https://go-review.googlesource.com/c/tools/+/291569, gopls will return an empty foldingRange response when encountering parse errors instead of returning incomplete results. This CL adds provideFoldingRanges in the middleware, that converts an empty foldingRange response with 'undefined' if the document is not empty. Manually tested. Testing it in the integration test setup is currently tricky until gopls with the change is released. Updates #1224 Updates golang/go#41281 Change-Id: I32cfb30d7e6a9874b9d1cb6c7e5309f19ee081e5 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/299569 Trust: Hyang-Ah Hana Kim <hyangah@gmail.com> Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com> TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
When parse errors occur, go's parse package cannot recover nicely. gopls tried to compute folding ranges based on the partial info in this case, but returning partial folding range info confuses editors (vscode) and results in dropping previous folding range info from the region after the parse error location. This CL makes gopls not to return anything - so the editor can tell the result is not believable and ignore it. The ideal solution is to return a response explicitly surfacing this case, but currently LSP (3.16, as of today) does not have a way to describe this condition. See the discussion in microsoft/language-server-protocol#1200. We also tried to make gopls return an error. While it worked nicely in VSCode, we are not sure about how other editors handle errors from foldingRange. So, instead, we just let gopls return an empty result - since foldingRange is already broken in this case, we hope it doesn't add a lot of noise to existing users. VSCode Go will check the response from the middleware. If the response is empty but the file is not empty, VSCode Go will ignore the response. (https://go-review.googlesource.com/c/vscode-go/+/299569) Updates golang/vscode-go#1224 Updates golang/go#41281 Change-Id: I917d6667508aabbca1906137eb5e21a97a6cfdaf Reviewed-on: https://go-review.googlesource.com/c/tools/+/291569 Trust: Hyang-Ah Hana Kim <hyangah@gmail.com> Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Change https://golang.org/cl/300290 mentions this issue: |
@hyangah what's left to do here? Should we prioritize this? Thanks. |
Just to let you know this is not resolved. Folding works fine in VS Code with Go extension up to a few thousand lines (not sure of the exact point) however at a certain point it no longer works. I have worked out (since my original post) that this relates to SETTINGS > FORMAT ON SAVE > FILE (default). Something about having thousands of lines of Go then it breaks formatting of the entire file when saving and it unfolds everything. Currently the workaround I use is to set FORMAT ON SAVE to MODIFICATIONS then it does not try and format the entire file. Then you can change it to FILE (default) occasionally and it will format the file correctly. |
Thanks @nicholasimon -- I've put this back in our backlog. |
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
Please direct general questions to:
#vscode
channel in Gophers SlackPlease 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?
go version
to get version of Gogo version go1.15.1 windows/amd64
code -v
orcode-insiders -v
to get version of VS Code or VS Code Insiders1.48.2
a0479759d6e9ea56afa657e454193f72aef85bd0
x64
Go 0.16.2
go env
to get the go development environment detailsset 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
The text was updated successfully, but these errors were encountered: