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

feat: extend array documentation on completion #608

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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