Skip to content

Commit

Permalink
feat: extend array documentation on completion (#608)
Browse files Browse the repository at this point in the history
Co-authored-by: Petr Spacek <[email protected]>
  • Loading branch information
p-spacek and Petr Spacek authored Dec 8, 2021
1 parent 8c76979 commit 05bab07
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
33 changes: 19 additions & 14 deletions src/languageservice/services/yamlCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,17 +472,20 @@ export class YamlCompletion {
if (Array.isArray(propertySchema.items)) {
this.addSchemaValueCompletions(propertySchema.items[0], separatorAfter, collector, {});
} else if (typeof propertySchema.items === 'object' && propertySchema.items.type === 'object') {
const insertText = `- ${this.getInsertTextForObject(
propertySchema.items,
separatorAfter,
' '
).insertText.trimLeft()}`;
const documentation = this.getDocumentationWithMarkdownText(
`Create an item of an array${propertySchema.description ? ' (' + propertySchema.description + ')' : ''}`,
insertText
);
collector.add({
kind: this.getSuggestionKind(propertySchema.items.type),
label: '- (array item)',
documentation: `Create an item of an array${
propertySchema.description === undefined ? '' : '(' + propertySchema.description + ')'
}`,
insertText: `- ${this.getInsertTextForObject(
propertySchema.items,
separatorAfter,
' '
).insertText.trimLeft()}`,
documentation,
insertText,
insertTextFormat: InsertTextFormat.Snippet,
});
}
Expand Down Expand Up @@ -599,13 +602,16 @@ export class YamlCompletion {
this.addSchemaValueCompletions(s.schema.items[index], separatorAfter, collector, types);
}
} else if (typeof s.schema.items === 'object' && s.schema.items.type === 'object') {
const insertText = `- ${this.getInsertTextForObject(s.schema.items, separatorAfter, ' ').insertText.trimLeft()}`;
const documentation = this.getDocumentationWithMarkdownText(
`Create an item of an array${s.schema.description ? ' (' + s.schema.description + ')' : ''}`,
insertText
);
collector.add({
kind: this.getSuggestionKind(s.schema.items.type),
label: '- (array item)',
documentation: `Create an item of an array${
s.schema.description === undefined ? '' : '(' + s.schema.description + ')'
}`,
insertText: `- ${this.getInsertTextForObject(s.schema.items, separatorAfter, ' ').insertText.trimLeft()}`,
documentation,
insertText,
insertTextFormat: InsertTextFormat.Snippet,
});

Expand Down Expand Up @@ -1302,8 +1308,7 @@ function convertToStringValue(value: string): string {
return `"${value}"`;
}

// eslint-disable-next-line prettier/prettier, no-useless-escape
if (value.indexOf('\"') !== -1) {
if (value.indexOf('"') !== -1) {
value = value.replace(doubleQuotesEscapeRegExp, '"');
}

Expand Down
14 changes: 6 additions & 8 deletions test/autoCompletion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ describe('Auto Completion Tests', () => {
properties: {
name: {
type: 'string',
// eslint-disable-next-line prettier/prettier, no-useless-escape
default: '\"yaml\"',
default: '"yaml"',
},
},
});
Expand All @@ -177,8 +176,7 @@ describe('Auto Completion Tests', () => {
properties: {
name: {
type: 'string',
// eslint-disable-next-line prettier/prettier, no-useless-escape
default: '\"yaml\"',
default: '"yaml"',
},
},
});
Expand Down Expand Up @@ -898,7 +896,7 @@ describe('Auto Completion Tests', () => {
assert.deepEqual(
result.items[0],
createExpectedCompletion('- (array item)', '- $1', 1, 2, 1, 3, 9, 2, {
documentation: 'Create an item of an array',
documentation: { kind: 'markdown', value: 'Create an item of an array\n ```\n- \n```' },
})
);
})
Expand Down Expand Up @@ -933,7 +931,7 @@ describe('Auto Completion Tests', () => {
assert.deepEqual(
result.items[0],
createExpectedCompletion('- (array item)', '- $1', 2, 2, 2, 2, 9, 2, {
documentation: 'Create an item of an array',
documentation: { kind: 'markdown', value: 'Create an item of an array\n ```\n- \n```' },
})
);
})
Expand Down Expand Up @@ -968,7 +966,7 @@ describe('Auto Completion Tests', () => {
assert.deepEqual(
result.items[0],
createExpectedCompletion('- (array item)', '- $1', 1, 0, 1, 0, 9, 2, {
documentation: 'Create an item of an array',
documentation: { kind: 'markdown', value: 'Create an item of an array\n ```\n- \n```' },
})
);
})
Expand Down Expand Up @@ -1189,7 +1187,7 @@ describe('Auto Completion Tests', () => {
assert.deepEqual(
result.items[0],
createExpectedCompletion('- (array item)', '- name: ${1:test}', 3, 4, 3, 4, 9, 2, {
documentation: 'Create an item of an array',
documentation: { kind: 'markdown', value: 'Create an item of an array\n ```\n- name: test\n```' },
})
);
})
Expand Down

0 comments on commit 05bab07

Please sign in to comment.