[tools] gopls: implement simplified CLI flag parsing and dispatching

3 views
Skip to first unread message

Hyang-Ah Hana Kim (Gerrit)

unread,
Jun 26, 2026, 12:02:09 PM (5 days ago) Jun 26
to Hyang-Ah Hana Kim, goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, golang-co...@googlegroups.com
Attention needed from Hyang-Ah Hana Kim

Message from Hyang-Ah Hana Kim

Set Ready For Review

Open in Gerrit

Related details

Attention is currently required from:
  • Hyang-Ah Hana Kim
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: Iad8685503dc48ba41b851cb4e3aea172b305a5b9
Gerrit-Change-Number: 794462
Gerrit-PatchSet: 3
Gerrit-Owner: Hyang-Ah Hana Kim <hya...@gmail.com>
Gerrit-Reviewer: Hyang-Ah Hana Kim <hya...@gmail.com>
Gerrit-Attention: Hyang-Ah Hana Kim <hya...@gmail.com>
Gerrit-Comment-Date: Fri, 26 Jun 2026 16:02:04 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
unsatisfied_requirement
satisfied_requirement
open
diffy

Hyang-Ah Hana Kim (Gerrit)

unread,
Jun 26, 2026, 12:11:19 PM (5 days ago) Jun 26
to Hyang-Ah Hana Kim, goph...@pubsubhelper.golang.org, Alan Donovan, Alex Putman, golang...@luci-project-accounts.iam.gserviceaccount.com, golang-co...@googlegroups.com
Attention needed from Alan Donovan and Alex Putman

Hyang-Ah Hana Kim voted and added 2 comments

Votes added by Hyang-Ah Hana Kim

Commit-Queue+1

2 comments

File gopls/internal/cmd/normalize.go
Line 1, Patchset 3 (Latest):// Copyright 2026 The Go Authors. All rights reserved.
Hyang-Ah Hana Kim . unresolved

Patchset 1 is more or less https://go-review.git.corp.google.com/c/tools/+/794081/2/gopls/internal/cmd/normalize.go

but with some modification to accept cases like `gopls -otel=... serve`.

Line 29, Patchset 3 (Latest): // TODO(adonovan): FlagSet.Parse should do
Hyang-Ah Hana Kim . unresolved

I was trying to address this in CL 794760, but that's unsatisfactory.

The tricky part of using the complete subprocess-based testing to replace TestDispatch is, some subcommands like `gopls serve` or `gopls mcp` are
meant not to exit when successful. We can consider the gopls integration test framework like approach for serve/mcp, but that feels very heavy weight.

Open in Gerrit

Related details

Attention is currently required from:
  • Alan Donovan
  • Alex Putman
Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: tools
    Gerrit-Branch: master
    Gerrit-Change-Id: Iad8685503dc48ba41b851cb4e3aea172b305a5b9
    Gerrit-Change-Number: 794462
    Gerrit-PatchSet: 3
    Gerrit-Owner: Hyang-Ah Hana Kim <hya...@gmail.com>
    Gerrit-Reviewer: Alan Donovan <adon...@google.com>
    Gerrit-Reviewer: Alex Putman <apu...@golang.org>
    Gerrit-Attention: Alex Putman <apu...@golang.org>
    Gerrit-Attention: Alan Donovan <adon...@google.com>
    Gerrit-Comment-Date: Fri, 26 Jun 2026 16:11:15 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy

    Alan Donovan (Gerrit)

    unread,
    Jun 26, 2026, 12:51:37 PM (4 days ago) Jun 26
    to Hyang-Ah Hana Kim, goph...@pubsubhelper.golang.org, Alex Putman, golang...@luci-project-accounts.iam.gserviceaccount.com, golang-co...@googlegroups.com
    Attention needed from Alex Putman and Hyang-Ah Hana Kim

    Alan Donovan added 5 comments

    File gopls/internal/cmd/info.go
    Line 65, Patchset 3 (Latest): // Directly print help for the resolved command.
    Alan Donovan . unresolved

    This is so much cleaner! Very nice.
    Are we overlooking anything that the recursive tool.Run call did for us?

    File gopls/internal/cmd/integration_test.go
    Line 1128, Patchset 3 (Latest):
    func TestHelp(t *testing.T) {
    t.Parallel()

    tree := writeTree(t, ``)
    res := gopls(t, tree, "help", "remote")
    res.checkExit(true)
    res.checkStderr("interact with the gopls daemon")
    }
    Alan Donovan . unresolved

    You can delete this; TestHelpTree does this and more.

    File gopls/internal/cmd/normalize.go
    Line 63, Patchset 3 (Latest):
    Alan Donovan . unresolved

    If we move the tool package into cmd (in another CL), then all the Profile stuff in RunWithProfile can move right here. I think it will make things considerably simpler.

    Line 164, Patchset 3 (Latest): if i == len(args) {
    Alan Donovan . unresolved

    One alternative that we could evaluate is make dispatch not call parse at all, but merely shuffle the arguments into the normalized order (e.g. `gopls -listen=... -otel=...` -> `gopls -otel=... serve -listen=...`) so that the caller can then proceed to call appFlags.Parse exactly once and cmdFlags.Parse exactly once.

    Given that you named this file normalize, I'm guessing you started out with this idea but hit a snag?

    Line 195, Patchset 3 (Latest): if strings.HasPrefix(arg, "-") && arg != "-" && arg != "--" {
    Alan Donovan . unresolved

    I don't think this is precise: you need to know which flags are boolean (see L143 et seq) to parse correctly, and you also need to know when to stop. Hence my ugly logic with two maps in https://go-review.git.corp.google.com/c/tools/+/794081/2/gopls/internal/cmd/normalize.go.

    Otherwise both of these (admittedly hypothetical cases today) would trigger spurious errors about `-v` being after `serve`:

    • `gopls serve -unary -v` (intending `--unary=-v`)
    • `gopls serve -boolflag -unaryflag=value subcommand -v` (intending that the -v flag is intended for the `subcommand` of `serve`, not `serve` itself).
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Alex Putman
    • Hyang-Ah Hana Kim
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: tools
    Gerrit-Branch: master
    Gerrit-Change-Id: Iad8685503dc48ba41b851cb4e3aea172b305a5b9
    Gerrit-Change-Number: 794462
    Gerrit-PatchSet: 3
    Gerrit-Owner: Hyang-Ah Hana Kim <hya...@gmail.com>
    Gerrit-Reviewer: Alan Donovan <adon...@google.com>
    Gerrit-Reviewer: Alex Putman <apu...@golang.org>
    Gerrit-Reviewer: Hyang-Ah Hana Kim <hya...@gmail.com>
    Gerrit-Attention: Alex Putman <apu...@golang.org>
    Gerrit-Attention: Hyang-Ah Hana Kim <hya...@gmail.com>
    Gerrit-Comment-Date: Fri, 26 Jun 2026 16:51:33 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy

    Hyang-Ah Hana Kim (Gerrit)

    unread,
    Jun 30, 2026, 9:45:54 AM (14 hours ago) Jun 30
    to Hyang-Ah Hana Kim, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
    Attention needed from Alex Putman and Hyang-Ah Hana Kim

    Hyang-Ah Hana Kim uploaded new patchset

    Hyang-Ah Hana Kim uploaded patch set #4 to this change.
    Following approvals got outdated and were removed:
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Alex Putman
    • Hyang-Ah Hana Kim
    Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: newpatchset
      Gerrit-Project: tools
      Gerrit-Branch: master
      Gerrit-Change-Id: Iad8685503dc48ba41b851cb4e3aea172b305a5b9
      Gerrit-Change-Number: 794462
      Gerrit-PatchSet: 4
      unsatisfied_requirement
      open
      diffy

      Hyang-Ah Hana Kim (Gerrit)

      unread,
      Jun 30, 2026, 5:13:20 PM (7 hours ago) Jun 30
      to Hyang-Ah Hana Kim, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
      Attention needed from Alex Putman and Hyang-Ah Hana Kim

      Hyang-Ah Hana Kim uploaded new patchset

      Hyang-Ah Hana Kim uploaded patch set #5 to this change.
      Following approvals got outdated and were removed:
      Open in Gerrit

      Related details

      Attention is currently required from:
      • Alex Putman
      • Hyang-Ah Hana Kim
      Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: newpatchset
      Gerrit-Project: tools
      Gerrit-Branch: master
      Gerrit-Change-Id: Iad8685503dc48ba41b851cb4e3aea172b305a5b9
      Gerrit-Change-Number: 794462
      Gerrit-PatchSet: 5
      unsatisfied_requirement
      open
      diffy
      Reply all
      Reply to author
      Forward
      0 new messages