@@ -45,8 +45,8 @@ describe("Feature - CodeAction: Extract subSchema to $defs", () => {
45
45
{
46
46
newText : `{ "$ref": "#/$defs/def1" }` ,
47
47
range : {
48
- end : { character : 5 , line : 7 } ,
49
- start : { character : 13 , line : 4 }
48
+ start : { line : 4 , character : 13 } ,
49
+ end : { line : 7 , character : 5 }
50
50
}
51
51
} ,
52
52
{
@@ -58,8 +58,8 @@ describe("Feature - CodeAction: Extract subSchema to $defs", () => {
58
58
}
59
59
}` ,
60
60
range : {
61
- end : { character : 3 , line : 8 } ,
62
- start : { character : 3 , line : 8 }
61
+ start : { line : 8 , character : 3 } ,
62
+ end : { line : 8 , character : 3 }
63
63
}
64
64
}
65
65
] ,
@@ -109,8 +109,8 @@ describe("Feature - CodeAction: Extract subSchema to $defs", () => {
109
109
{
110
110
newText : `{ "$ref": "#/definitions/def2" }` ,
111
111
range : {
112
- end : { line : 8 , character : 5 } ,
113
- start : { line : 5 , character : 11 }
112
+ start : { line : 5 , character : 11 } ,
113
+ end : { line : 8 , character : 5 }
114
114
}
115
115
} ,
116
116
{
@@ -120,8 +120,8 @@ describe("Feature - CodeAction: Extract subSchema to $defs", () => {
120
120
"minimum": 0
121
121
}` ,
122
122
range : {
123
- end : { character : 5 , line : 13 } ,
124
- start : { character : 5 , line : 13 }
123
+ start : { line : 13 , character : 5 } ,
124
+ end : { line : 13 , character : 5 }
125
125
}
126
126
}
127
127
] ,
@@ -214,8 +214,8 @@ describe("Feature - CodeAction: Extract subSchema to $defs", () => {
214
214
{
215
215
newText : `{ "$ref": "#/definitions/def1" }` ,
216
216
range : {
217
- end : { line : 7 , character : 5 } ,
218
- start : { line : 4 , character : 11 }
217
+ start : { line : 4 , character : 11 } ,
218
+ end : { line : 7 , character : 5 }
219
219
}
220
220
} ,
221
221
{
@@ -225,8 +225,8 @@ describe("Feature - CodeAction: Extract subSchema to $defs", () => {
225
225
"minimum": 0
226
226
}` ,
227
227
range : {
228
- end : { character : 18 , line : 9 } ,
229
- start : { character : 18 , line : 9 }
228
+ start : { line : 9 , character : 18 } ,
229
+ end : { line : 9 , character : 18 }
230
230
}
231
231
}
232
232
] ,
@@ -319,8 +319,8 @@ describe("Feature - CodeAction: Extract subSchema to $defs", () => {
319
319
newText : `,
320
320
"def1": { "type": "string" }` ,
321
321
range : {
322
- end : { character : 56 , line : 23 } ,
323
- start : { character : 56 , line : 23 }
322
+ start : { line : 23 , character : 56 } ,
323
+ end : { line : 23 , character : 56 }
324
324
}
325
325
}
326
326
] ,
@@ -361,17 +361,15 @@ describe("Feature - CodeAction: Extract subSchema to $defs", () => {
361
361
expect ( edits ?. [ 1 ] ?. range ?. end ) . to . eql ( { line : 8 , character : 3 } ) ;
362
362
} ) ;
363
363
364
- describe ( "should maintain indentation as per used in the schema " , ( ) => {
365
- test ( "checking for the indentation: 2 spaces" , async ( ) => {
364
+ describe ( "Handling configuration settings " , ( ) => {
365
+ test ( "uses detected indentation when detectIndentation is true and applies default EOL behavior when eol is 'auto' - checking for 2 spaces" , async ( ) => {
366
366
await client . changeConfiguration (
367
367
undefined ,
368
368
{
369
- tabSize : 2 ,
370
- insertSpaces : true ,
371
- detectIndentation : false
369
+ detectIndentation : true
372
370
} ,
373
371
{
374
- eol : "\n "
372
+ eol : "auto "
375
373
}
376
374
) ;
377
375
await client . writeDocument ( "subject.schema.json" , `{
@@ -404,7 +402,7 @@ describe("Feature - CodeAction: Extract subSchema to $defs", () => {
404
402
}` ) ;
405
403
} ) ;
406
404
407
- test ( "checking for the indentation: 4 spaces" , async ( ) => {
405
+ test ( "uses provided tabSize and insertSpaces when detectIndentation is false and respects specified EOL when settings.eol is not 'auto' - checking for 4 spaces" , async ( ) => {
408
406
await client . changeConfiguration (
409
407
undefined ,
410
408
{
@@ -445,5 +443,46 @@ describe("Feature - CodeAction: Extract subSchema to $defs", () => {
445
443
}
446
444
}` ) ;
447
445
} ) ;
446
+
447
+ test ( "indentation.type is 'tab' when insertSpaces is false and it works correctly with the schema" , async ( ) => {
448
+ await client . changeConfiguration (
449
+ undefined ,
450
+ {
451
+ tabSize : 2 ,
452
+ insertSpaces : false ,
453
+ detectIndentation : false
454
+ }
455
+ ) ;
456
+ await client . writeDocument ( "subject.schema.json" , `{
457
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
458
+ "type": "object",
459
+ "properties": {
460
+ "name": {
461
+ "type": "string"
462
+ }
463
+ }
464
+ }` ) ;
465
+ documentUri = await client . openDocument ( "subject.schema.json" ) ;
466
+
467
+ const codeActions = await client . sendRequest ( CodeActionRequest . type , {
468
+ textDocument : { uri : documentUri } ,
469
+ range : {
470
+ start : { line : 4 , character : 12 } ,
471
+ end : { line : 6 , character : 5 }
472
+ } ,
473
+ context : { diagnostics : [ ] }
474
+ } ) ;
475
+ const firstAction = codeActions ?. [ 0 ] as CodeAction ;
476
+ const documentChange = firstAction . edit ?. documentChanges ?. [ 0 ] as TextDocumentEdit ;
477
+ const edits = documentChange . edits ;
478
+ /* eslint-disable @stylistic/no-tabs */
479
+ expect ( edits ?. [ 1 ] . newText ) . to . eql ( `,
480
+ "$defs": {
481
+ "def1": {
482
+ "type": "string"
483
+ }
484
+ }` ) ;
485
+ /* eslint-enable @stylistic/no-tabs */
486
+ } ) ;
448
487
} ) ;
449
488
} ) ;
0 commit comments