vscode-yaml icon indicating copy to clipboard operation
vscode-yaml copied to clipboard

Invalid auto-complete when `const` is an object

Open michaeltlombardi opened this issue 2 years ago • 0 comments

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

  • [x] Windows
  • [ ] Mac
  • [ ] Linux
  • [ ] other (please specify)

michaeltlombardi avatar Jul 03 '23 14:07 michaeltlombardi