in src/services/jsonCompletion.ts [298:339]
private getSchemaLessPropertyCompletions(doc: Parser.JSONDocument, node: ASTNode, currentKey: string, collector: CompletionsCollector): void {
const collectCompletionsForSimilarObject = (obj: ObjectASTNode) => {
obj.properties.forEach((p) => {
const key = p.keyNode.value;
collector.add({
kind: CompletionItemKind.Property,
label: key,
insertText: this.getInsertTextForValue(key, ''),
insertTextFormat: InsertTextFormat.Snippet,
filterText: this.getFilterTextForValue(key),
documentation: ''
});
});
};
if (node.parent) {
if (node.parent.type === 'property') {
// if the object is a property value, check the tree for other objects that hang under a property of the same name
const parentKey = node.parent.keyNode.value;
doc.visit(n => {
if (n.type === 'property' && n !== node.parent && n.keyNode.value === parentKey && n.valueNode && n.valueNode.type === 'object') {
collectCompletionsForSimilarObject(n.valueNode);
}
return true;
});
} else if (node.parent.type === 'array') {
// if the object is in an array, use all other array elements as similar objects
node.parent.items.forEach(n => {
if (n.type === 'object' && n !== node) {
collectCompletionsForSimilarObject(n);
}
});
}
} else if (node.type === 'object') {
collector.add({
kind: CompletionItemKind.Property,
label: '$schema',
insertText: this.getInsertTextForProperty('$schema', undefined, true, ''),
insertTextFormat: InsertTextFormat.Snippet, documentation: '',
filterText: this.getFilterTextForValue("$schema")
});
}
}