Skip to content

x/tools/gopls: implement rangeFormatting LSP request #31150

Open
@myitcv

Description

@myitcv

What version of Go are you using (go version)?

$ go version
go version go1.12.4 linux/amd64
$ go list -m golang.org/x/tools
golang.org/x/tools v0.0.0-20190428024724-550556f78a90

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN="/home/myitcv/gostuff/src/github.com/myitcv/govim/.bin"
GOCACHE="/home/myitcv/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/myitcv/gostuff"
GOPROXY=""
GORACE=""
GOROOT="/home/myitcv/gos"
GOTMPDIR=""
GOTOOLDIR="/home/myitcv/gos/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/myitcv/gostuff/src/github.com/myitcv/govim/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-build120717318=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Considering the following govim testscript in which I attempt to range-format line numbers 3-5 (inc) in main.go:

vim ex 'e main.go'
vim ex '3,5GOVIMGoFmt'
vim ex 'noautocmd w'
cmp main.go main.go.golden

-- go.mod --
module mod

-- main.go --
package main

func main(){
fmt.Println("Hello, world")
}
-- main.go.golden --
package main

func main() {
	fmt.Println("Hello, world")
}

I get the error:

ToUTF16Column: point is missing offset

The params sent were:

&protocol.DocumentRangeFormattingParams{
    TextDocument: protocol.TextDocumentIdentifier{URI:"file://$WORK/main.go"},
    Range:        protocol.Range{
        Start: protocol.Position{Line:2, Character:0},
        End:   protocol.Position{Line:5, Character:0},
    },
    Options: protocol.FormattingOptions{},
}

What did you expect to see?

No error.

What did you see instead?

The above error.

cc @stamblerre @ianthehat

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.goplsIssues related to the Go language server, gopls.help wanted

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions