opencode-navigator 0.27.4 → 0.27.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,5 @@
1
+ import {parseTree,findNodeAtLocation,modify,applyEdits
2
+ } from "./chunk-v6qckzat.js";
1
3
  import {createComponent as _$createComponent4} from "@opentui/solid"
2
4
  import {createSignal} from "solid-js"
3
5
  function todoConfig(entries){let owner=-1
@@ -9,833 +11,6 @@ const candidates=owner>=0?[entries[owner]]:entries
9
11
  const files=[...new Set(candidates.flatMap((entry)=>entry.path&&/\.jsonc?$/iu.test(entry.path)?[entry.path]:[]))]
10
12
  return{enabled,files,signature:JSON.stringify(entries),unavailable:files.length===0?"OpenCode did not expose an editable JSON/JSONC source for its effective experimental settings.":undefined
11
13
  }}
12
- function createScanner(text,ignoreTrivia=false){const len=text.length
13
- let pos=0,value="",tokenOffset=0,token=16,lineNumber=0,lineStartOffset=0,tokenLineStartOffset=0,prevTokenLineStartOffset=0,scanError=0
14
- function scanHexDigits(count,exact){let digits=0
15
- let value=0
16
- while(digits<count||!exact){let ch=text.charCodeAt(pos)
17
- if(ch>=48&&ch<=57){value=value*16 + ch-48
18
- } else if(ch>=65&&ch<=70){value=value*16 + ch-65 + 10
19
- } else if(ch>=97&&ch<=102){value=value*16 + ch-97 + 10
20
- } else{break
21
- }
22
- pos++
23
- digits++
24
- }
25
- if(digits<count){value=-1
26
- }
27
- return value
28
- }
29
- function setPosition(newPosition){pos=newPosition
30
- value=""
31
- tokenOffset=0
32
- token=16
33
- scanError=0
34
- }
35
- function scanNumber(){let start=pos
36
- if(text.charCodeAt(pos)===48){pos++
37
- } else{pos++
38
- while(pos<text.length&&isDigit(text.charCodeAt(pos))){pos++
39
- }}
40
- if(pos<text.length&&text.charCodeAt(pos)===46){pos++
41
- if(pos<text.length&&isDigit(text.charCodeAt(pos))){pos++
42
- while(pos<text.length&&isDigit(text.charCodeAt(pos))){pos++
43
- }} else{scanError=3
44
- return text.substring(start,pos)
45
- }}
46
- let end=pos
47
- if(pos<text.length&&(text.charCodeAt(pos)===69||text.charCodeAt(pos)===101)){pos++
48
- if(pos<text.length&&text.charCodeAt(pos)===43||text.charCodeAt(pos)===45){pos++
49
- }
50
- if(pos<text.length&&isDigit(text.charCodeAt(pos))){pos++
51
- while(pos<text.length&&isDigit(text.charCodeAt(pos))){pos++
52
- }
53
- end=pos
54
- } else{scanError=3
55
- }}
56
- return text.substring(start,end)
57
- }
58
- function scanString(){let result="",start=pos
59
- while(true){if(pos>=len){result += text.substring(start,pos)
60
- scanError=2
61
- break
62
- }
63
- const ch=text.charCodeAt(pos)
64
- if(ch===34){result += text.substring(start,pos)
65
- pos++
66
- break
67
- }
68
- if(ch===92){result += text.substring(start,pos)
69
- pos++
70
- if(pos>=len){scanError=2
71
- break
72
- }
73
- const ch2=text.charCodeAt(pos++)
74
- switch(ch2){case 34:result += '"'
75
- break
76
- case 92:result += "\\"
77
- break
78
- case 47:result += "/"
79
- break
80
- case 98:result += "\b"
81
- break
82
- case 102:result += "\f"
83
- break
84
- case 110:result += `
85
- `
86
- break
87
- case 114:result += "\r"
88
- break
89
- case 116:result += "\t"
90
- break
91
- case 117:const ch3=scanHexDigits(4,true)
92
- if(ch3>=0){result += String.fromCharCode(ch3)
93
- } else{scanError=4
94
- }
95
- break
96
- default:scanError=5
97
- }
98
- start=pos
99
- continue
100
- }
101
- if(ch>=0&&ch<=31){if(isLineBreak(ch)){result += text.substring(start,pos)
102
- scanError=2
103
- break
104
- } else{scanError=6
105
- }}
106
- pos++
107
- }
108
- return result
109
- }
110
- function scanNext(){value=""
111
- scanError=0
112
- tokenOffset=pos
113
- lineStartOffset=lineNumber
114
- prevTokenLineStartOffset=tokenLineStartOffset
115
- if(pos>=len){tokenOffset=len
116
- return token=17
117
- }
118
- let code=text.charCodeAt(pos)
119
- if(isWhiteSpace(code)){do{pos++
120
- value += String.fromCharCode(code)
121
- code=text.charCodeAt(pos)
122
- } while(isWhiteSpace(code))
123
- return token=15
124
- }
125
- if(isLineBreak(code)){pos++
126
- value += String.fromCharCode(code)
127
- if(code===13&&text.charCodeAt(pos)===10){pos++
128
- value += `
129
- `
130
- }
131
- lineNumber++
132
- tokenLineStartOffset=pos
133
- return token=14
134
- }
135
- switch(code){case 123:pos++
136
- return token=1
137
- case 125:pos++
138
- return token=2
139
- case 91:pos++
140
- return token=3
141
- case 93:pos++
142
- return token=4
143
- case 58:pos++
144
- return token=6
145
- case 44:pos++
146
- return token=5
147
- case 34:pos++
148
- value=scanString()
149
- return token=10
150
- case 47:const start=pos-1
151
- if(text.charCodeAt(pos + 1)===47){pos += 2
152
- while(pos<len){if(isLineBreak(text.charCodeAt(pos))){break
153
- }
154
- pos++
155
- }
156
- value=text.substring(start,pos)
157
- return token=12
158
- }
159
- if(text.charCodeAt(pos + 1)===42){pos += 2
160
- const safeLength=len-1
161
- let commentClosed=false
162
- while(pos<safeLength){const ch=text.charCodeAt(pos)
163
- if(ch===42&&text.charCodeAt(pos + 1)===47){pos += 2
164
- commentClosed=true
165
- break
166
- }
167
- pos++
168
- if(isLineBreak(ch)){if(ch===13&&text.charCodeAt(pos)===10){pos++
169
- }
170
- lineNumber++
171
- tokenLineStartOffset=pos
172
- }}
173
- if(!commentClosed){pos++
174
- scanError=1
175
- }
176
- value=text.substring(start,pos)
177
- return token=13
178
- }
179
- value += String.fromCharCode(code)
180
- pos++
181
- return token=16
182
- case 45:value += String.fromCharCode(code)
183
- pos++
184
- if(pos===len||!isDigit(text.charCodeAt(pos))){return token=16
185
- }
186
- case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:value += scanNumber()
187
- return token=11
188
- default:while(pos<len&&isUnknownContentCharacter(code)){pos++
189
- code=text.charCodeAt(pos)
190
- }
191
- if(tokenOffset!==pos){value=text.substring(tokenOffset,pos)
192
- switch(value){case "true":return token=8
193
- case "false":return token=9
194
- case "null":return token=7
195
- }
196
- return token=16
197
- }
198
- value += String.fromCharCode(code)
199
- pos++
200
- return token=16
201
- }}
202
- function isUnknownContentCharacter(code){if(isWhiteSpace(code)||isLineBreak(code)){return false
203
- }
204
- switch(code){case 125:case 93:case 123:case 91:case 34:case 58:case 44:case 47:return false
205
- }
206
- return true
207
- }
208
- function scanNextNonTrivia(){let result
209
- do{result=scanNext()
210
- } while(result>=12&&result<=15)
211
- return result
212
- }
213
- return{setPosition,getPosition:()=>pos,scan:ignoreTrivia?scanNextNonTrivia:scanNext,getToken:()=>token,getTokenValue:()=>value,getTokenOffset:()=>tokenOffset,getTokenLength:()=>pos-tokenOffset,getTokenStartLine:()=>lineStartOffset,getTokenStartCharacter:()=>tokenOffset-prevTokenLineStartOffset,getTokenError:()=>scanError
214
- }}
215
- function isWhiteSpace(ch){return ch===32||ch===9
216
- }
217
- function isLineBreak(ch){return ch===10||ch===13
218
- }
219
- function isDigit(ch){return ch>=48&&ch<=57
220
- }
221
- var CharacterCodes;
222
- (function(CharacterCodes){CharacterCodes[CharacterCodes["lineFeed"]=10]="lineFeed"
223
- CharacterCodes[CharacterCodes["carriageReturn"]=13]="carriageReturn"
224
- CharacterCodes[CharacterCodes["space"]=32]="space"
225
- CharacterCodes[CharacterCodes["_0"]=48]="_0"
226
- CharacterCodes[CharacterCodes["_1"]=49]="_1"
227
- CharacterCodes[CharacterCodes["_2"]=50]="_2"
228
- CharacterCodes[CharacterCodes["_3"]=51]="_3"
229
- CharacterCodes[CharacterCodes["_4"]=52]="_4"
230
- CharacterCodes[CharacterCodes["_5"]=53]="_5"
231
- CharacterCodes[CharacterCodes["_6"]=54]="_6"
232
- CharacterCodes[CharacterCodes["_7"]=55]="_7"
233
- CharacterCodes[CharacterCodes["_8"]=56]="_8"
234
- CharacterCodes[CharacterCodes["_9"]=57]="_9"
235
- CharacterCodes[CharacterCodes["a"]=97]="a"
236
- CharacterCodes[CharacterCodes["b"]=98]="b"
237
- CharacterCodes[CharacterCodes["c"]=99]="c"
238
- CharacterCodes[CharacterCodes["d"]=100]="d"
239
- CharacterCodes[CharacterCodes["e"]=101]="e"
240
- CharacterCodes[CharacterCodes["f"]=102]="f"
241
- CharacterCodes[CharacterCodes["g"]=103]="g"
242
- CharacterCodes[CharacterCodes["h"]=104]="h"
243
- CharacterCodes[CharacterCodes["i"]=105]="i"
244
- CharacterCodes[CharacterCodes["j"]=106]="j"
245
- CharacterCodes[CharacterCodes["k"]=107]="k"
246
- CharacterCodes[CharacterCodes["l"]=108]="l"
247
- CharacterCodes[CharacterCodes["m"]=109]="m"
248
- CharacterCodes[CharacterCodes["n"]=110]="n"
249
- CharacterCodes[CharacterCodes["o"]=111]="o"
250
- CharacterCodes[CharacterCodes["p"]=112]="p"
251
- CharacterCodes[CharacterCodes["q"]=113]="q"
252
- CharacterCodes[CharacterCodes["r"]=114]="r"
253
- CharacterCodes[CharacterCodes["s"]=115]="s"
254
- CharacterCodes[CharacterCodes["t"]=116]="t"
255
- CharacterCodes[CharacterCodes["u"]=117]="u"
256
- CharacterCodes[CharacterCodes["v"]=118]="v"
257
- CharacterCodes[CharacterCodes["w"]=119]="w"
258
- CharacterCodes[CharacterCodes["x"]=120]="x"
259
- CharacterCodes[CharacterCodes["y"]=121]="y"
260
- CharacterCodes[CharacterCodes["z"]=122]="z"
261
- CharacterCodes[CharacterCodes["A"]=65]="A"
262
- CharacterCodes[CharacterCodes["B"]=66]="B"
263
- CharacterCodes[CharacterCodes["C"]=67]="C"
264
- CharacterCodes[CharacterCodes["D"]=68]="D"
265
- CharacterCodes[CharacterCodes["E"]=69]="E"
266
- CharacterCodes[CharacterCodes["F"]=70]="F"
267
- CharacterCodes[CharacterCodes["G"]=71]="G"
268
- CharacterCodes[CharacterCodes["H"]=72]="H"
269
- CharacterCodes[CharacterCodes["I"]=73]="I"
270
- CharacterCodes[CharacterCodes["J"]=74]="J"
271
- CharacterCodes[CharacterCodes["K"]=75]="K"
272
- CharacterCodes[CharacterCodes["L"]=76]="L"
273
- CharacterCodes[CharacterCodes["M"]=77]="M"
274
- CharacterCodes[CharacterCodes["N"]=78]="N"
275
- CharacterCodes[CharacterCodes["O"]=79]="O"
276
- CharacterCodes[CharacterCodes["P"]=80]="P"
277
- CharacterCodes[CharacterCodes["Q"]=81]="Q"
278
- CharacterCodes[CharacterCodes["R"]=82]="R"
279
- CharacterCodes[CharacterCodes["S"]=83]="S"
280
- CharacterCodes[CharacterCodes["T"]=84]="T"
281
- CharacterCodes[CharacterCodes["U"]=85]="U"
282
- CharacterCodes[CharacterCodes["V"]=86]="V"
283
- CharacterCodes[CharacterCodes["W"]=87]="W"
284
- CharacterCodes[CharacterCodes["X"]=88]="X"
285
- CharacterCodes[CharacterCodes["Y"]=89]="Y"
286
- CharacterCodes[CharacterCodes["Z"]=90]="Z"
287
- CharacterCodes[CharacterCodes["asterisk"]=42]="asterisk"
288
- CharacterCodes[CharacterCodes["backslash"]=92]="backslash"
289
- CharacterCodes[CharacterCodes["closeBrace"]=125]="closeBrace"
290
- CharacterCodes[CharacterCodes["closeBracket"]=93]="closeBracket"
291
- CharacterCodes[CharacterCodes["colon"]=58]="colon"
292
- CharacterCodes[CharacterCodes["comma"]=44]="comma"
293
- CharacterCodes[CharacterCodes["dot"]=46]="dot"
294
- CharacterCodes[CharacterCodes["doubleQuote"]=34]="doubleQuote"
295
- CharacterCodes[CharacterCodes["minus"]=45]="minus"
296
- CharacterCodes[CharacterCodes["openBrace"]=123]="openBrace"
297
- CharacterCodes[CharacterCodes["openBracket"]=91]="openBracket"
298
- CharacterCodes[CharacterCodes["plus"]=43]="plus"
299
- CharacterCodes[CharacterCodes["slash"]=47]="slash"
300
- CharacterCodes[CharacterCodes["formFeed"]=12]="formFeed"
301
- CharacterCodes[CharacterCodes["tab"]=9]="tab"
302
- })(CharacterCodes||(CharacterCodes={}));
303
- var cachedSpaces=new Array(20).fill(0).map((_,index)=>{return " ".repeat(index)
304
- })
305
- var maxCachedValues=200
306
- var cachedBreakLinesWithSpaces={" ":{"\n":new Array(maxCachedValues).fill(0).map((_,index)=>{return `
307
- ` + " ".repeat(index)
308
- }),"\r":new Array(maxCachedValues).fill(0).map((_,index)=>{return "\r" + " ".repeat(index)
309
- }),"\r\n":new Array(maxCachedValues).fill(0).map((_,index)=>{return `\r
310
- ` + " ".repeat(index)
311
- })
312
- },"\t":{"\n":new Array(maxCachedValues).fill(0).map((_,index)=>{return `
313
- ` + "\t".repeat(index)
314
- }),"\r":new Array(maxCachedValues).fill(0).map((_,index)=>{return "\r" + "\t".repeat(index)
315
- }),"\r\n":new Array(maxCachedValues).fill(0).map((_,index)=>{return `\r
316
- ` + "\t".repeat(index)
317
- })
318
- }}
319
- var supportedEols=[`
320
- `,"\r",`\r
321
- `];
322
- function format(documentText,range,options){let initialIndentLevel
323
- let formatText
324
- let formatTextStart
325
- let rangeStart
326
- let rangeEnd
327
- if(range){rangeStart=range.offset
328
- rangeEnd=rangeStart + range.length
329
- formatTextStart=rangeStart
330
- while(formatTextStart>0&&!isEOL(documentText,formatTextStart-1)){formatTextStart--
331
- }
332
- let endOffset=rangeEnd
333
- while(endOffset<documentText.length&&!isEOL(documentText,endOffset)){endOffset++
334
- }
335
- formatText=documentText.substring(formatTextStart,endOffset)
336
- initialIndentLevel=computeIndentLevel(formatText,options)
337
- } else{formatText=documentText
338
- initialIndentLevel=0
339
- formatTextStart=0
340
- rangeStart=0
341
- rangeEnd=documentText.length
342
- }
343
- const eol=getEOL(options,documentText)
344
- const eolFastPathSupported=supportedEols.includes(eol)
345
- let numberLineBreaks=0
346
- let indentLevel=0
347
- let indentValue
348
- if(options.insertSpaces){indentValue=cachedSpaces[options.tabSize||4]??repeat(cachedSpaces[1],options.tabSize||4)
349
- } else{indentValue="\t"
350
- }
351
- const indentType=indentValue==="\t"?"\t":" "
352
- let scanner=createScanner(formatText,false)
353
- let hasError=false
354
- function newLinesAndIndent(){if(numberLineBreaks>1){return repeat(eol,numberLineBreaks) + repeat(indentValue,initialIndentLevel + indentLevel)
355
- }
356
- const amountOfSpaces=indentValue.length*(initialIndentLevel + indentLevel)
357
- if(!eolFastPathSupported||amountOfSpaces>cachedBreakLinesWithSpaces[indentType][eol].length){return eol + repeat(indentValue,initialIndentLevel + indentLevel)
358
- }
359
- if(amountOfSpaces<=0){return eol
360
- }
361
- return cachedBreakLinesWithSpaces[indentType][eol][amountOfSpaces]
362
- }
363
- function scanNext(){let token=scanner.scan()
364
- numberLineBreaks=0
365
- while(token===15||token===14){if(token===14&&options.keepLines){numberLineBreaks += 1
366
- } else if(token===14){numberLineBreaks=1
367
- }
368
- token=scanner.scan()
369
- }
370
- hasError=token===16||scanner.getTokenError()!==0
371
- return token
372
- }
373
- const editOperations=[]
374
- function addEdit(text,startOffset,endOffset){if(!hasError&&(!range||startOffset<rangeEnd&&endOffset>rangeStart)&&documentText.substring(startOffset,endOffset)!==text){editOperations.push({offset:startOffset,length:endOffset-startOffset,content:text})
375
- }}
376
- let firstToken=scanNext()
377
- if(options.keepLines&&numberLineBreaks>0){addEdit(repeat(eol,numberLineBreaks),0,0)
378
- }
379
- if(firstToken!==17){let firstTokenStart=scanner.getTokenOffset() + formatTextStart
380
- let initialIndent=indentValue.length*initialIndentLevel<20&&options.insertSpaces?cachedSpaces[indentValue.length*initialIndentLevel]:repeat(indentValue,initialIndentLevel)
381
- addEdit(initialIndent,formatTextStart,firstTokenStart)
382
- }
383
- while(firstToken!==17){let firstTokenEnd=scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart
384
- let secondToken=scanNext()
385
- let replaceContent=""
386
- let needsLineBreak=false
387
- while(numberLineBreaks===0&&(secondToken===12||secondToken===13)){let commentTokenStart=scanner.getTokenOffset() + formatTextStart
388
- addEdit(cachedSpaces[1],firstTokenEnd,commentTokenStart)
389
- firstTokenEnd=scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart
390
- needsLineBreak=secondToken===12
391
- replaceContent=needsLineBreak?newLinesAndIndent():""
392
- secondToken=scanNext()
393
- }
394
- if(secondToken===2){if(firstToken!==1){indentLevel--
395
- }
396
- if(options.keepLines&&numberLineBreaks>0||!options.keepLines&&firstToken!==1){replaceContent=newLinesAndIndent()
397
- } else if(options.keepLines){replaceContent=cachedSpaces[1]
398
- }} else if(secondToken===4){if(firstToken!==3){indentLevel--
399
- }
400
- if(options.keepLines&&numberLineBreaks>0||!options.keepLines&&firstToken!==3){replaceContent=newLinesAndIndent()
401
- } else if(options.keepLines){replaceContent=cachedSpaces[1]
402
- }} else{switch(firstToken){case 3:case 1:indentLevel++
403
- if(options.keepLines&&numberLineBreaks>0||!options.keepLines){replaceContent=newLinesAndIndent()
404
- } else{replaceContent=cachedSpaces[1]
405
- }
406
- break
407
- case 5:if(options.keepLines&&numberLineBreaks>0||!options.keepLines){replaceContent=newLinesAndIndent()
408
- } else{replaceContent=cachedSpaces[1]
409
- }
410
- break
411
- case 12:replaceContent=newLinesAndIndent()
412
- break
413
- case 13:if(numberLineBreaks>0){replaceContent=newLinesAndIndent()
414
- } else if(!needsLineBreak){replaceContent=cachedSpaces[1]
415
- }
416
- break
417
- case 6:if(options.keepLines&&numberLineBreaks>0){replaceContent=newLinesAndIndent()
418
- } else if(!needsLineBreak){replaceContent=cachedSpaces[1]
419
- }
420
- break
421
- case 10:if(options.keepLines&&numberLineBreaks>0){replaceContent=newLinesAndIndent()
422
- } else if(secondToken===6&&!needsLineBreak){replaceContent=""
423
- }
424
- break
425
- case 7:case 8:case 9:case 11:case 2:case 4:if(options.keepLines&&numberLineBreaks>0){replaceContent=newLinesAndIndent()
426
- } else{if((secondToken===12||secondToken===13)&&!needsLineBreak){replaceContent=cachedSpaces[1]
427
- } else if(secondToken!==5&&secondToken!==17){hasError=true
428
- }}
429
- break
430
- case 16:hasError=true
431
- break
432
- }
433
- if(numberLineBreaks>0&&(secondToken===12||secondToken===13)){replaceContent=newLinesAndIndent()
434
- }}
435
- if(secondToken===17){if(options.keepLines&&numberLineBreaks>0){replaceContent=newLinesAndIndent()
436
- } else{replaceContent=options.insertFinalNewline?eol:""
437
- }}
438
- const secondTokenStart=scanner.getTokenOffset() + formatTextStart
439
- addEdit(replaceContent,firstTokenEnd,secondTokenStart)
440
- firstToken=secondToken
441
- }
442
- return editOperations
443
- }
444
- function repeat(s,count){let result=""
445
- for(let i=0;i<count; i++){result += s
446
- }
447
- return result
448
- }
449
- function computeIndentLevel(content,options){let i=0
450
- let nChars=0
451
- const tabSize=options.tabSize||4
452
- while(i<content.length){let ch=content.charAt(i)
453
- if(ch===cachedSpaces[1]){nChars++
454
- } else if(ch==="\t"){nChars += tabSize
455
- } else{break
456
- }
457
- i++
458
- }
459
- return Math.floor(nChars / tabSize)
460
- }
461
- function getEOL(options,text){for(let i=0;i<text.length; i++){const ch=text.charAt(i)
462
- if(ch==="\r"){if(i + 1<text.length&&text.charAt(i + 1)===`
463
- `){return `\r
464
- `
465
- }
466
- return "\r"
467
- } else if(ch===`
468
- `){return `
469
- `
470
- }}
471
- return options&&options.eol||`
472
- `
473
- }
474
- function isEOL(text,offset){return `\r
475
- `.indexOf(text.charAt(offset))!==-1
476
- }
477
- var ParseOptions;
478
- (function(ParseOptions){ParseOptions.DEFAULT={allowTrailingComma:false
479
- }})(ParseOptions||(ParseOptions={}))
480
- function parseTree(text,errors=[],options=ParseOptions.DEFAULT){let currentParent={type:"array",offset:-1,length:-1,children:[],parent:undefined}
481
- function ensurePropertyComplete(endOffset){if(currentParent.type==="property"){currentParent.length=endOffset-currentParent.offset
482
- currentParent=currentParent.parent
483
- }}
484
- function onValue(valueNode){currentParent.children.push(valueNode)
485
- return valueNode
486
- }
487
- const visitor={onObjectBegin:(offset)=>{currentParent=onValue({type:"object",offset,length:-1,parent:currentParent,children:[]})
488
- },onObjectProperty:(name,offset,length)=>{currentParent=onValue({type:"property",offset,length:-1,parent:currentParent,children:[]})
489
- currentParent.children.push({type:"string",value:name,offset,length,parent:currentParent})
490
- },onObjectEnd:(offset,length)=>{ensurePropertyComplete(offset + length)
491
- currentParent.length=offset + length-currentParent.offset
492
- currentParent=currentParent.parent
493
- ensurePropertyComplete(offset + length)
494
- },onArrayBegin:(offset,length)=>{currentParent=onValue({type:"array",offset,length:-1,parent:currentParent,children:[]})
495
- },onArrayEnd:(offset,length)=>{currentParent.length=offset + length-currentParent.offset
496
- currentParent=currentParent.parent
497
- ensurePropertyComplete(offset + length)
498
- },onLiteralValue:(value,offset,length)=>{onValue({type:getNodeType(value),offset,length,parent:currentParent,value})
499
- ensurePropertyComplete(offset + length)
500
- },onSeparator:(sep,offset,length)=>{if(currentParent.type==="property"){if(sep===":"){currentParent.colonOffset=offset
501
- } else if(sep===","){ensurePropertyComplete(offset)
502
- }}},onError:(error,offset,length)=>{errors.push({error,offset,length})
503
- }}
504
- visit(text,visitor,options)
505
- const result=currentParent.children[0]
506
- if(result){delete result.parent
507
- }
508
- return result
509
- }
510
- function findNodeAtLocation(root,path){if(!root){return
511
- }
512
- let node=root
513
- for(let segment of path){if(typeof segment==="string"){if(node.type!=="object"||!Array.isArray(node.children)){return
514
- }
515
- let found=false
516
- for(const propertyNode of node.children){if(Array.isArray(propertyNode.children)&&propertyNode.children[0].value===segment&&propertyNode.children.length===2){node=propertyNode.children[1]
517
- found=true
518
- break
519
- }}
520
- if(!found){return
521
- }} else{const index=segment
522
- if(node.type!=="array"||index<0||!Array.isArray(node.children)||index>=node.children.length){return
523
- }
524
- node=node.children[index]
525
- }}
526
- return node
527
- }
528
- function visit(text,visitor,options=ParseOptions.DEFAULT){const _scanner=createScanner(text,false)
529
- const _jsonPath=[]
530
- let suppressedCallbacks=0
531
- function toNoArgVisit(visitFunction){return visitFunction?()=>suppressedCallbacks===0&&visitFunction(_scanner.getTokenOffset(),_scanner.getTokenLength(),_scanner.getTokenStartLine(),_scanner.getTokenStartCharacter()):()=>true
532
- }
533
- function toOneArgVisit(visitFunction){return visitFunction?(arg)=>suppressedCallbacks===0&&visitFunction(arg,_scanner.getTokenOffset(),_scanner.getTokenLength(),_scanner.getTokenStartLine(),_scanner.getTokenStartCharacter()):()=>true
534
- }
535
- function toOneArgVisitWithPath(visitFunction){return visitFunction?(arg)=>suppressedCallbacks===0&&visitFunction(arg,_scanner.getTokenOffset(),_scanner.getTokenLength(),_scanner.getTokenStartLine(),_scanner.getTokenStartCharacter(),()=>_jsonPath.slice()):()=>true
536
- }
537
- function toBeginVisit(visitFunction){return visitFunction?()=>{if(suppressedCallbacks>0){suppressedCallbacks++
538
- } else{let cbReturn=visitFunction(_scanner.getTokenOffset(),_scanner.getTokenLength(),_scanner.getTokenStartLine(),_scanner.getTokenStartCharacter(),()=>_jsonPath.slice())
539
- if(cbReturn===false){suppressedCallbacks=1
540
- }}}:()=>true
541
- }
542
- function toEndVisit(visitFunction){return visitFunction?()=>{if(suppressedCallbacks>0){suppressedCallbacks--
543
- }
544
- if(suppressedCallbacks===0){visitFunction(_scanner.getTokenOffset(),_scanner.getTokenLength(),_scanner.getTokenStartLine(),_scanner.getTokenStartCharacter())
545
- }}:()=>true
546
- }
547
- const onObjectBegin=toBeginVisit(visitor.onObjectBegin),onObjectProperty=toOneArgVisitWithPath(visitor.onObjectProperty),onObjectEnd=toEndVisit(visitor.onObjectEnd),onArrayBegin=toBeginVisit(visitor.onArrayBegin),onArrayEnd=toEndVisit(visitor.onArrayEnd),onLiteralValue=toOneArgVisitWithPath(visitor.onLiteralValue),onSeparator=toOneArgVisit(visitor.onSeparator),onComment=toNoArgVisit(visitor.onComment),onError=toOneArgVisit(visitor.onError)
548
- const disallowComments=options&&options.disallowComments
549
- const allowTrailingComma=options&&options.allowTrailingComma
550
- function scanNext(){while(true){const token=_scanner.scan()
551
- switch(_scanner.getTokenError()){case 4:handleError(14)
552
- break
553
- case 5:handleError(15)
554
- break
555
- case 3:handleError(13)
556
- break
557
- case 1:if(!disallowComments){handleError(11)
558
- }
559
- break
560
- case 2:handleError(12)
561
- break
562
- case 6:handleError(16)
563
- break
564
- }
565
- switch(token){case 12:case 13:if(disallowComments){handleError(10)
566
- } else{onComment()
567
- }
568
- break
569
- case 16:handleError(1)
570
- break
571
- case 15:case 14:break
572
- default:return token
573
- }}}
574
- function handleError(error,skipUntilAfter=[],skipUntil=[]){onError(error)
575
- if(skipUntilAfter.length + skipUntil.length>0){let token=_scanner.getToken()
576
- while(token!==17){if(skipUntilAfter.indexOf(token)!==-1){scanNext()
577
- break
578
- } else if(skipUntil.indexOf(token)!==-1){break
579
- }
580
- token=scanNext()
581
- }}}
582
- function parseString(isValue){const value=_scanner.getTokenValue()
583
- if(isValue){onLiteralValue(value)
584
- } else{onObjectProperty(value)
585
- _jsonPath.push(value)
586
- }
587
- scanNext()
588
- return true
589
- }
590
- function parseLiteral(){switch(_scanner.getToken()){case 11:const tokenValue=_scanner.getTokenValue()
591
- let value=Number(tokenValue)
592
- if(isNaN(value)){handleError(2)
593
- value=0
594
- }
595
- onLiteralValue(value)
596
- break
597
- case 7:onLiteralValue(null)
598
- break
599
- case 8:onLiteralValue(true)
600
- break
601
- case 9:onLiteralValue(false)
602
- break
603
- default:return false
604
- }
605
- scanNext()
606
- return true
607
- }
608
- function parseProperty(){if(_scanner.getToken()!==10){handleError(3,[],[2,5])
609
- return false
610
- }
611
- parseString(false)
612
- if(_scanner.getToken()===6){onSeparator(":")
613
- scanNext()
614
- if(!parseValue()){handleError(4,[],[2,5])
615
- }} else{handleError(5,[],[2,5])
616
- }
617
- _jsonPath.pop()
618
- return true
619
- }
620
- function parseObject(){onObjectBegin()
621
- scanNext()
622
- let needsComma=false
623
- while(_scanner.getToken()!==2&&_scanner.getToken()!==17){if(_scanner.getToken()===5){if(!needsComma){handleError(4,[],[])
624
- }
625
- onSeparator(",")
626
- scanNext()
627
- if(_scanner.getToken()===2&&allowTrailingComma){break
628
- }} else if(needsComma){handleError(6,[],[])
629
- }
630
- if(!parseProperty()){handleError(4,[],[2,5])
631
- }
632
- needsComma=true
633
- }
634
- onObjectEnd()
635
- if(_scanner.getToken()!==2){handleError(7,[2],[])
636
- } else{scanNext()
637
- }
638
- return true
639
- }
640
- function parseArray(){onArrayBegin()
641
- scanNext()
642
- let isFirstElement=true
643
- let needsComma=false
644
- while(_scanner.getToken()!==4&&_scanner.getToken()!==17){if(_scanner.getToken()===5){if(!needsComma){handleError(4,[],[])
645
- }
646
- onSeparator(",")
647
- scanNext()
648
- if(_scanner.getToken()===4&&allowTrailingComma){break
649
- }} else if(needsComma){handleError(6,[],[])
650
- }
651
- if(isFirstElement){_jsonPath.push(0)
652
- isFirstElement=false
653
- } else{_jsonPath[_jsonPath.length-1]++
654
- }
655
- if(!parseValue()){handleError(4,[],[4,5])
656
- }
657
- needsComma=true
658
- }
659
- onArrayEnd()
660
- if(!isFirstElement){_jsonPath.pop()
661
- }
662
- if(_scanner.getToken()!==4){handleError(8,[4],[])
663
- } else{scanNext()
664
- }
665
- return true
666
- }
667
- function parseValue(){switch(_scanner.getToken()){case 3:return parseArray()
668
- case 1:return parseObject()
669
- case 10:return parseString(true)
670
- default:return parseLiteral()
671
- }}
672
- scanNext()
673
- if(_scanner.getToken()===17){if(options.allowEmptyContent){return true
674
- }
675
- handleError(4,[],[])
676
- return false
677
- }
678
- if(!parseValue()){handleError(4,[],[])
679
- return false
680
- }
681
- if(_scanner.getToken()!==17){handleError(9,[],[])
682
- }
683
- return true
684
- }
685
- function getNodeType(value){switch(typeof value){case "boolean":return "boolean"
686
- case "number":return "number"
687
- case "string":return "string"
688
- case "object":{if(!value){return "null"
689
- } else if(Array.isArray(value)){return "array"
690
- }
691
- return "object"
692
- }
693
- default:return "null"
694
- }}
695
- function setProperty(text,originalPath,value,options){const path=originalPath.slice()
696
- const errors=[]
697
- const root=parseTree(text,errors)
698
- let parent=undefined
699
- let lastSegment=undefined
700
- while(path.length>0){lastSegment=path.pop()
701
- parent=findNodeAtLocation(root,path)
702
- if(parent===undefined&&value!==undefined){if(typeof lastSegment==="string"){value={[lastSegment]:value}} else{value=[value]
703
- }} else{break
704
- }}
705
- if(!parent){if(value===undefined){throw new Error("Can not delete in empty document")
706
- }
707
- return withFormatting(text,{offset:root?root.offset:0,length:root?root.length:0,content:JSON.stringify(value)},options)
708
- } else if(parent.type==="object"&&typeof lastSegment==="string"&&Array.isArray(parent.children)){const existing=findNodeAtLocation(parent,[lastSegment])
709
- if(existing!==undefined){if(value===undefined){if(!existing.parent){throw new Error("Malformed AST")
710
- }
711
- const propertyIndex=parent.children.indexOf(existing.parent)
712
- let removeBegin
713
- let removeEnd=existing.parent.offset + existing.parent.length
714
- if(propertyIndex>0){let previous=parent.children[propertyIndex-1]
715
- removeBegin=previous.offset + previous.length
716
- } else{removeBegin=parent.offset + 1
717
- if(parent.children.length>1){let next=parent.children[1]
718
- removeEnd=next.offset
719
- }}
720
- return withFormatting(text,{offset:removeBegin,length:removeEnd-removeBegin,content:""},options)
721
- } else{return withFormatting(text,{offset:existing.offset,length:existing.length,content:JSON.stringify(value)},options)
722
- }} else{if(value===undefined){return []
723
- }
724
- const newProperty=`${JSON.stringify(lastSegment)}: ${JSON.stringify(value)}`
725
- const index=options.getInsertionIndex?options.getInsertionIndex(parent.children.map((p)=>p.children[0].value)):parent.children.length
726
- let edit
727
- if(index>0){let previous=parent.children[index-1]
728
- edit={offset:previous.offset + previous.length,length:0,content:"," + newProperty}} else if(parent.children.length===0){edit={offset:parent.offset + 1,length:0,content:newProperty}} else{edit={offset:parent.offset + 1,length:0,content:newProperty + ","}}
729
- return withFormatting(text,edit,options)
730
- }} else if(parent.type==="array"&&typeof lastSegment==="number"&&Array.isArray(parent.children)){const insertIndex=lastSegment
731
- if(insertIndex===-1){const newProperty=`${JSON.stringify(value)}`
732
- let edit
733
- if(parent.children.length===0){edit={offset:parent.offset + 1,length:0,content:newProperty}} else{const previous=parent.children[parent.children.length-1]
734
- edit={offset:previous.offset + previous.length,length:0,content:"," + newProperty}}
735
- return withFormatting(text,edit,options)
736
- } else if(value===undefined&&parent.children.length>=0){const removalIndex=lastSegment
737
- const toRemove=parent.children[removalIndex]
738
- let edit
739
- if(parent.children.length===1){edit={offset:parent.offset + 1,length:parent.length-2,content:""}} else if(parent.children.length-1===removalIndex){let previous=parent.children[removalIndex-1]
740
- let offset=previous.offset + previous.length
741
- let parentEndOffset=parent.offset + parent.length
742
- edit={offset,length:parentEndOffset-2-offset,content:""}} else{edit={offset:toRemove.offset,length:parent.children[removalIndex + 1].offset-toRemove.offset,content:""}}
743
- return withFormatting(text,edit,options)
744
- } else if(value!==undefined){let edit
745
- const newProperty=`${JSON.stringify(value)}`
746
- if(!options.isArrayInsertion&&parent.children.length>lastSegment){const toModify=parent.children[lastSegment]
747
- edit={offset:toModify.offset,length:toModify.length,content:newProperty}} else if(parent.children.length===0||lastSegment===0){edit={offset:parent.offset + 1,length:0,content:parent.children.length===0?newProperty:newProperty + ","}} else{const index=lastSegment>parent.children.length?parent.children.length:lastSegment
748
- const previous=parent.children[index-1]
749
- edit={offset:previous.offset + previous.length,length:0,content:"," + newProperty}}
750
- return withFormatting(text,edit,options)
751
- } else{throw new Error(`Can not ${value === undefined ? "remove" : options.isArrayInsertion ? "insert" : "modify"} Array index ${insertIndex} as length is not sufficient`)
752
- }} else{throw new Error(`Can not add ${typeof lastSegment !== "number" ? "index" : "property"} to parent of type ${parent.type}`)
753
- }}
754
- function withFormatting(text,edit,options){if(!options.formattingOptions){return [edit]
755
- }
756
- let newText=applyEdit(text,edit)
757
- let begin=edit.offset
758
- let end=edit.offset + edit.content.length
759
- if(edit.length===0||edit.content.length===0){while(begin>0&&!isEOL(newText,begin-1)){begin--
760
- }
761
- while(end<newText.length&&!isEOL(newText,end)){end++
762
- }}
763
- const edits=format(newText,{offset:begin,length:end-begin},{...options.formattingOptions,keepLines:false})
764
- for(let i=edits.length-1;i>=0; i--){const edit=edits[i]
765
- newText=applyEdit(newText,edit)
766
- begin=Math.min(begin,edit.offset)
767
- end=Math.max(end,edit.offset + edit.length)
768
- end += edit.content.length-edit.length
769
- }
770
- const editLength=text.length-(newText.length-end)-begin
771
- return [{offset:begin,length:editLength,content:newText.substring(begin,end)}]
772
- }
773
- function applyEdit(text,edit){return text.substring(0,edit.offset) + edit.content + text.substring(edit.offset + edit.length)
774
- }
775
- var ScanError;
776
- (function(ScanError){ScanError[ScanError["None"]=0]="None"
777
- ScanError[ScanError["UnexpectedEndOfComment"]=1]="UnexpectedEndOfComment"
778
- ScanError[ScanError["UnexpectedEndOfString"]=2]="UnexpectedEndOfString"
779
- ScanError[ScanError["UnexpectedEndOfNumber"]=3]="UnexpectedEndOfNumber"
780
- ScanError[ScanError["InvalidUnicode"]=4]="InvalidUnicode"
781
- ScanError[ScanError["InvalidEscapeCharacter"]=5]="InvalidEscapeCharacter"
782
- ScanError[ScanError["InvalidCharacter"]=6]="InvalidCharacter"
783
- })(ScanError||(ScanError={}))
784
- var SyntaxKind;
785
- (function(SyntaxKind){SyntaxKind[SyntaxKind["OpenBraceToken"]=1]="OpenBraceToken"
786
- SyntaxKind[SyntaxKind["CloseBraceToken"]=2]="CloseBraceToken"
787
- SyntaxKind[SyntaxKind["OpenBracketToken"]=3]="OpenBracketToken"
788
- SyntaxKind[SyntaxKind["CloseBracketToken"]=4]="CloseBracketToken"
789
- SyntaxKind[SyntaxKind["CommaToken"]=5]="CommaToken"
790
- SyntaxKind[SyntaxKind["ColonToken"]=6]="ColonToken"
791
- SyntaxKind[SyntaxKind["NullKeyword"]=7]="NullKeyword"
792
- SyntaxKind[SyntaxKind["TrueKeyword"]=8]="TrueKeyword"
793
- SyntaxKind[SyntaxKind["FalseKeyword"]=9]="FalseKeyword"
794
- SyntaxKind[SyntaxKind["StringLiteral"]=10]="StringLiteral"
795
- SyntaxKind[SyntaxKind["NumericLiteral"]=11]="NumericLiteral"
796
- SyntaxKind[SyntaxKind["LineCommentTrivia"]=12]="LineCommentTrivia"
797
- SyntaxKind[SyntaxKind["BlockCommentTrivia"]=13]="BlockCommentTrivia"
798
- SyntaxKind[SyntaxKind["LineBreakTrivia"]=14]="LineBreakTrivia"
799
- SyntaxKind[SyntaxKind["Trivia"]=15]="Trivia"
800
- SyntaxKind[SyntaxKind["Unknown"]=16]="Unknown"
801
- SyntaxKind[SyntaxKind["EOF"]=17]="EOF"
802
- })(SyntaxKind||(SyntaxKind={}))
803
- var parseTree2=parseTree
804
- var findNodeAtLocation2=findNodeAtLocation
805
- var ParseErrorCode;
806
- (function(ParseErrorCode){ParseErrorCode[ParseErrorCode["InvalidSymbol"]=1]="InvalidSymbol"
807
- ParseErrorCode[ParseErrorCode["InvalidNumberFormat"]=2]="InvalidNumberFormat"
808
- ParseErrorCode[ParseErrorCode["PropertyNameExpected"]=3]="PropertyNameExpected"
809
- ParseErrorCode[ParseErrorCode["ValueExpected"]=4]="ValueExpected"
810
- ParseErrorCode[ParseErrorCode["ColonExpected"]=5]="ColonExpected"
811
- ParseErrorCode[ParseErrorCode["CommaExpected"]=6]="CommaExpected"
812
- ParseErrorCode[ParseErrorCode["CloseBraceExpected"]=7]="CloseBraceExpected"
813
- ParseErrorCode[ParseErrorCode["CloseBracketExpected"]=8]="CloseBracketExpected"
814
- ParseErrorCode[ParseErrorCode["EndOfFileExpected"]=9]="EndOfFileExpected"
815
- ParseErrorCode[ParseErrorCode["InvalidCommentToken"]=10]="InvalidCommentToken"
816
- ParseErrorCode[ParseErrorCode["UnexpectedEndOfComment"]=11]="UnexpectedEndOfComment"
817
- ParseErrorCode[ParseErrorCode["UnexpectedEndOfString"]=12]="UnexpectedEndOfString"
818
- ParseErrorCode[ParseErrorCode["UnexpectedEndOfNumber"]=13]="UnexpectedEndOfNumber"
819
- ParseErrorCode[ParseErrorCode["InvalidUnicode"]=14]="InvalidUnicode"
820
- ParseErrorCode[ParseErrorCode["InvalidEscapeCharacter"]=15]="InvalidEscapeCharacter"
821
- ParseErrorCode[ParseErrorCode["InvalidCharacter"]=16]="InvalidCharacter"
822
- })(ParseErrorCode||(ParseErrorCode={}))
823
- function modify(text,path,value,options){return setProperty(text,path,value,options)
824
- }
825
- function applyEdits(text,edits){let sortedEdits=edits.slice(0).sort((a,b)=>{const diff=a.offset-b.offset
826
- if(diff===0){return a.length-b.length
827
- }
828
- return diff
829
- })
830
- let lastModifiedOffset=text.length
831
- for(let i=sortedEdits.length-1;i>=0; i--){let e=sortedEdits[i]
832
- if(e.offset + e.length<=lastModifiedOffset){text=applyEdit(text,e)
833
- } else{throw new Error("Overlapping edit")
834
- }
835
- lastModifiedOffset=e.offset
836
- }
837
- return text
838
- }
839
14
  function unique(node,key){const matches=node.children?.filter((property)=>property.children?.[0].value===key)??[]
840
15
  if(matches.length>1)
841
16
  throw new Error(`Duplicate ${key} fields; edit this configuration manually.`)
@@ -845,16 +20,16 @@ throw new Error("The configuration is too large to edit safely.")
845
20
  const prefix=source.startsWith("\uFEFF")?"\uFEFF":""
846
21
  const text=source.slice(prefix.length)
847
22
  const errors=[]
848
- const root=parseTree2(text,errors,{allowTrailingComma:true})
23
+ const root=parseTree(text,errors,{allowTrailingComma:true})
849
24
  if(errors.length>0||root?.type!=="object")
850
25
  throw new Error("The configuration is not a valid JSON/JSONC object.")
851
26
  unique(root,"experimental")
852
- const experimental=findNodeAtLocation2(root,["experimental"])
27
+ const experimental=findNodeAtLocation(root,["experimental"])
853
28
  if(experimental&&experimental.type!=="object")
854
29
  throw new Error("experimental must be an object.")
855
30
  if(experimental)
856
31
  unique(experimental,"todo")
857
- const todo=findNodeAtLocation2(root,["experimental","todo"])
32
+ const todo=findNodeAtLocation(root,["experimental","todo"])
858
33
  if(todo&&todo.type!=="boolean")
859
34
  throw new Error("experimental.todo must be a boolean.")
860
35
  const edits=modify(text,["experimental","todo"],true,{formattingOptions:{insertSpaces:!/^\t/mu.test(source),tabSize:2,eol:source.includes(`\r