Skip to content

Commit 7643405

Browse files
committed
Move findNodeAtOffset
1 parent cc2b52e commit 7643405

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

language-server/src/json-node.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,5 @@ export const annotation = (node, keyword, dialect = "https://json-schema.org/dra
4545
return Instance.annotation(node, keyword, dialect);
4646
};
4747

48-
export const findNodeAtOffset = (node, offset, includeRightBound = false) => {
49-
if (contains(node, offset, includeRightBound)) {
50-
for (let i = 0; i < node.children.length && node.children[i].offset <= offset; i++) {
51-
const item = findNodeAtOffset(node.children[i], offset, includeRightBound);
52-
if (item) {
53-
return item;
54-
}
55-
}
56-
57-
return node;
58-
}
59-
};
60-
61-
const contains = (node, offset, includeRightBound = false) => {
62-
return (offset >= node.offset && offset < (node.offset + node.textLength))
63-
|| includeRightBound && (offset === (node.offset + node.textLength));
64-
};
65-
6648
// eslint-disable-next-line import/export
6749
export * from "@hyperjump/json-schema/annotated-instance/experimental";

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export class JsonSchemaDocument {
180180

181181
findNodeAtOffset(offset) {
182182
for (const { schemaResource } of this.schemaResources) {
183-
const node = JsonNode.findNodeAtOffset(schemaResource, offset);
183+
const node = _findNodeAtOffset(schemaResource, offset);
184184
if (node) {
185185
return node;
186186
}
@@ -212,6 +212,24 @@ const getEmbeddedDialectUri = (node, dialectUri) => {
212212
}
213213
};
214214

215+
const _findNodeAtOffset = (node, offset, includeRightBound = false) => {
216+
if (contains(node, offset, includeRightBound)) {
217+
for (let i = 0; i < node.children.length && node.children[i].offset <= offset; i++) {
218+
const item = _findNodeAtOffset(node.children[i], offset, includeRightBound);
219+
if (item) {
220+
return item;
221+
}
222+
}
223+
224+
return node;
225+
}
226+
};
227+
228+
const contains = (node, offset, includeRightBound = false) => {
229+
return (offset >= node.offset && offset < (node.offset + node.textLength))
230+
|| includeRightBound && (offset === (node.offset + node.textLength));
231+
};
232+
215233
const nodeStep = (node, key) => {
216234
const property = node.children.find((property) => getNodeValue(property.children[0]) === key);
217235
return property?.children[1];

0 commit comments

Comments
 (0)