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

fix: autocomplete indent on object within an array #5

Merged
merged 1 commit into from
Jul 26, 2022

Conversation

rickcowan
Copy link
Collaborator

What does this PR do?

Fixes an issue where the indent is incorrect for an object within an array that is also within an array.

Given the following schema:

{
  "type": "object",
  "properties": {
    "array1": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["thing1"],
        "properties": {
          "thing1": {
            "type": "object",
            "required": ["array2"],
            "properties": {
              "array2": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": ["thing2", "type"],
                  "properties": {
                    "type": {
                      "type": "string"
                    },
                    "thing2": {
                      "type": "object",
                      "required": ["item1", "item2"],
                      "properties": {
                        "item1": { "type": "string" },
                        "item2": { "type": "string" }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

When autocomplete is attempted on:

array1:
  - #cursor here

It previously autocompleted to:

array1:
  - thing1:
      array2:
        - type: 
          thing2:
          item1: 
          item2: 

After the fix it correctly indents as:

array1:
  - thing1:
      array2:
        - type: 
          thing2:
            item1: 
            item2: 

The prior code that added indentation should now be handled by this fix: redhat-developer#634

What issues does this PR fix or reference?

https://app.zenhub.com/workspaces/eusa-standup-board---6071eb7d59410e000e9bc963/issues/jigx-com/jigx-builder/307

Is it tested? How?

Manual testing and unit test.

Copy link
Collaborator

@p-spacek p-spacek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why they had 'two spaces' instead of ${this.indentation}... but I think it wasn't correct.

@@ -1299,7 +1299,7 @@ export class YamlCompletion {
if (arrayInsertLines.length > 1) {
for (let index = 1; index < arrayInsertLines.length; index++) {
const element = arrayInsertLines[index];
arrayInsertLines[index] = `${indent}${this.indentation} ${element.trimLeft()}`;
arrayInsertLines[index] = ` ${element}`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two spaces are there because of the standard indentation?
if yes, there should be ${this.indentation} instead
because indentation could be 4 spaces, tabulator, 2 spaces

@rickcowan rickcowan merged commit 111d926 into jigx Jul 26, 2022
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.

2 participants