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: source.fixAll codeaction corrupts source #45997

Open
hyangah opened this issue May 6, 2021 · 0 comments
Open

x/tools/gopls: source.fixAll codeaction corrupts source #45997

hyangah opened this issue May 6, 2021 · 0 comments
Labels
gopls/corruption Issues related to file corruption in gopls gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@hyangah
Copy link
Contributor

hyangah commented May 6, 2021

VSCode 1.55.2
VSCode Go 0.24.2
gopls 0.6.10 and 0.6.11-pre.1

settings.json:

    "[go]": {
        "editor.codeActionsOnSave": {
            "source.organizeImports": false,
            "source.fixAll": true
        },
    },

main.go:

package main

type astruct struct {
	A int
	B int
}

type bstruct struct {
	a astruct
}

type cstruct struct {
	pb *bstruct
	sa []*astruct
}

func main() {
	c1 := cstruct{&bstruct{astruct{1, 2}}, []*astruct{{1, 2}, &astruct{2, 3}, &astruct{4, 5}}}
	_ = c1
}

Trigger file save, and observe how the line c1 := ... that had multiple lint issues changed.

func main() {
	c1 := cstruct{&bstruct{astruct{1, 2}}, []*astruct{{1, 2}, {2, 3}, &astruct
	_ = c1
}

gopls trace (gopls v0.6.11-pre.1):

[Trace - 10:59:24.347 AM] Sending request 'textDocument/codeAction - (8)'.
Params: {"textDocument":{"uri":"file:///Users/hakim/demo/tools.go"},"range":{"start":{"line":0,"character":0},"end":{"line":20,"character":0}},"context":{"diagnostics":[{"range":{"start":{"line":18,"character":3},"end":{"line":18,"character":7}},"message":"expected '==', found '=' (compile)","severity":2,"source":"go-staticcheck"},{"range":{"start":{"line":19,"character":1},"end":{"line":19,"character":1}},"message":"missing ',' before newline in composite literal (compile)","severity":2,"source":"go-staticcheck"},{"range":{"start":{"line":17,"character":59},"end":{"line":17,"character":67}},"message":"redundant type from array, slice, or map composite literal","severity":2,"tags":[1],"source":"simplifycompositelit"},{"range":{"start":{"line":17,"character":75},"end":{"line":17,"character":83}},"message":"redundant type from array, slice, or map composite literal","severity":2,"tags":[1],"source":"simplifycompositelit"}],"only":["source.fixAll"]}}


[Trace - 10:59:24.348 AM] Received response 'textDocument/codeAction - (8)' in 0ms.
Result: [{"title":"Remove '\u0026astruct'","kind":"source.fixAll","diagnostics":[{"range":{"start":{"line":17,"character":59},"end":{"line":17,"character":67}},"severity":2,"source":"simplifycompositelit","message":"redundant type from array, slice, or map composite literal","tags":[1]}],"edit":{"documentChanges":[{"textDocument":{"version":35,"uri":"file:///Users/hakim/demo/tools.go"},"edits":[{"range":{"start":{"line":17,"character":59},"end":{"line":17,"character":67}},"newText":""}]}]}},{"title":"Remove '\u0026astruct'","kind":"source.fixAll","diagnostics":[{"range":{"start":{"line":17,"character":75},"end":{"line":17,"character":83}},"severity":2,"source":"simplifycompositelit","message":"redundant type from array, slice, or map composite literal","tags":[1]}],"edit":{"documentChanges":[{"textDocument":{"version":35,"uri":"file:///Users/hakim/demo/tools.go"},"edits":[{"range":{"start":{"line":17,"character":75},"end":{"line":17,"character":83}},"newText":""}]}]}}]


[Trace - 10:59:24.354 AM] Sending notification 'textDocument/didChange'.
Params: {"textDocument":{"uri":"file:///Users/hakim/demo/tools.go","version":36},"contentChanges":[{"range":{"start":{"line":17,"character":59},"end":{"line":17,"character":67}},"rangeLength":8,"text":""}]}


[Trace - 10:59:24.357 AM] Received notification 'textDocument/publishDiagnostics'.
Params: {"uri":"file:///Users/hakim/demo/tools.go","version":36,"diagnostics":[{"range":{"start":{"line":17,"character":67},"end":{"line":17,"character":75}},"severity":2,"source":"simplifycompositelit","message":"redundant type from array, slice, or map composite literal","tags":[1]}]}


[Trace - 10:59:24.358 AM] Sending notification 'textDocument/didChange'.
Params: {"textDocument":{"uri":"file:///Users/hakim/demo/tools.go","version":37},"contentChanges":[{"range":{"start":{"line":17,"character":75},"end":{"line":17,"character":83}},"rangeLength":8,"text":""}]}


[Trace - 10:59:24.358 AM] Sending request 'textDocument/formatting - (9)'.
Params: {"textDocument":{"uri":"file:///Users/hakim/demo/tools.go"},"options":{"tabSize":4,"insertSpaces":false}}


[Error - Received] 10:59:24.359 AM #9 18:76: missing ',' before newline in composite literal (and 2 more errors)


[Error - 10:59:24 AM] Request textDocument/formatting failed.
  Message: 18:76: missing ',' before newline in composite literal (and 2 more errors)
  Code: 0 
[Trace - 10:59:24.361 AM] Received notification 'textDocument/publishDiagnostics'.
Params: {"uri":"file:///Users/hakim/demo/tools.go","version":37,"diagnostics":[{"range":{"start":{"line":17,"character":75},"end":{"line":17,"character":75}},"severity":1,"source":"syntax","message":"missing ',' before newline in composite literal"}]}


[Trace - 10:59:24.406 AM] Sending notification 'textDocument/didSave'.
Params: {"textDocument":{"uri":"file:///Users/hakim/demo/tools.go"}}
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels May 6, 2021
@gopherbot gopherbot added this to the Unreleased milestone May 6, 2021
@stamblerre stamblerre added this to To Do in gopls on-deck Jul 15, 2021
@suzmue suzmue added the gopls/corruption Issues related to file corruption in gopls label May 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls/corruption Issues related to file corruption in gopls gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
No open projects
Development

No branches or pull requests

3 participants