Fix #288: preserve $1 snippet placeholder when cursor is at end of a … - #1319
Open
jwrhw7tueydwtt7575g wants to merge 2 commits into
Open
Fix #288: preserve $1 snippet placeholder when cursor is at end of a …#1319jwrhw7tueydwtt7575g wants to merge 2 commits into
jwrhw7tueydwtt7575g wants to merge 2 commits into
Conversation
… is at end of a non-empty line followed by a newline The completion collector in yamlCompletion.ts stripped a trailing $1 from completionItem.insertText unconditionally. This was correct when there was non-newline content after the cursor that the inserted text needed to coexist with, but wrong when the cursor sat at the end of a line that ended with a newline. In the latter case the snippet placeholder is the editor's signal for caret placement and must be preserved. For example, with content '- \n' and the caret at the end of '- ', the service returned 'prop1: ' instead of 'prop1: $1'. This regressed behavior recorded in PR redhat-developer#280 and the test removed in commit 73567b2. The strip is now skipped when the cursor is at the end of a line that has both a trailing newline AND non-whitespace content before the cursor (e.g. the sequence marker '- '). For content '- ' (no newline) the strip is still applied; for content ' ' (whitespace-only line) the strip is still applied; for empty lines the strip is still applied. The PR redhat-developer#280 workaround (overwriteRange.start.line === overwriteRange.end.line) is left in place - it guards against a separate class of malformed multi-line textEdits unrelated to this bug. A regression test 'Check text edit when there is a newline' is added to test/autoCompletion.test.ts that asserts all three completion items from testArrayMaxProperties.json preserve $1 for content '- \n' at the end of '- '. It mirrors the assertions from the test removed in 73567b2. Co-Authored-By: Claude <noreply@anthropic.com>
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.
What does this PR do?
Fixes an issue in the completion collector (
yamlCompletion.ts) where a trailing$1snippet placeholder was unconditionally stripped fromcompletionItem.insertText.This stripping was correct when non-newline content after the cursor needed to
coexist with the inserted text, but incorrect when the cursor sat at the end of
a line that ended with a newline — in that case the
$1placeholder is theeditor's signal for caret placement and must be preserved.
For example, with content
'- \n'and the caret at the end of'- ', theservice returned
'prop1: 'instead of'prop1: $1'.The fix skips the strip when the cursor is at the end of a line that has both
a trailing newline and non-whitespace content before the cursor (e.g. the
sequence marker
'- '). The strip is still applied for:'-'(no newline)The existing PR #280 workaround
(
overwriteRange.start.line === overwriteRange.end.line) is left in place, asit guards against a separate class of malformed multi-line textEdits unrelated
to this bug.
What issues does this PR fix or reference?
Fixes #288
References #280 (regression introduced by this PR)
References commit
73567b2(removed the test that should have caught this)Is it tested? How?
Yes. A regression test, "Check text edit when there is a newline", was
added to
test/autoCompletion.test.ts. It asserts that all three completionitems from
testArrayMaxProperties.jsonpreserve$1for content'- \n'atthe end of
'- '. This mirrors the assertions from the test that was removedin commit
73567b2.