internal/lsp: fix variable reuse bug in code actions

Taking the address of the variables defined by range in a for loop is not
safe since they are reused. Get the address from the original slice.

Change-Id: If7fbf3fdbfeeaf329f36e416642582002895bbce
Reviewed-on: https://go-review.googlesource.com/c/tools/+/330649
Trust: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
Suzy Mueller 2021-06-24 11:53:41 -04:00
parent d36a54b56b
commit ae0deb7a4c
1 changed files with 3 additions and 3 deletions

View File

@ -312,11 +312,11 @@ func extractionFixes(ctx context.Context, snapshot source.Snapshot, pkg source.P
commands = append(commands, cmd)
}
var actions []protocol.CodeAction
for _, cmd := range commands {
for i := range commands {
actions = append(actions, protocol.CodeAction{
Title: cmd.Title,
Title: commands[i].Title,
Kind: protocol.RefactorExtract,
Command: &cmd,
Command: &commands[i],
})
}
return actions, nil