Skip to content

Commit d7c2154

Browse files
committed
fix: doNotSuggest for property and value completion
1 parent ed03cbf commit d7c2154

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

src/languageservice/services/yamlCompletion.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,10 @@ export class YamlCompletion {
691691
});
692692
}
693693
for (const schema of matchingSchemas) {
694+
if (schema.schema.doNotSuggest) {
695+
continue;
696+
}
697+
694698
if (
695699
((schema.node.internalNode === node && !matchOriginal) ||
696700
(schema.node.internalNode === originalNode && !hasColon) ||
@@ -716,7 +720,7 @@ export class YamlCompletion {
716720
if (Object.prototype.hasOwnProperty.call(schemaProperties, key)) {
717721
const propertySchema = schemaProperties[key];
718722

719-
if (typeof propertySchema === 'object' && !propertySchema.deprecationMessage && !propertySchema['doNotSuggest']) {
723+
if (typeof propertySchema === 'object' && !propertySchema.deprecationMessage && !propertySchema.doNotSuggest) {
720724
let identCompensation = '';
721725
if (nodeParent && isSeq(nodeParent) && node.items.length <= 1 && !hasOnlyWhitespace) {
722726
// because there is a slash '-' to prevent the properties generated to have the correct
@@ -1308,6 +1312,10 @@ export class YamlCompletion {
13081312
isArray?: boolean
13091313
): void {
13101314
if (typeof schema === 'object') {
1315+
if (schema.doNotSuggest) {
1316+
return;
1317+
}
1318+
13111319
this.addEnumValueCompletions(schema, separatorAfter, collector, isArray);
13121320
this.addDefaultValueCompletions(schema, separatorAfter, collector);
13131321
this.collectTypes(schema, types);

test/autoCompletionFix.test.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,4 +1305,70 @@ test1:
13051305
expect(completion.items[0].insertText).to.be.equal('${1:property}: ');
13061306
expect(completion.items[0].documentation).to.be.equal('Property Description');
13071307
});
1308+
1309+
describe('doNotSuggest schema', () => {
1310+
it('should not autocomplete schema with doNotSuggest - property completion', async () => {
1311+
const schema: JSONSchema = {
1312+
properties: {
1313+
prop1: { type: 'string' },
1314+
},
1315+
doNotSuggest: true,
1316+
};
1317+
schemaProvider.addSchema(SCHEMA_ID, schema);
1318+
const content = '';
1319+
const completion = await parseSetup(content, 0, 1);
1320+
1321+
expect(completion.items.length).equal(0);
1322+
});
1323+
it('should not autocomplete schema with doNotSuggest - value completion', async () => {
1324+
const schema: JSONSchema = {
1325+
properties: {
1326+
prop1: {
1327+
anyOf: [
1328+
{
1329+
type: 'string',
1330+
default: 'value_default',
1331+
doNotSuggest: true,
1332+
},
1333+
{
1334+
type: 'object',
1335+
defaultSnippets: [
1336+
{
1337+
label: 'snippet',
1338+
body: {
1339+
value1: 'value_snippet',
1340+
},
1341+
},
1342+
],
1343+
doNotSuggest: true,
1344+
},
1345+
],
1346+
},
1347+
},
1348+
};
1349+
schemaProvider.addSchema(SCHEMA_ID, schema);
1350+
const content = 'prop1: ';
1351+
const completion = await parseSetup(content, 0, content.length);
1352+
1353+
expect(completion.items.length).equal(0);
1354+
});
1355+
it('should autocomplete inside schema in doNotSuggest', async () => {
1356+
const schema: JSONSchema = {
1357+
properties: {
1358+
obj1: {
1359+
properties: {
1360+
item1: { type: 'string' },
1361+
},
1362+
},
1363+
},
1364+
doNotSuggest: true,
1365+
};
1366+
schemaProvider.addSchema(SCHEMA_ID, schema);
1367+
const content = 'obj1:\n | |';
1368+
const completion = await parseCaret(content);
1369+
1370+
expect(completion.items.length).equal(1);
1371+
expect(completion.items[0].label).equal('item1');
1372+
});
1373+
});
13081374
});

0 commit comments

Comments
 (0)