-
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: new code disappears or is modified after formatting #34955
Comments
The issue ocurred with the gopls@(devel), and the normal v0.1.6 version. Also with the v0.1.7 version suggested by vscode-go. It's worth noting that the type of "code rewrite" is different with the
And after saving:
What I have to do to recover from this is to undo the 2 edits made by the formatter, and then execute "reload window". gopls version:
Vscode settings.json: {
"workbench.startupEditor": "newUntitledFile",
"extensions.ignoreRecommendations": true,
"tslint.jsEnable": true,
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.tslint": true
},
"typescript.updateImportsOnFileMove.enabled": "always",
"editor.detectIndentation": false,
"editor.insertSpaces": false,
"zenMode.hideTabs": false,
"editor.renderWhitespace": "boundary",
"workbench.iconTheme": "vscode-icons",
"bracketPairColorizer.showHorizontalScopeLine": false,
"bracketPairColorizer.showBracketsInRuler": true,
"vsicons.dontShowNewVersionMessage": true,
"explorer.confirmDragAndDrop": false,
"files.watcherExclude": {
"dist/**": true
},
"files.exclude": {
"**/dist/**": true
},
"search.exclude": {
"**/dist": true,
"**/docs": true
},
"workbench.colorTheme": "Monokai",
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe",
"git.path": "C:/Users/noflo/AppData/Local/Atlassian/SourceTree/git_local/bin/git.exe",
"editor.mouseWheelScrollSensitivity": 3,
"go.useLanguageServer": true,
"gopls": {
"go-diff": true
},
} Output of gopls window:
The output of gopls trace is on this gist: EDIT:
|
@jpvillaseca: Thank you for the detailed report! What is the output of |
Oh I'm sorry I see you've attached it. I will look into this more thoroughly ASAP. |
To get more detailed "go.languageServerFlags": [
"serve",
"-rpc.trace",
], to your VSCode settings. Based on the trace you attached, it seems like the file you were trying to format already had syntax errors and wasn't formatted. Can you try formatting a file that doesn't have any syntax errors? |
Thank you, @stamblerre . |
Ah I see - makes sense. Thank you for doing this - it will be very helpful to get this information! |
Ok. The verbose trace from within vscode is: And the output of the gopls trace command on the file without issues: (This is without |
Do you mind sharing the same but with |
Of course. Here are the traces with
After saving. It ate the comments and some words. I had to do 4 undos to get back to the working version, but it is already crippled on-disk.
Here is the trace from vscode: And this is the trace from gopls: (I reverted the file to the original version using notepad) I hope this helps =) EDIT: Another example with the same file, but now it started replacing the first columns of some lines:
Was crippled to:
|
Thank you so much for this report. Definitely very unexpected behavior. @ianthehat: Any ideas here? |
@jpvillaseca: Were you able to determine if this happens as a result formatting or organizing imports? That is, can you reproduce it by right-clicking and selecting |
It seems organize imports and format document are both culprit. I added an intentionally failing import, run the And also the same with The original last 17 lines from the file: // CheckForStalledJobs looks for any dangling jobs that didn't report progress on time
func CheckForStalledJobs() {
client := redispool.GetClient()
if client == nil {
return errors.New("Unable to get redis client")
}
// for each job in the in-progress list look for their entry in the inprogress list
inprogressJobs := jobs.LRange("inprogress-jobs", 0, -1)
// if not there, mark it as retry and move it to the queue or cancel it if it exceeds the retry threshold
}
// func DequeueJob() job *jc.Job {
// // Look for a
// } And after running either command: (it even ate the "b" from DequeueJob in the commented out section, or the "e" in "entry" in another comment, and some spacesand curly braces in between // CheckForStalledJobs looksfor any dangling jobs that didn't report progress on time
func CheckForStalledJobs() {
client := redispoo.GetClient()
if client == nil {
eturn errors.New("Unable to get redis client")
}
// for each job in the in-progress list look for their ntry in the inprogress list
/ if not there, mark it as retry and move it to the queue or cancel it if it exceeds the retry threshold
// func DequeueJo() job *jc.Job {
// / Look for a
// } |
Hello @stamblerre I know this issue is still marked open. But wanted to test the issue in the latest version of gopls 0.2.2. It still persists, the behavior remains the same. |
Can you try reproducing on the current master? |
I have the same problem: https://streamable.com/69fgs I would be happy to help with this issue. |
@dhcgn: Can you see if this reproduces for you at master? You can download |
@stamblerre the behavior changed, now I can save the file without it will be corrupted but without auto-format when saving a file. Auto-Succession was broken too. How can I get the gopls from master and keep the integration in vscode working? After I update the go tools the old behavior is back again:
|
Can you share your VS Code |
A number of users have reported that this has been resolved in |
Re-opening this issue, as it's been reported several times with |
Change https://golang.org/cl/218859 mentions this issue: |
I believe I've figured out the issue and have a fix for it. If affected users could try applying the patch before it is merged to confirm that it fixes the issue, that would be very helpful. Here are the steps to do so: $ git clone https://go.googlesource.com/tools
$ cd tools
$ git fetch "https://go.googlesource.com/tools" refs/changes/59/218859/3 && git cherry-pick FETCH_HEAD
$ cd gopls
$ go install |
The change is now merged, so |
Change https://golang.org/cl/219125 mentions this issue: |
We were previously only invalidating files if they were contained within a subdirectory of a view, but we should really be invalidating all files that are known to a view. Fixes golang/go#34955 Change-Id: I2eb1476e6b5f74a64dbb6d47459f4009648c720d Reviewed-on: https://go-review.googlesource.com/c/tools/+/218859 Run-TryBot: Rebecca Stambler <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> (cherry picked from commit e2a38c8) Reviewed-on: https://go-review.googlesource.com/c/tools/+/219125
I encountered the issue today with version v0.3.2-pre1. On save, it changed the imports from:
... to:
The logs are here.
Thanks for your help on this! |
Thank you for following up! As expected with this bug, we see a
Most notably, the file has a
@heschik has recently made some changes to our handling of URIs because of this exact issue. @galenwarren: Can you download |
I've installed the master version -- will see how it goes and report back. Thanks again. |
@stamblerre what I found that worked for me was to enable Go Modules. Without them, the issue appeared on any settings and version configuration, but with go modules, "go.useLanguageServer": true,
"go.languageServerExperimentalFeatures": {
"format": false,
"signatureHelp": true,
"workspaceSymbols": true,
},
"gopls": {
"usePlaceholders": true,
}, |
@jpvillaseca: Setting format to false may also mask the issue. I would expect that this issue should be fixed at master, however (unless there is a corner case we haven't yet encountered, which is very possible). |
Just wanted to let you that I've been using the master version for a few days now and all seems to be good! Any thoughts on when that version might be published? Thanks. |
Glad to hear it! I'll close this issue then. (Please re-open if something new comes up.) |
A number of VSCode issues have been raised regarding problems with formatting (see microsoft/vscode-go#2824, microsoft/vscode-go#2787). There are a few possibilities about what the source of this issue might be, but it is likely that either, (1) formatting is being run on old code, or (2) something is going wrong with the diff algorithm.
If you have this issue, please share the following information so that we can diagnose it:
Ctrl + Shift + P
->Preferences: Open Settings (JSON)
)gopls
version (gopls version
)gopls -rpc.trace -v format path/to/file.go
gopls
logs from when this issue occurs (see https://github.com/golang/tools/blob/master/gopls/doc/troubleshooting.md#capturing-logs for information on how to capture logs).Furthermore, we have recently substituted the
gopls
diff algorithm for a better alternative. It's possible that this was the culprit. If you are able to installgopls
at master:then you can try out this new diff algorithm. Try it by adding the following setting:
If any users test out
go-diff
, please do report if this changes anything.Finally, it will be helpful to determine if the issue is formatting or imports. Please try disabling the following settings one at a time and please report which alters the behavior.
The text was updated successfully, but these errors were encountered: