Skip to content

fix: JSON resource type value completion formatted as key#520

Merged
kddejong merged 4 commits intoaws-cloudformation:mainfrom
kddejong:fix/json-resource-type-value-completion
Apr 8, 2026
Merged

fix: JSON resource type value completion formatted as key#520
kddejong merged 4 commits intoaws-cloudformation:mainfrom
kddejong:fix/json-resource-type-value-completion

Conversation

@kddejong
Copy link
Copy Markdown
Collaborator

@kddejong kddejong commented Apr 6, 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 VS Code couldn't match

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.

@kddejong kddejong requested a review from a team as a code owner April 6, 2026 19:35
@kddejong kddejong force-pushed the fix/json-resource-type-value-completion branch from 00a1a8b to ff3dd52 Compare April 6, 2026 19:47
kddejong added 4 commits April 8, 2026 11:36
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.
@Zee2413 Zee2413 force-pushed the fix/json-resource-type-value-completion branch from e36ea32 to bf1faeb Compare April 8, 2026 15:36
@kddejong kddejong merged commit 20b43f7 into aws-cloudformation:main Apr 8, 2026
8 checks passed
@kddejong kddejong deleted the fix/json-resource-type-value-completion branch April 8, 2026 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Resource type completions are not displayed in JSON

3 participants