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: off by one error in name function rename #39364

WBare opened this issue Jun 2, 2020 · 5 comments

x/tools/gopls: off by one error in name function rename #39364

WBare opened this issue Jun 2, 2020 · 5 comments


Copy link

@WBare WBare commented Jun 2, 2020

What version of Go, VS Code & VS Code Go extension are you using?

  • Run go version to get version of Go
    • go version go1.14.3 windows/amd64
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders
    • Version: 1.45.1 (system setup)
      Commit: 5763d909d5f12fe19f215cbfdd29a91c0fa9208a
      Date: 2020-05-14T08:27:35.169Z
      Electron: 7.2.4
      Chrome: 78.0.3904.130
      Node.js: 12.8.1
      OS: Windows_NT x64 10.0.18363
  • Check your installed extensions to get the version of the VS Code Go extension
    • 0.14.3

Describe the bug

When changing a function name which is preceded by a multiline /* */ style doc comment, the name change makes two mistakes.

  1. it moves the function name within the comment from the line immediately after the starting /* up one line and touching the starting /*
  2. it leaves the last character from the old name appended to the end of the new name.

Maybe it is somehow related to two char Windows end of line CR/LF.

Steps to reproduce the behavior:

Add this code to a .go file:

Test description
func Test() {

Now place your cursor in the function name Test() and press F2 to change the name. Type the new name Gronk. The result will be:

/*Gronkt description
func Gronk() {
Copy link

@hyangah hyangah commented Jun 2, 2020

@WBare Can you please share your go related settings? (those starting with go or [go] or gopls). We need it to figure out what tool is doing the renaming job.

If you are using the language server ("go.useLanguageServer": true), please follow the instruction in and share the gopls log. Thanks!

Copy link

@WBare WBare commented Jun 2, 2020

Ok. Here are the settings:

"files.autoSave": "afterDelay",
"": false,
"git.autofetch": true,
"git.enableSmartCommit": true,
"git.confirmSync": false,
"diffEditor.renderSideBySide": false,
"todo-tree.highlights.enabled": true,
"explorer.confirmDelete": false,
"python.jediEnabled": false,
"go.formatTool": "goimports",
"todo-tree.tree.showScanModeButton": false,
"terminal.integrated.scrollback": 5000,
"cSpell.userWords": [
"cSpell.dictionaryDefinitions": [

"go.useLanguageServer": true


And here is the View->Output -> gopls

[Info - 1:35:01 PM] 2020/06/02 13:35:01 Build info 0.4.1 h1:0e3BPxGV4B3cd0zdMuccwW72SgmHp92lAjOyxX/ScAw= h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ= h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY= h1:e7nYe9s94RHunFJ7b+mmPxiQMOKMVSqYASToWb1EcHs= h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= h1:sXmLre5bzIR6ypkjXCDI3jHPssRhc8KD/Ome589sc3U= h1:KaMb5GLhlcSX+e+qhbRJODnUUBvlw01jt4yrjFIHAuA=

Go info

go version go1.14.3 windows/amd64

[Info - 1:35:02 PM] 2020/06/02 13:35:02 go env for D:\GoDev\
(valid build configuration = true)
(build flags: [-modfile=C:\Users\WARREN2\AppData\Local\Temp\])
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Warren Bare\AppData\Local\go-build
set GOENV=C:\Users\Warren Bare\AppData\Roaming\go\env
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\Warren Bare\go
set GOPROXY=,direct
set GOROOT=c:\go
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set GOMOD=D:\GoDev\\go.mod
set CGO_CFLAGS=-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\WARREN~2\AppData\Local\Temp\go-build973149906=/tmp/go-build -gno-record-gcc-switches

[Info - 1:35:02 PM] 2020/06/02 13:35:02 go/packages.Load
query=[./... builtin]

[Info - 1:35:33 PM] 2020/06/02 13:35:33 background imports cache refresh starting

[Info - 1:35:33 PM] 2020/06/02 13:35:33 background refresh finished after 302.2648ms

Copy link

@stamblerre stamblerre commented Jun 2, 2020

Thank you! Looks like you're using gopls so I will transfer this to the gopls issue tracker.

@stamblerre stamblerre transferred this issue from golang/vscode-go Jun 2, 2020
@stamblerre stamblerre changed the title Off by one error in name function name change x/tools/gopls: off by one error in name function rename Jun 2, 2020
@gopherbot gopherbot added this to the Unreleased milestone Jun 2, 2020
@stamblerre stamblerre modified the milestones: Unreleased, gopls/v0.5.0 Jun 2, 2020
@golang golang deleted a comment from gopherbot Jul 2, 2020
Copy link

@stamblerre stamblerre commented Jul 2, 2020

Thanks for the report @WBare. You are right to say that this relates to Windows line endings. I'll take a look at this and see if it's fixable, but in the meantime, we do suggest always using Unix line endings, as gofmt always uses them.

Copy link

@gopherbot gopherbot commented Jul 2, 2020

Change mentions this issue: internal/lsp: fix rename with Windows line endings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants