Skip to content

Commit 7e2da01

Browse files
committed
definition to get added to the bottom of
1 parent 0ec64fa commit 7e2da01

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ export class ExtractSubSchemaToDefs {
6969
const newDefName = `def${highestDefNumber + 1}`;
7070
const extractedDef = schemaDocument.textDocument.getText(range);
7171
const settings = await this.configuration.get();
72-
72+
const lastDefinition = definitionsNode?.children.at(-1);
73+
const lastDefinitionPosition = (lastDefinition?.offset && lastDefinition?.textLength)
74+
? lastDefinition.offset + lastDefinition.textLength
75+
: /** @type {number} */ (definitionsNode?.offset) + 1;
7376
/** @type {CodeAction} */
7477
const codeAction = {
7578
title: `Extract '${newDefName}' to ${definitionsKeyword}`,
@@ -84,10 +87,10 @@ export class ExtractSubSchemaToDefs {
8487
definitionsNode
8588
? withFormatting(schemaDocument.textDocument, {
8689
range: {
87-
start: schemaDocument.textDocument.positionAt(definitionsNode.offset + 1),
88-
end: schemaDocument.textDocument.positionAt(definitionsNode.offset + 1)
90+
start: schemaDocument.textDocument.positionAt(lastDefinitionPosition),
91+
end: schemaDocument.textDocument.positionAt(lastDefinitionPosition)
8992
},
90-
newText: `\n"${newDefName}": ${extractedDef},`
93+
newText: lastDefinition ? `,\n"${newDefName}": ${extractedDef}` : `\n"${newDefName}": ${extractedDef}`
9194
}, settings)
9295
: withFormatting(schemaDocument.textDocument, {
9396
range: {

0 commit comments

Comments
 (0)