Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocomplete bug with nested objects in arrays in the 1.0.0 version #621

Closed
1 of 4 tasks
fredriklengstrand opened this issue Oct 26, 2021 · 5 comments · Fixed by redhat-developer/yaml-language-server#579
Labels
Milestone

Comments

@fredriklengstrand
Copy link

Describe the bug

When I try to autocomplete properties for a nested object inside an array I get autocomplete for the root object instead.

test.yaml:

# yaml-language-server: $schema=schema.json
- teststring: Test
- testobject:
    property1: Test

schema.json

{
    "$schema": "http://json-schema.org/draft-07/schema",
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "teststring": {
                "type": "string"
            },
            "testobject": {
                "type": "object",
                "properties": {
                    "property1": {
                        "type": "string"
                    }
                }
            }
        }
    }
}

Expected Behavior

I expected to be able to autocomplete the property1 property inside the testobject property, this is how it worked in the 0.23.0 version:

0 23 0

Current Behavior

I get autocomplete for the root object:s teststring property in the 1.0.0 version:

1 0 0

Steps to Reproduce

  1. Create the two files as shown above
  2. Try to autocomplete the property1 property

Environment

  • Windows
  • Mac
  • Linux
  • other (please specify)
@mkyrc
Copy link

mkyrc commented Oct 27, 2021

I can confirm the same problem for Linux. The root properties are displayed instead of the object properties. Issue is connected to 1.0.0. Version 0.23.0 is working correctly.

@evidolob
Copy link
Collaborator

@fredriklengstrand @martinkyrc It should be fixed in 1.1.0 which just released, could you check that it works?

@mkyrc
Copy link

mkyrc commented Oct 27, 2021

@evidolob thanks for quick fix. Now it looks much better! :) I can confirm that issue is fixed.

EDIT: I'm playing with some complex json-schema files and issue is not fixed in 1.1.0. I'm attaching more details to new comment.

@fredriklengstrand
Copy link
Author

fredriklengstrand commented Oct 28, 2021

@evidolob Thank you, it seems to work a little better but there still seems to be issues in some cases, for example:

schema.json:

{
    "$schema": "http://json-schema.org/draft-07/schema",
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "teststring": {
                "type": "string"
            },
            "testobject": {
                "type": "object",
                "properties": {
                    "property1": {
                        "type": "string"
                    },
                    "property2": {
                        "type": "string"
                    }
                }
            }
        }
    }
}

test.yaml:

# yaml-language-server: $schema=schema.json
- teststring: Test
- testobject:
    property1: Test

If I try to autocomplete property2 when the cursor is on a line below property1 (with same indentation) it works, but when I have the cursor on a line above property1 (with same indentation) it doesn't (see screenshots). In the 0.23.0 this worked as well.

Works:
works

Doesn't work:
doesn't work

@mkyrc
Copy link

mkyrc commented Oct 28, 2021

It looks, like reported issue is not fixed in 1.1.0. It is connected only to nested arrays. Let me show where is the issue.

json-schema in my test:

{
  "allOf": [
    { "$ref": "#/$configs/objectA" }, 
    { "$ref": "#/$configs/objectB" }
  ],

  "$defs": {
    "name": {      
      "name": { "type": "string", "description": "name" }
    },
    "prop1": {
      "prop1": { "type": "string", "description": "prop1" }
    },
    "prop2": {
      "prop1": { "type": "string", "description": "prop2" }
    }
  },  

  "$configs": {
    "objectA": {
      "type": "object",
      "title": "Object A",
      "properties": {
        "objA": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "name": { "$ref": "#/$defs/name" },
              "color": { "type": "string", "description": "color" },
              "prop1": { "$ref": "#/$defs/prop1" },
              "prop2": { "$ref": "#/$defs/prop2" }
            },
            "required": ["name"],
            "additionalProperties": false
          }
        }
      }
    },
    "objectB": {
      "type": "object",
      "title": "Object B",
      "properties": {
        "objB": {
          "type": "object",
          "properties": {
            "name": { "$ref": "#/$defs/name" },
            "size": { "type": "string", "description": "size" },
            "prop1": { "$ref": "#/$defs/prop1" },
            "prop2": { "$ref": "#/$defs/prop2" }
          },
          "required": ["name", "size"],
          "additionalProperties": false
        }
      }
    }
  }
}

version 0.23

nested array object

everything is working correctly:
v0 23-array-object-working

nested object

everything is working correctly:
v0 23-object-working

version 1.1.0

nested object

it's working:
v1 1 0-object-1-working
v1 1 0-object-2-working

nested array object - is NOT working (working partially)

first suggestion is working:
v1 1 0-array-object-1-working

another 'ctrl+space' suggestions are not working:
v1 1 0-array-object-2-not-working

but suggestions starting with letter are working:
v1 1 0-array-object-3-suggestion-working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants