Skip to content

Commit c26c936

Browse files
committed
Move dialect registry to schema-document
1 parent 4e1cd4a commit c26c936

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

language-server/src/features/schema-registry.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { getDocumentSettings } from "./document-settings.js";
22
import * as SchemaDocument from "../schema-document.js";
3-
import { registerSchema, unregisterSchema } from "@hyperjump/json-schema/draft-2020-12";
4-
import * as SchemaNode from "../schema-node.js";
3+
import { unregisterSchema } from "@hyperjump/json-schema/draft-2020-12";
54
import { publishAsync } from "../pubsub.js";
6-
import { keywordNameFor } from "../util.js";
75

86
/**
97
* @import { Connection } from "vscode-languageserver"
@@ -56,13 +54,6 @@ export const getSchemaDocument = async (connection, textDocument) => {
5654

5755
schemaDocuments.set(textDocument.uri, { version: textDocument.version, schemaDocument });
5856
}
59-
for (const schemaResource of schemaDocument.schemaResources) {
60-
const vocabToken = keywordNameFor("https://json-schema.org/keyword/vocabulary", schemaResource.dialectUri);
61-
const vocabularyNode = vocabToken && await SchemaNode.step(vocabToken, schemaResource);
62-
if (vocabularyNode) {
63-
registerSchema(SchemaNode.value(schemaResource), textDocument.uri);
64-
}
65-
}
6657

6758
return schemaDocument;
6859
};

language-server/src/schema-document.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { reduce } from "@hyperjump/pact";
44
import { getNodeValue, parseTree } from "jsonc-parser";
55
import * as SchemaNode from "./schema-node.js";
66
import { keywordNameFor, toAbsoluteUri, uriFragment, resolveIri, normalizeUri } from "./util.js";
7+
import { addSchema } from "@hyperjump/json-schema/draft-2020-12";
78

89
/**
910
* @import { TextDocument } from "vscode-languageserver-textdocument"
@@ -57,6 +58,12 @@ export const fromTextDocument = async (textDocument, contextDialectUri) => {
5758
buildSchemaResources(document, root, textDocument.uri, contextDialectUri);
5859

5960
for (const schemaResource of document.schemaResources) {
61+
const vocabToken = keywordNameFor("https://json-schema.org/keyword/vocabulary", schemaResource.dialectUri);
62+
const vocabularyNode = vocabToken && await SchemaNode.step(vocabToken, schemaResource);
63+
if (vocabularyNode) {
64+
addSchema(SchemaNode.value(schemaResource), schemaResource.baseUri);
65+
}
66+
6067
if (!schemaResource.dialectUri || !hasDialect(schemaResource.dialectUri)) {
6168
const $schema = SchemaNode.get("#/$schema", schemaResource);
6269
if ($schema && SchemaNode.typeOf($schema) === "string") {

0 commit comments

Comments
 (0)