Skip to content

Commit 5aa341a

Browse files
committed
restructure conditionals to reduce indentation
1 parent 3ebbdc1 commit 5aa341a

1 file changed

Lines changed: 20 additions & 18 deletions

File tree

src/services/jsonLinks.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,28 @@ export function findLinks(document: TextDocument, doc: JSONDocument, schemaServi
4141
}
4242
if (node.type === "property" && node.valueNode?.type === 'string' && schemaService) {
4343
const pathNode = node.valueNode;
44-
const pathLinks: DocumentLink[] = [];
4544
const promise = schemaService.getSchemaForResource(document.uri, doc).then((schema) => {
46-
if (schema) {
47-
const matchingSchemas = doc.getMatchingSchemas(schema.schema, pathNode.offset);
48-
matchingSchemas.forEach((s) => {
49-
if (s.node === pathNode && !s.inverted && s.schema) {
50-
if (s.schema.format === 'uri-reference') {
51-
const pathURI = resolveURIRef(pathNode.value, document);
52-
if (pathURI) {
53-
if (fileExistsSync(pathURI.fsPath)) {
54-
pathLinks.push({
55-
target: pathURI.toString(),
56-
range: createRange(document, pathNode)
57-
});
58-
}
59-
}
60-
}
61-
}
62-
});
45+
const pathLinks: DocumentLink[] = [];
46+
if (!schema) {
47+
return pathLinks;
6348
}
49+
doc.getMatchingSchemas(schema.schema, pathNode.offset).forEach((s) => {
50+
if (s.node !== pathNode || s.inverted || !s.schema) {
51+
return;
52+
}
53+
if (s.schema.format !== 'uri-reference') {
54+
return;
55+
}
56+
const pathURI = resolveURIRef(pathNode.value, document);
57+
if (pathURI) {
58+
if (fileExistsSync(pathURI.fsPath)) {
59+
pathLinks.push({
60+
target: pathURI.toString(),
61+
range: createRange(document, pathNode)
62+
});
63+
}
64+
}
65+
});
6466
return pathLinks;
6567
});
6668
promises.push(promise);

0 commit comments

Comments
 (0)