in src/services/jsonDocumentSymbols.ts [239:269]
public findDocumentColors(document: TextDocument, doc: Parser.JSONDocument, context?: DocumentSymbolsContext): Thenable<ColorInformation[]> {
return this.schemaService.getSchemaForResource(document.uri, doc).then(schema => {
const result: ColorInformation[] = [];
if (schema) {
let limit = context && typeof context.resultLimit === 'number' ? context.resultLimit : Number.MAX_VALUE;
const matchingSchemas = doc.getMatchingSchemas(schema.schema);
const visitedNode: { [nodeId: string]: boolean } = {};
for (const s of matchingSchemas) {
if (!s.inverted && s.schema && (s.schema.format === 'color' || s.schema.format === 'color-hex') && s.node && s.node.type === 'string') {
const nodeId = String(s.node.offset);
if (!visitedNode[nodeId]) {
const color = colorFromHex(Parser.getNodeValue(s.node));
if (color) {
const range = getRange(document, s.node);
result.push({ color, range });
}
visitedNode[nodeId] = true;
limit--;
if (limit <= 0) {
if (context && context.onResultLimitExceeded) {
context.onResultLimitExceeded(document.uri);
}
return result;
}
}
}
}
}
return result;
});
}