Skip to content

Commit cc2b52e

Browse files
committed
Rename json-node.js
1 parent a8c89f5 commit cc2b52e

File tree

7 files changed

+26
-26
lines changed

7 files changed

+26
-26
lines changed

language-server/src/annotations.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { describe, it, expect, beforeAll, afterAll } from "vitest";
55

66
import { registerSchema, unregisterSchema } from "@hyperjump/json-schema/draft-2020-12";
77
import { getSchema, compile, interpret } from "@hyperjump/json-schema/experimental";
8-
import * as Instance from "./json-instance.js";
8+
import * as JsonNode from "./json-node.js";
99
import { toAbsoluteUri } from "./util.js";
1010
import { TextDocument } from "vscode-languageserver-textdocument";
1111
import { parseTree } from "jsonc-parser";
@@ -55,15 +55,15 @@ describe("Annotations", () => {
5555
allowTrailingComma: true,
5656
allowEmptyContent: true
5757
});
58-
instance = Instance.fromJsonc(root);
58+
instance = JsonNode.fromJsonc(root);
5959
interpret(compiled, instance);
6060
});
6161

6262
subject.assertions.forEach((assertion) => {
6363
it(`${assertion.keyword} annotations at '${assertion.location}' should be ${JSON.stringify(assertion.expected)}`, () => {
6464
const dialect = suite.schema.$schema ? toAbsoluteUri(suite.schema.$schema) : dialectId;
65-
const subject = Instance.get(assertion.location, instance);
66-
const annotations = subject ? Instance.annotation(subject, assertion.keyword, dialect) : [];
65+
const subject = JsonNode.get(assertion.location, instance);
66+
const annotations = subject ? JsonNode.annotation(subject, assertion.keyword, dialect) : [];
6767
expect(annotations).to.eql(assertion.expected);
6868
});
6969
});

language-server/src/features/deprecated.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { DiagnosticSeverity, DiagnosticTag } from "vscode-languageserver";
2-
import * as Instance from "../json-instance.js";
2+
import * as JsonNode from "../json-node.js";
33
import { subscribe } from "../pubsub.js";
44

55

@@ -11,10 +11,10 @@ export default {
1111
onInitialized() {
1212
subscribe("diagnostics", async (_message, { schemaDocument, diagnostics }) => {
1313
for (const deprecated of schemaDocument.annotatedWith("deprecated")) {
14-
if (Instance.annotation(deprecated, "deprecated").some((deprecated) => deprecated)) {
14+
if (JsonNode.annotation(deprecated, "deprecated").some((deprecated) => deprecated)) {
1515
diagnostics.push({
1616
instance: deprecated.parent,
17-
message: Instance.annotation(deprecated, "x-deprecationMessage").join("\n") || "deprecated",
17+
message: JsonNode.annotation(deprecated, "x-deprecationMessage").join("\n") || "deprecated",
1818
severity: DiagnosticSeverity.Warning,
1919
tags: [DiagnosticTag.Deprecated]
2020
});

language-server/src/features/hover.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { MarkupKind } from "vscode-languageserver";
2-
import * as Instance from "../json-instance.js";
2+
import * as JsonNode from "../json-node.js";
33
import { getSchemaDocument } from "./schema-registry.js";
44

55

@@ -19,11 +19,11 @@ export default {
1919

2020
// This is a little wierd because we want the hover to be on the keyword, but
2121
// the annotation is actually on the value not the keyword.
22-
if (keyword.parent && Instance.typeOf(keyword.parent) === "property" && keyword.parent.children[0] === keyword) {
22+
if (keyword.parent && JsonNode.typeOf(keyword.parent) === "property" && keyword.parent.children[0] === keyword) {
2323
return {
2424
contents: {
2525
kind: MarkupKind.Markdown,
26-
value: Instance.annotation(keyword.parent.children[1], "description").join("\n")
26+
value: JsonNode.annotation(keyword.parent.children[1], "description").join("\n")
2727
},
2828
range: {
2929
start: document.positionAt(keyword.offset),

language-server/src/features/semantic-tokens.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { SemanticTokensBuilder } from "vscode-languageserver";
22
import { getKeywordId } from "@hyperjump/json-schema/experimental";
3-
import * as Instance from "../json-instance.js";
3+
import * as JsonNode from "../json-node.js";
44
import { getSchemaDocument } from "./schema-registry.js";
55
import { toAbsoluteUri } from "../util.js";
66
import { isMatchedFile } from "./workspace.js";
@@ -133,8 +133,8 @@ const getSemanticTokens = function* (schemaDocument) {
133133
};
134134

135135
const schemaHandler = function* (schemaResource, dialectUri) {
136-
for (const [keyNode, valueNode] of Instance.entries(schemaResource)) {
137-
const keywordName = Instance.value(keyNode);
136+
for (const [keyNode, valueNode] of JsonNode.entries(schemaResource)) {
137+
const keywordName = JsonNode.value(keyNode);
138138
const keywordId = keywordIdFor(keywordName, dialectUri);
139139

140140
if (keywordId) {
@@ -159,13 +159,13 @@ const keywordIdFor = (keywordName, dialectUri) => {
159159
};
160160

161161
const schemaMapHandler = function* (schemaResource, dialectUri) {
162-
for (const schemaNode of Instance.values(schemaResource)) {
162+
for (const schemaNode of JsonNode.values(schemaResource)) {
163163
yield* schemaHandler(schemaNode, dialectUri);
164164
}
165165
};
166166

167167
const schemaArrayHandler = function* (schemaResource, dialectUri) {
168-
for (const schemaNode of Instance.iter(schemaResource)) {
168+
for (const schemaNode of JsonNode.iter(schemaResource)) {
169169
yield* schemaHandler(schemaNode, dialectUri);
170170
}
171171
};

language-server/src/json-schema-document.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { getSchema, compile, interpret, getKeywordName, hasDialect, BASIC } from
22
import * as JsonPointer from "@hyperjump/json-pointer";
33
import { resolveIri, toAbsoluteIri } from "@hyperjump/uri";
44
import { getNodeValue, parseTree } from "jsonc-parser";
5-
import * as Instance from "./json-instance.js";
5+
import * as JsonNode from "./json-node.js";
66
import { uriFragment } from "./util.js";
77

88

@@ -28,8 +28,8 @@ export class JsonSchemaDocument {
2828

2929
for (const { dialectUri, schemaResource } of document.schemaResources) {
3030
if (!hasDialect(dialectUri)) {
31-
const $schema = Instance.get("#/$schema", schemaResource);
32-
if ($schema && Instance.typeOf($schema) === "string") {
31+
const $schema = JsonNode.get("#/$schema", schemaResource);
32+
if ($schema && JsonNode.typeOf($schema) === "string") {
3333
document.errors.push({
3434
keyword: "https://json-schema.org/keyword/schema",
3535
instanceNode: $schema,
@@ -60,7 +60,7 @@ export class JsonSchemaDocument {
6060
document.errors.push({
6161
keyword: error.keyword,
6262
keywordNode: await getSchema(error.absoluteKeywordLocation),
63-
instanceNode: Instance.get(error.instanceLocation, schemaResource)
63+
instanceNode: JsonNode.get(error.instanceLocation, schemaResource)
6464
});
6565
}
6666
}
@@ -71,7 +71,7 @@ export class JsonSchemaDocument {
7171
}
7272

7373
#buildSchemaResources(node, uri = "", dialectUri = "", pointer = "", parent = undefined, anchors = {}) {
74-
const jsonNode = Instance.cons(uri, pointer, getNodeValue(node), node.type, [], parent, node.offset, node.length);
74+
const jsonNode = JsonNode.cons(uri, pointer, getNodeValue(node), node.type, [], parent, node.offset, node.length);
7575

7676
switch (node.type) {
7777
case "array":
@@ -115,7 +115,7 @@ export class JsonSchemaDocument {
115115
if (embeddedDialectUri) {
116116
this.#buildSchemaResources(node, uri, embeddedDialectUri);
117117

118-
return Instance.cons(uri, pointer, true, "boolean", [], parent, node.offset, node.length);
118+
return JsonNode.cons(uri, pointer, true, "boolean", [], parent, node.offset, node.length);
119119
}
120120
}
121121

@@ -170,8 +170,8 @@ export class JsonSchemaDocument {
170170

171171
* annotatedWith(keyword, dialectId = "https://json-schema.org/draft/2020-12/schema") {
172172
for (const { schemaResource } of this.schemaResources) {
173-
for (const node of Instance.allNodes(schemaResource)) {
174-
if (Instance.annotation(node, keyword, dialectId).length > 0) {
173+
for (const node of JsonNode.allNodes(schemaResource)) {
174+
if (JsonNode.annotation(node, keyword, dialectId).length > 0) {
175175
yield node;
176176
}
177177
}
@@ -180,7 +180,7 @@ export class JsonSchemaDocument {
180180

181181
findNodeAtOffset(offset) {
182182
for (const { schemaResource } of this.schemaResources) {
183-
const node = Instance.findNodeAtOffset(schemaResource, offset);
183+
const node = JsonNode.findNodeAtOffset(schemaResource, offset);
184184
if (node) {
185185
return node;
186186
}

language-server/src/json-schema-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { registerSchema, unregisterSchema } from "@hyperjump/json-schema";
55
import { getSchema, compile, interpret } from "@hyperjump/json-schema/experimental";
66
import { TextDocument } from "vscode-languageserver-textdocument";
77
import { parseTree } from "jsonc-parser";
8-
import * as Instance from "./json-instance.js";
8+
import * as JsonNode from "./json-node.js";
99

1010

1111
const shouldSkip = (skip, path) => {
@@ -83,7 +83,7 @@ export const runTestSuite = (draft, dialectId, skip) => {
8383
allowTrailingComma: true,
8484
allowEmptyContent: true
8585
});
86-
const instance = Instance.fromJsonc(root);
86+
const instance = JsonNode.fromJsonc(root);
8787
const output = interpret(compiled, instance);
8888
expect(output.valid).to.equal(test.valid);
8989
});

0 commit comments

Comments
 (0)