Skip to content

x/tools/gopls: organizeImports affects cmd/go/... imports #81966

Open

Description

@thatnealpatel

https://go.dev/cl/840685 has at least 4 comments about
import reorganization and while I am fully to blame
for putting organizeImports on my :w in a central
config that the 4 machines I am authoring security
patches share, this should either be considered a bug
in gopls or a new opinion we accept in our source files.

I have no opinion.

cc @prattmic @FiloSottile @adonovan

Activity

  1. added
    goplsIssues related to the Go language server, gopls.
    BugReportIssues describing a possible bug in the Go implementation.
    on Oct 2, 2026
  2. added
    ToolsThis label describes issues relating to any tools in the x/tools repository.
    on Oct 2, 2026
  3. added this to the Unreleased milestone on Oct 2, 2026
  4. adonovan commented on Oct 2, 2026

    @adonovan
    Member

    We encourage users to run organizeImports on save. We know how it ought to work, and we fix bugs when it doesn't.

    What sequence of steps led to the unwanted behavior?

  5. self-assigned this
    on Oct 2, 2026
  6. seankhliao commented on Oct 2, 2026

    @seankhliao
    Member

    cmd/go is already somewhat inconsistent in whether cmd/ imports are grouped with std.
    as a random example, these two files in the same package have different formattings:

    https://go.googlesource.com/go/+/refs/heads/master/src/cmd/go/internal/work/action.go
    https://go.googlesource.com/go/+/refs/heads/master/src/cmd/go/internal/work/cover.go

    I think we need to commit to a particular style and make a mechanical format commit to align the files.

    I have a mild preference for separating cmd/ from std/ imports (I think this is equivalent to passing goimports -local cmd/).

    cc @golang/go-command

  7. seankhliao commented on Oct 2, 2026

    @seankhliao
    Member

    e.g. this is what it looks like running goimports -local cmd -w . for cmd/go (ignoring all the other cmd/ packages for now):
    https://go-review.googlesource.com/c/go/+/843865

    note all the files it didn't change, and some files with mixed import grouping.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugReportIssues describing a possible bug in the Go implementation.ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions