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
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:
Code-Review: +1 by Dmitri Shuralyov, +2 by Alan Donovan
TryBots-Pass: LUCI-TryBot-Result-1 by Go LUCI, TryBot-Bypass+1 by Alan Donovan