fix: JSON resource type value completion formatted as key#520
Merged
kddejong merged 4 commits intoaws-cloudformation:mainfrom Apr 8, 2026
Merged
Conversation
00a1a8b to
ff3dd52
Compare
Zee2413
reviewed
Apr 6, 2026
Zee2413
reviewed
Apr 6, 2026
Zee2413
approved these changes
Apr 7, 2026
gemammercado
approved these changes
Apr 8, 2026
CompletionFormatter.formatForJson treated all completions as key insertions — wrapping in quotes with trailing colon and replacing from column 0. This broke resource type value completion in JSON (e.g. typing AWS::S3::B inside "Type": "") because: 1. newText was '"AWS::S3::Bucket":' (colon appended to value) 2. textEdit range started at column 0, wiping out the "Type" key 3. filterText was '"AWS::S3::Bu"' which editors couldn't match Fix: detect value completions via CompletionItemKind.Class (used exclusively for resource types) and replace only the quoted value token with the correct text. Also fixes debug_tree.ts crash on undefined cfnFileType. Adds e2e and unit tests for JSON resource type value completion.
Replace item.kind === CompletionItemKind.Class check with proper
syntax tree inspection. A node is a value completion when it is
the value child of a pair node in the JSON tree-sitter AST:
node.parent?.type === 'pair' && parent.childForFieldName('value') === node
This is more precise than checking item.kind since
TopLevelSectionCompletionProvider also uses CompletionItemKind.Class
for key completions.
Adds test for DeletionPolicy enum values in JSON templates. This was also affected by the value formatting bug.
Add isJsonPairValue() to Context that uses the tree-sitter pair node structure to reliably detect value positions in JSON. A node is a value when it is the value child of a pair node. This is consistent with how YAML key/value detection works in Context (using synthetic nodes) and avoids relying on item.kind or the unreliable propertyPath heuristic for JSON.
e36ea32 to
bf1faeb
Compare
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.
CompletionFormatter.formatForJson treated all completions as key insertions — wrapping in quotes with trailing colon and replacing from column 0. This broke resource type value completion in JSON (e.g. typing AWS::S3::B inside "Type": "") because:
Fix: detect value completions (nodeType=string, isValue && !isKey) and replace only the quoted value token with the correct text.
Also fixes debug_tree.ts crash on undefined cfnFileType.
Adds e2e and unit tests for JSON resource type value completion.
fixes #450
Issue #, if available:
Description of changes:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.