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

Invalid var block formatting when g:go_gopls_gofumpt enabled #3231

Closed
moorereason opened this issue May 20, 2021 · 1 comment · Fixed by #3232
Closed

Invalid var block formatting when g:go_gopls_gofumpt enabled #3231

moorereason opened this issue May 20, 2021 · 1 comment · Fixed by #3232
Labels
Milestone

Comments

@moorereason
Copy link
Contributor

What did you do?

With g:go_gopls_gofumpt = 1, save the following file:

package main

var (
        // foo
        b = 2
)

func main() {}

What did you expect to happen?

Expected the formatting of the var block to be reformatted as:

// foo
var b = 2

What happened instead?

Creates a syntactically invalid file:

package main

var (// foo
var b = 2

func main() {}

I'm unable to reproduce the issue with the gofumpt binary (see mvdan/gofumpt#119). This only appears to happen in vim-go with g:go_gopls_gofumpt enabled.

Configuration

vim-go version:

Occurs with v1.25 and HEAD (currently 8c883d7)

vimrc you used to reproduce:

vimrc
call plug#begin('~/.vim/plugged')
Plug 'fatih/vim-go'
call plug#end()

let g:go_gopls_gofumpt = 1

Vim version (first three lines from :version):

NVIM v0.4.4
Build type: Release
LuaJIT 2.0.5

Go version (go version):

go version go1.16.3 linux/amd64

Go environment

go env Output:
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/XXX/.cache/go-build"
GOENV="/home/XXX/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/XXX/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/XXX"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/XXX/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/XXX/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.3"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/XXX/src/mvdan.cc/gofumpt/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build546098438=/tmp/go-build -gno-record-gcc-switches"

gopls version

gopls version Output:
golang.org/x/tools/gopls v0.6.11
    golang.org/x/tools/[email protected] h1:7S2k0xuVYc3secjy2uz0n+fGYxGJU6gXsLOmQ/r1HoI=

vim-go configuration:

vim-go configuration
g:go_loaded_install = 1
g:go_gopls_gofumpt = 1
g:go_jump_to_error = 1
g:go_loaded_gosnippets = 1

filetype detection configuration:

filetype detection
filetype detection:ON  plugin:ON  indent:ON
bhcleek added a commit to bhcleek/vim-go that referenced this issue May 20, 2021
Fix applyTextEdits to correctly calculate the prefix of the replacement
text.

Fixes fatih#3231
@bhcleek bhcleek added this to the vim-go 1.26 milestone May 20, 2021
@bhcleek bhcleek added the bug label May 20, 2021
@bhcleek
Copy link
Collaborator

bhcleek commented May 20, 2021

Thank you for the good report. I'll merge the fix tonight.

bhcleek added a commit that referenced this issue May 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants