[tools] gopls/completion: prepend space when completing right after "//" before a declaration

0 views
Skip to first unread message

Gopher Robot (Gerrit)

unread,
Apr 9, 2026, 11:15:45 PM (4 hours ago) Apr 9
to Abhay Chaurasiya, Gerrit Bot, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Dmitri Shuralyov, Dmitri Shuralyov, Alan Donovan, Go LUCI, Hongxiang Jiang, golang-co...@googlegroups.com

Gopher Robot submitted the change

Change information

Commit message:
gopls/completion: prepend space when completing right after "//" before a declaration

When a user places the cursor immediately after "//" (no space) on a
line directly above a declaration, gopls already suggests the
declaration name as a completion candidate. However the inserted text
lacked the conventional space, producing "//Name" instead of the
proper Go doc comment form "// Name".

Detect this case in populateCommentCompletions (cursor at slash+2
with comment text exactly "//") and set a new
commentNeedsLeadingSpace flag on the completionContext. item() checks
the flag and prepends a space to the insert text (and snippet), so
accepting the completion yields "// Name".

A marker test is added to comment.txt asserting that a function name
is offered when the cursor is right after "//" directly above its
declaration. All existing completion marker tests continue to pass.

Fixes golang/go#76374
Change-Id: Ibc91170861ad8a142b5cc9bb85d57313d92929b8
GitHub-Last-Rev: 19eb9ed9ba82532d08c90f92b0c5e5e3c8262a03
GitHub-Pull-Request: golang/tools#630
TryBot-Bypass: Alan Donovan <adon...@google.com>
Reviewed-by: Dmitri Shuralyov <dmit...@google.com>
Reviewed-by: Alan Donovan <adon...@google.com>
Auto-Submit: Alan Donovan <adon...@google.com>
Files:
  • M gopls/internal/golang/completion/completion.go
  • M gopls/internal/golang/completion/format.go
  • M gopls/internal/test/marker/testdata/completion/comment.txt
Change size: S
Delta: 3 files changed, 37 insertions(+), 0 deletions(-)
Branch: refs/heads/master
Submit Requirements:
  • requirement satisfiedCode-Review: +1 by Dmitri Shuralyov, +2 by Alan Donovan
  • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result-1 by Go LUCI, TryBot-Bypass+1 by Alan Donovan
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: Ibc91170861ad8a142b5cc9bb85d57313d92929b8
Gerrit-Change-Number: 762540
Gerrit-PatchSet: 3
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Dmitri Shuralyov <dmit...@google.com>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-CC: Abhay Chaurasiya <abhaycha...@gmail.com>
Gerrit-CC: Dmitri Shuralyov <dmit...@golang.org>
Gerrit-CC: Hongxiang Jiang <hxj...@golang.org>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages