Skip to content

Commit 12a81a8

Browse files
arpitkuriyaljdesrosiers
authored andcommitted
fixed formatting issue for embedded schema
1 parent cb6110a commit 12a81a8

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

language-server/src/features/codeAction/extractSubschema.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ export class ExtractSubSchemaToDefs {
5151

5252
const dialectUri = /** @type {string} */ (node.root.dialectUri);
5353
const definitionsKeyword = getKeywordName(dialectUri, "https://json-schema.org/keyword/definitions");
54-
5554
const definitionsNode = SchemaNode.step(definitionsKeyword, node.root);
5655
let highestDefNumber = 0;
5756
if (definitionsNode) {
@@ -69,8 +68,10 @@ export class ExtractSubSchemaToDefs {
6968
const newDefName = `def${highestDefNumber + 1}`;
7069
const extractedDef = schemaDocument.textDocument.getText(range);
7170
const settings = await this.configuration.get();
71+
const lastSubschema = node.root.children.slice(-1)[0];
72+
const lastSubschemaPosition = lastSubschema.offset + lastSubschema.textLength;
7273
const lastDefinition = definitionsNode?.children.at(-1);
73-
const lastDefinitionPosition = (lastDefinition?.offset && lastDefinition?.textLength)
74+
const lastDefinitionPosition = (lastDefinition)
7475
? lastDefinition.offset + lastDefinition.textLength
7576
: /** @type {number} */ (definitionsNode?.offset) + 1;
7677
/** @type {CodeAction} */
@@ -94,8 +95,8 @@ export class ExtractSubSchemaToDefs {
9495
}, settings)
9596
: withFormatting(schemaDocument.textDocument, {
9697
range: {
97-
start: schemaDocument.textDocument.positionAt(node.root.offset + node.root.textLength - 2),
98-
end: schemaDocument.textDocument.positionAt(node.root.offset + node.root.textLength - 2)
98+
start: schemaDocument.textDocument.positionAt(lastSubschemaPosition),
99+
end: schemaDocument.textDocument.positionAt(lastSubschemaPosition)
99100
},
100101
newText: `,\n"${definitionsKeyword}": {\n"${newDefName}": ${extractedDef}\n}`
101102
}, settings)

0 commit comments

Comments
 (0)