Skip to content

Commit 769f53f

Browse files
committed
fix: doNotSuggest for property and value completion
1 parent 7203630 commit 769f53f

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
@@ -1309,6 +1313,10 @@ export class YamlCompletion {
13091313
isArray?: boolean
13101314
): void {
13111315
if (typeof schema === 'object') {
1316+
if (schema.doNotSuggest) {
1317+
return;
1318+
}
1319+
13121320
this.addEnumValueCompletions(schema, separatorAfter, collector, isArray);
13131321
this.addDefaultValueCompletions(schema, separatorAfter, collector);
13141322
this.collectTypes(schema, types);

test/autoCompletionFix.test.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,4 +1329,70 @@ test1:
13291329
expect(completion.items[0].insertText).to.be.equal('${1:property}: ');
13301330
expect(completion.items[0].documentation).to.be.equal('Property Description');
13311331
});
1332+
1333+
describe('doNotSuggest schema', () => {
1334+
it('should not autocomplete schema with doNotSuggest - property completion', async () => {
1335+
const schema: JSONSchema = {
1336+
properties: {
1337+
prop1: { type: 'string' },
1338+
},
1339+
doNotSuggest: true,
1340+
};
1341+
schemaProvider.addSchema(SCHEMA_ID, schema);
1342+
const content = '';
1343+
const completion = await parseSetup(content, 0, 1);
1344+
1345+
expect(completion.items.length).equal(0);
1346+
});
1347+
it('should not autocomplete schema with doNotSuggest - value completion', async () => {
1348+
const schema: JSONSchema = {
1349+
properties: {
1350+
prop1: {
1351+
anyOf: [
1352+
{
1353+
type: 'string',
1354+
default: 'value_default',
1355+
doNotSuggest: true,
1356+
},
1357+
{
1358+
type: 'object',
1359+
defaultSnippets: [
1360+
{
1361+
label: 'snippet',
1362+
body: {
1363+
value1: 'value_snippet',
1364+
},
1365+
},
1366+
],
1367+
doNotSuggest: true,
1368+
},
1369+
],
1370+
},
1371+
},
1372+
};
1373+
schemaProvider.addSchema(SCHEMA_ID, schema);
1374+
const content = 'prop1: ';
1375+
const completion = await parseSetup(content, 0, content.length);
1376+
1377+
expect(completion.items.length).equal(0);
1378+
});
1379+
it('should autocomplete inside schema in doNotSuggest', async () => {
1380+
const schema: JSONSchema = {
1381+
properties: {
1382+
obj1: {
1383+
properties: {
1384+
item1: { type: 'string' },
1385+
},
1386+
},
1387+
},
1388+
doNotSuggest: true,
1389+
};
1390+
schemaProvider.addSchema(SCHEMA_ID, schema);
1391+
const content = 'obj1:\n | |';
1392+
const completion = await parseCaret(content);
1393+
1394+
expect(completion.items.length).equal(1);
1395+
expect(completion.items[0].label).equal('item1');
1396+
});
1397+
});
13321398
});

0 commit comments

Comments
 (0)