Skip to content
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
15 changes: 7 additions & 8 deletions src/languageservice/services/yamlCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ const doubleQuotesEscapeRegExp = /[\\]+"/g;
const parentCompletionKind = CompletionItemKind.Class;

interface ParentCompletionItemOptions {
schemaType: string;
schemaDescription?: string;
schema: JSONSchema;
indent?: string;
insertTexts?: string[];
}
Expand Down Expand Up @@ -158,10 +157,12 @@ export class YamlCompletion {
if (existsInYaml) {
return;
}
const schema = completionItem.parent.schema;
const schemaType = getSchemaTypeName(schema);
const schemaDescription = schema.markdownDescription || schema.description;

const schemaType = completionItem.parent.schemaType;
let parentCompletion: CompletionItem | undefined = result.items.find(
(item) => item.label === schemaType && item.kind === parentCompletionKind
(item: CompletionItem) => item.parent?.schema === schema && item.kind === parentCompletionKind
);

if (parentCompletion && parentCompletion.parent.insertTexts.includes(completionItem.insertText)) {
Expand All @@ -172,7 +173,7 @@ export class YamlCompletion {
parentCompletion = {
...completionItem,
label: schemaType,
documentation: completionItem.parent.schemaDescription,
documentation: schemaDescription,
sortText: '_' + schemaType, // this parent completion goes first,
kind: parentCompletionKind,
};
Expand Down Expand Up @@ -633,7 +634,6 @@ export class YamlCompletion {
});
// if the prop is required add it also to parent suggestion
if (schema.schema.required?.includes(key)) {
const schemaType = getSchemaTypeName(schema.schema);
collector.add({
label: key,
insertText: this.getInsertTextForProperty(
Expand All @@ -645,8 +645,7 @@ export class YamlCompletion {
insertTextFormat: InsertTextFormat.Snippet,
documentation: this.fromMarkup(propertySchema.markdownDescription) || propertySchema.description || '',
parent: {
schemaType,
schemaDescription: schema.schema.markdownDescription || schema.schema.description,
schema: schema.schema,
indent: identCompensation,
},
});
Expand Down
5 changes: 3 additions & 2 deletions test/autoCompletion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2707,7 +2707,7 @@ describe('Auto Completion Tests', () => {
})
);
});
it('Should agregate suggested text without duplicities in insertText', async () => {
it('Should not agregate suggested text from different schemas', async () => {
const schema = {
definitions: { obj1, obj2 },
anyOf: [
Expand All @@ -2723,7 +2723,7 @@ describe('Auto Completion Tests', () => {
const content = '';
const result = await parseSetup(content, content.length);

expect(result.items.length).equal(3);
expect(result.items.length).equal(4);
expect(result.items[1]).to.deep.equal(
createExpectedCompletion('Object1', 'type: typeObj1\noptions:\n label: ', 0, 0, 0, 0, 7, 2, {
documentation: {
Expand All @@ -2733,6 +2733,7 @@ describe('Auto Completion Tests', () => {
sortText: '_Object1',
})
);
expect(result.items[1]).to.deep.equal(result.items[3]);
});
it('Should suggest rest of the parent object', async () => {
const schema = {
Expand Down