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: imports differs from goimports #41225

Closed
powerman opened this issue Sep 4, 2020 · 1 comment
Closed

x/tools/gopls: imports differs from goimports #41225

powerman opened this issue Sep 4, 2020 · 1 comment
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.

Comments

@powerman
Copy link

powerman commented Sep 4, 2020

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

$ go version
go version go1.15.1 linux/amd64
$ gopls version
golang.org/x/tools/gopls 0.4.4
    golang.org/x/tools/gopls@v0.4.4 h1:8djGYsaZ0ByP0vaXg4T+mnyfDcHpWKSZ+tpQSGv9ahk=

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
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/powerman/.cache/go-build"
GOENV="/home/powerman/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/powerman/go/pkg/mod"
GONOPROXY="github.com/dentalcpdpro,github.com/mtgroupit,gitlab.qarea.org"
GONOSUMDB="github.com/dentalcpdpro,github.com/mtgroupit,gitlab.qarea.org"
GOOS="linux"
GOPATH="/home/powerman/go"
GOPRIVATE="github.com/dentalcpdpro,github.com/mtgroupit,gitlab.qarea.org"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="x86_64-pc-linux-gnu-gcc"
CXX="x86_64-pc-linux-gnu-g++"
CGO_ENABLED="1"
GOMOD="/home/powerman/tmp/go/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-build538437635=/tmp/go-build -gno-record-gcc-switches"

What did you do?

$ cat fmt.go 
package main
func F(*testing.T, time.Time) {}
$ gopls imports fmt.go 
package main

import (
	"testing"
	"time"
)
func F(*testing.T, time.Time) {}
$ goimports fmt.go 
package main

import (
	"testing"
	"time"
)

func F(*testing.T, time.Time) {}

What did you expect to see?

Same output as produced by goimports (empty lines around import() block).

What did you see instead?

Empty line only before but not after import() block.

Related: fatih/vim-go#2993

@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 Sep 4, 2020
@gopherbot gopherbot added this to the Unreleased milestone Sep 4, 2020
@stamblerre stamblerre modified the milestones: Unreleased, gopls/v1.0.0 Sep 4, 2020
@stamblerre stamblerre added the NeedsFix The path to resolution is known, but the work has not been done. label Sep 17, 2020
@stamblerre
Copy link
Contributor

stamblerre commented Oct 13, 2020

The gopls imports logic is a bit different from goimports--it specifically separates import organization from formatting, whereas goimports also runs gofmt. To get the same experience on the command-line, you would need to run both gopls imports and gopls format. I would still recommend using goimports on the command line, as the gopls CLI is meant more to replicate individual requests.

We might consider a gopls command to do both importing and formatting, if you're interested in making a contribution.

@stamblerre stamblerre removed this from the gopls/v1.0.0 milestone Oct 13, 2020
@golang golang locked and limited conversation to collaborators Oct 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants