Repository: go
Issue: x/tools/gopls: no folding ranges for invalid code
Labels: help wanted,gopls,Tools

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:
- [`#vscode` channel in Gophers Slack](https://invite.slack.golangbridge.org/messages/vscode)

Please review the [documentation](https://github.com/golang/vscode-go/tree/master/docs) before filing an issue.
Helpful pages include:

- [GOPATH](https://github.com/golang/vscode-go/tree/master/docs/gopath.md)
- [Module Support](https://github.com/golang/vscode-go/tree/master/docs/modules.md)
- [Debugging](https://github.com/golang/vscode-go/tree/master/docs/debugging.md)
  - Set "trace": "log" and share the resulting logs in the debug console when logging an issue.

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