redhat-developer / redhat-developer/vscode-yaml

Invalid auto-complete when `const` is an object

Open
#950 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
829
Forks
260
Avg merge
5h 43m
Merged PRs (30d)
1

Description

Describe the bug

When the value of const is an object, the auto-complete for the property/instance is garbled and invalid.

Instead of:

foo:
  bar: baz

It auto-completes as:

foo: 
  bar}: ${2:baz

Expected Behavior

Auto-complete for constant values should insert correctly, even when the constant is an object, as it does when the constant is an array, string, number, or null.

Current Behavior

Auto-complete inserts what appears to be a broken internal string.

Steps to Reproduce

  1. Define a test schema as test.schema.json:

    {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "title": "Schema with an object constant",
        "description": "Defines a schema with an object constant.",
        "type": "object",
        "properties": {
            "foo": {
                "title": "Property with an object constant",
                "const": {
                    "bar": "baz"
                }
            }
        }
    }
    
  2. Define a test instance using that schema as test.instance.yaml:

    # yaml-language-server: $schema=test.schema.json
    
  3. Type foo, wait for IntelliSense, then press enter.

  4. Result:

    # yaml-language-server: $schema=test.schema.yaml
    foo: 
      bar}: ${2:baz
    
  5. Define a test instance as test.schema.json

    {
        "$schema": "test.schema.json"
    }
    
  6. Add a comma, then use IntelliSense to find the foo property and press enter to auto-complete.

  7. Result:

       {
        "$schema": "test.schema.json",
        "foo": {
            "bar": "baz"
        }
    }
    

Environment

  • Windows
  • Mac
  • Linux
  • other (please specify)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with test.schema.json and test.instance.yaml, using IntelliSense on the foo property with an object const. Trace the autocomplete handling for object constants and compare it with the documented array, string, number, and null cases. Done means both YAML and JSON insert valid object values without malformed snippet placeholders.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, vscode
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.