@@ -51,7 +51,6 @@ export class ExtractSubSchemaToDefs {
51
51
52
52
const dialectUri = /** @type {string } */ ( node . root . dialectUri ) ;
53
53
const definitionsKeyword = getKeywordName ( dialectUri , "https://json-schema.org/keyword/definitions" ) ;
54
-
55
54
const definitionsNode = SchemaNode . step ( definitionsKeyword , node . root ) ;
56
55
let highestDefNumber = 0 ;
57
56
if ( definitionsNode ) {
@@ -69,8 +68,10 @@ export class ExtractSubSchemaToDefs {
69
68
const newDefName = `def${ highestDefNumber + 1 } ` ;
70
69
const extractedDef = schemaDocument . textDocument . getText ( range ) ;
71
70
const settings = await this . configuration . get ( ) ;
71
+ const lastSubschema = node . root . children . slice ( - 1 ) [ 0 ] ;
72
+ const lastSubschemaPosition = lastSubschema . offset + lastSubschema . textLength ;
72
73
const lastDefinition = definitionsNode ?. children . at ( - 1 ) ;
73
- const lastDefinitionPosition = ( lastDefinition ?. offset && lastDefinition ?. textLength )
74
+ const lastDefinitionPosition = ( lastDefinition )
74
75
? lastDefinition . offset + lastDefinition . textLength
75
76
: /** @type {number } */ ( definitionsNode ?. offset ) + 1 ;
76
77
/** @type {CodeAction } */
@@ -94,8 +95,8 @@ export class ExtractSubSchemaToDefs {
94
95
} , settings )
95
96
: withFormatting ( schemaDocument . textDocument , {
96
97
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 )
99
100
} ,
100
101
newText : `,\n"${ definitionsKeyword } ": {\n"${ newDefName } ": ${ extractedDef } \n}`
101
102
} , settings )
0 commit comments