gopls/completion: prepend space when completing right after "//" before a declaration#630
Open
abhay1999 wants to merge 1 commit intogolang:masterfrom
Open
Conversation
…re a declaration When a user places the cursor immediately after "//" (with no trailing space) on a line directly above a declaration, gopls already suggests the declaration name as a completion candidate. However the suggested insert 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 that asserts the candidate appears when the cursor is right after "//", above a function declaration. Fixes golang/go#76374
Contributor
|
This PR (HEAD: 254d6e0) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/tools/+/762540. Important tips:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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