-
Notifications
You must be signed in to change notification settings - Fork 17.5k
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
go/parser: invalid block comment end position with CRLF line endings #42646
Comments
What is the output of |
I had already upgraded the gopls extension by the time I saw your reply, so I'm afraid I don't know what version it was originally. Having run the None of these changes have fixed the original problem, VSCodeis still mangling the file sytax whenever a go file with a block comment is saved. I checked, and commenting out the same block with multiple "//" single line comment rather than the "/* */" block comments works ok, so it does seem to be the block comment syntax that is the issue. I also tried disabling the gopls "Use Language Server" setting. If I disable this in BOTH the Workspace and User settings, then saving works as expected, but if gopls is enabled in either setting the problem manifests. |
Thank you for following up--I was able to reproduce this with CRLF line endings. You can try changing your line endings (in the right bottom corner of the VS Code window) to LF to avoid this problem in the meantime ( |
This appears to be another instance of a go/parser bug with CRLF line endings. See the repro case here: https://play.golang.org/p/4Sb0-kywzTw. The parser reports that the comment ends 2 lines above its actual end. Related to #41197. /cc @findleyr |
I'm using a Windows machine for this development so it will be using CRLF line endings by default I expect. I will try changing to LF. I have been seeing other code-altering behaviours too, such as include statements (quite possibly erroneous ones as i'm new to Go coding) being deleted on save. Maybe there is a "correct by deleting" default behaviour in the auto-linter I'm not aware of. |
Change https://golang.org/cl/270879 mentions this issue: |
0.5.5 This is a patch release to fix two bugs in gopls/v0.5.4. Fixes Excessive reloading of packages outside of GOPATH or a module File corruption with CRLF line endings and //-style comments golang/go#42646 was supposed to have been fixed in gopls/v0.5.4, but it was not. golang/go#42923 was reported and fixed. 0.5.4 Features Opening a project that contains a module in a subdirectory Previously, gopls required that you open your editor exactly at or below the module root (the directory containing the go.mod). Now, you can open a directory that contains exactly one module in a subdirectory, and gopls will work as expected. For details on multi-module workspaces, see below. Removal of the granular go.mod upgrade codelenses Previously, we offered a code lens to suggest upgrades for each require in a go.mod file. In anticipation of changes that limit the amount that gopls accesses the network, we have decided to remove and reevaluate this feature. Users had mentioned that the code lenses cluttered their go.mod files, especially if they didn't actually want to upgrade. golang/go#38339 tracks the work to revamp this feature. An "Upgrade all dependencies" code lens should still appear at the top of your go.mod file. Improved error message reports Previously, critical error messages were reported as message pop-up that would re-trigger as you type. Many users would find this annoying. We have changed the approach to show error messages as progress reports, which should be less intrusive and appear more like status bars. Improved memory usage for workspaces with multiple folders We are now using a coarser cache key for package type information. If you use the gopls daemon, this may reduce your total memory usage. Experimental Multi-module workspace support The proposal described in golang/go#32394 is still in development and off by default. See our progress by tracking the multi-module workspace milestone and project. Enable multi-module workspace support by adding the following to your settings: "gopls": { "experimentalWorkspaceModule": true, } With this setting, you will be able to open a directory that contains multiple modules or a directory that contains nested modules. Give this a try if you're interested in this new feature, but please note that it is still very experimental. Please file issues if you encounter bugs. Fixes File corruption with CRLF line endings and /**/-style comments Previously, when you organized the imports in a file with CRLF line endings and multi-line comments, the formatter might output incorrect content for the file, rendering it invalid Go code. This issue has popped up a number of times, but we believe it has finally been fixed for good. If you are using Windows with CRLF line ending, please report any regressions. For full details, see golang/go#42646.
What version of Go, VS Code & VS Code Go extension are you using?
go: go1.15.4 windows/amd64
VSCode: 1.51.0
Extension: 0.18.1
Env:
Share the Go related settings you have added/edited
(Note: the above is strange, because in the extension settings UI the option "Go: Use Language Server" is NOT selected?? However toggling this setting does not change the behaviour of the bug)
Describe the bug
Starting with a go file that includes a section of code commented out as a block with /* and */, when I save the file VSCode alters the file before saving corrupting the code. This does not happen if the code does not contain the block comment.
Expected behaviour: Save the code as displayed
Steps to reproduce the behavior:
vscode_go_save_bug_before_saving.go.txt
vscode_go_save_bug_after_saving.go.txt
The text was updated successfully, but these errors were encountered: