typescript-language-server 4.4.1 → 5.0.1
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.
- package/CHANGELOG.md +25 -0
- package/README.md +0 -32
- package/lib/cli.mjs +1338 -539
- package/lib/cli.mjs.map +1 -1
- package/package.json +21 -21
package/lib/cli.mjs
CHANGED
|
@@ -116,7 +116,7 @@ function requireArgument() {
|
|
|
116
116
|
this._name = name;
|
|
117
117
|
break;
|
|
118
118
|
}
|
|
119
|
-
if (this._name.
|
|
119
|
+
if (this._name.endsWith('...')) {
|
|
120
120
|
this.variadic = true;
|
|
121
121
|
this._name = this._name.slice(0, -3);
|
|
122
122
|
}
|
|
@@ -124,11 +124,12 @@ function requireArgument() {
|
|
|
124
124
|
name() {
|
|
125
125
|
return this._name;
|
|
126
126
|
}
|
|
127
|
-
|
|
127
|
+
_collectValue(value, previous) {
|
|
128
128
|
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
129
129
|
return [ value ];
|
|
130
130
|
}
|
|
131
|
-
|
|
131
|
+
previous.push(value);
|
|
132
|
+
return previous;
|
|
132
133
|
}
|
|
133
134
|
default(value, description) {
|
|
134
135
|
this.defaultValue = value;
|
|
@@ -146,7 +147,7 @@ function requireArgument() {
|
|
|
146
147
|
throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(', ')}.`);
|
|
147
148
|
}
|
|
148
149
|
if (this.variadic) {
|
|
149
|
-
return this.
|
|
150
|
+
return this._collectValue(arg, previous);
|
|
150
151
|
}
|
|
151
152
|
return arg;
|
|
152
153
|
};
|
|
@@ -183,10 +184,14 @@ function requireHelp() {
|
|
|
183
184
|
class Help {
|
|
184
185
|
constructor() {
|
|
185
186
|
this.helpWidth = undefined;
|
|
187
|
+
this.minWidthToWrap = 40;
|
|
186
188
|
this.sortSubcommands = false;
|
|
187
189
|
this.sortOptions = false;
|
|
188
190
|
this.showGlobalOptions = false;
|
|
189
191
|
}
|
|
192
|
+
prepareContext(contextOptions) {
|
|
193
|
+
this.helpWidth = this.helpWidth ?? contextOptions.helpWidth ?? 80;
|
|
194
|
+
}
|
|
190
195
|
visibleCommands(cmd) {
|
|
191
196
|
const visibleCommands = cmd.commands.filter(cmd => !cmd._hidden);
|
|
192
197
|
const helpCommand = cmd._getHelpCommand();
|
|
@@ -255,16 +260,16 @@ function requireHelp() {
|
|
|
255
260
|
return argument.name();
|
|
256
261
|
}
|
|
257
262
|
longestSubcommandTermLength(cmd, helper) {
|
|
258
|
-
return helper.visibleCommands(cmd).reduce((max, command) => Math.max(max, helper.subcommandTerm(command)
|
|
263
|
+
return helper.visibleCommands(cmd).reduce((max, command) => Math.max(max, this.displayWidth(helper.styleSubcommandTerm(helper.subcommandTerm(command)))), 0);
|
|
259
264
|
}
|
|
260
265
|
longestOptionTermLength(cmd, helper) {
|
|
261
|
-
return helper.visibleOptions(cmd).reduce((max, option) => Math.max(max, helper.optionTerm(option)
|
|
266
|
+
return helper.visibleOptions(cmd).reduce((max, option) => Math.max(max, this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option)))), 0);
|
|
262
267
|
}
|
|
263
268
|
longestGlobalOptionTermLength(cmd, helper) {
|
|
264
|
-
return helper.visibleGlobalOptions(cmd).reduce((max, option) => Math.max(max, helper.optionTerm(option)
|
|
269
|
+
return helper.visibleGlobalOptions(cmd).reduce((max, option) => Math.max(max, this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option)))), 0);
|
|
265
270
|
}
|
|
266
271
|
longestArgumentTermLength(cmd, helper) {
|
|
267
|
-
return helper.visibleArguments(cmd).reduce((max, argument) => Math.max(max, helper.argumentTerm(argument)
|
|
272
|
+
return helper.visibleArguments(cmd).reduce((max, argument) => Math.max(max, this.displayWidth(helper.styleArgumentTerm(helper.argumentTerm(argument)))), 0);
|
|
268
273
|
}
|
|
269
274
|
commandUsage(cmd) {
|
|
270
275
|
let cmdName = cmd._name;
|
|
@@ -301,7 +306,11 @@ function requireHelp() {
|
|
|
301
306
|
extraInfo.push(`env: ${option.envVar}`);
|
|
302
307
|
}
|
|
303
308
|
if (extraInfo.length > 0) {
|
|
304
|
-
|
|
309
|
+
const extraDescription = `(${extraInfo.join(', ')})`;
|
|
310
|
+
if (option.description) {
|
|
311
|
+
return `${option.description} ${extraDescription}`;
|
|
312
|
+
}
|
|
313
|
+
return extraDescription;
|
|
305
314
|
}
|
|
306
315
|
return option.description;
|
|
307
316
|
}
|
|
@@ -314,77 +323,175 @@ function requireHelp() {
|
|
|
314
323
|
extraInfo.push(`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`);
|
|
315
324
|
}
|
|
316
325
|
if (extraInfo.length > 0) {
|
|
317
|
-
const
|
|
326
|
+
const extraDescription = `(${extraInfo.join(', ')})`;
|
|
318
327
|
if (argument.description) {
|
|
319
|
-
return `${argument.description} ${
|
|
328
|
+
return `${argument.description} ${extraDescription}`;
|
|
320
329
|
}
|
|
321
|
-
return
|
|
330
|
+
return extraDescription;
|
|
322
331
|
}
|
|
323
332
|
return argument.description;
|
|
324
333
|
}
|
|
334
|
+
formatItemList(heading, items, helper) {
|
|
335
|
+
if (items.length === 0) return [];
|
|
336
|
+
return [ helper.styleTitle(heading), ...items, '' ];
|
|
337
|
+
}
|
|
338
|
+
groupItems(unsortedItems, visibleItems, getGroup) {
|
|
339
|
+
const result = new Map;
|
|
340
|
+
unsortedItems.forEach(item => {
|
|
341
|
+
const group = getGroup(item);
|
|
342
|
+
if (!result.has(group)) result.set(group, []);
|
|
343
|
+
});
|
|
344
|
+
visibleItems.forEach(item => {
|
|
345
|
+
const group = getGroup(item);
|
|
346
|
+
if (!result.has(group)) {
|
|
347
|
+
result.set(group, []);
|
|
348
|
+
}
|
|
349
|
+
result.get(group).push(item);
|
|
350
|
+
});
|
|
351
|
+
return result;
|
|
352
|
+
}
|
|
325
353
|
formatHelp(cmd, helper) {
|
|
326
354
|
const termWidth = helper.padWidth(cmd, helper);
|
|
327
|
-
const helpWidth = helper.helpWidth
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
function formatItem(term, description) {
|
|
331
|
-
if (description) {
|
|
332
|
-
const fullText = `${term.padEnd(termWidth + itemSeparatorWidth)}${description}`;
|
|
333
|
-
return helper.wrap(fullText, helpWidth - itemIndentWidth, termWidth + itemSeparatorWidth);
|
|
334
|
-
}
|
|
335
|
-
return term;
|
|
355
|
+
const helpWidth = helper.helpWidth ?? 80;
|
|
356
|
+
function callFormatItem(term, description) {
|
|
357
|
+
return helper.formatItem(term, termWidth, description, helper);
|
|
336
358
|
}
|
|
337
|
-
|
|
338
|
-
return textArray.join('\n').replace(/^/gm, ' '.repeat(itemIndentWidth));
|
|
339
|
-
}
|
|
340
|
-
let output = [ `Usage: ${helper.commandUsage(cmd)}`, '' ];
|
|
359
|
+
let output = [ `${helper.styleTitle('Usage:')} ${helper.styleUsage(helper.commandUsage(cmd))}`, '' ];
|
|
341
360
|
const commandDescription = helper.commandDescription(cmd);
|
|
342
361
|
if (commandDescription.length > 0) {
|
|
343
|
-
output = output.concat([ helper.
|
|
344
|
-
}
|
|
345
|
-
const argumentList = helper.visibleArguments(cmd).map(argument =>
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
output = output.concat([ 'Commands:', formatList(commandList), '' ]);
|
|
362
|
-
}
|
|
362
|
+
output = output.concat([ helper.boxWrap(helper.styleCommandDescription(commandDescription), helpWidth), '' ]);
|
|
363
|
+
}
|
|
364
|
+
const argumentList = helper.visibleArguments(cmd).map(argument => callFormatItem(helper.styleArgumentTerm(helper.argumentTerm(argument)), helper.styleArgumentDescription(helper.argumentDescription(argument))));
|
|
365
|
+
output = output.concat(this.formatItemList('Arguments:', argumentList, helper));
|
|
366
|
+
const optionGroups = this.groupItems(cmd.options, helper.visibleOptions(cmd), option => option.helpGroupHeading ?? 'Options:');
|
|
367
|
+
optionGroups.forEach((options, group) => {
|
|
368
|
+
const optionList = options.map(option => callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option))));
|
|
369
|
+
output = output.concat(this.formatItemList(group, optionList, helper));
|
|
370
|
+
});
|
|
371
|
+
if (helper.showGlobalOptions) {
|
|
372
|
+
const globalOptionList = helper.visibleGlobalOptions(cmd).map(option => callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option))));
|
|
373
|
+
output = output.concat(this.formatItemList('Global Options:', globalOptionList, helper));
|
|
374
|
+
}
|
|
375
|
+
const commandGroups = this.groupItems(cmd.commands, helper.visibleCommands(cmd), sub => sub.helpGroup() || 'Commands:');
|
|
376
|
+
commandGroups.forEach((commands, group) => {
|
|
377
|
+
const commandList = commands.map(sub => callFormatItem(helper.styleSubcommandTerm(helper.subcommandTerm(sub)), helper.styleSubcommandDescription(helper.subcommandDescription(sub))));
|
|
378
|
+
output = output.concat(this.formatItemList(group, commandList, helper));
|
|
379
|
+
});
|
|
363
380
|
return output.join('\n');
|
|
364
381
|
}
|
|
382
|
+
displayWidth(str) {
|
|
383
|
+
return stripColor(str).length;
|
|
384
|
+
}
|
|
385
|
+
styleTitle(str) {
|
|
386
|
+
return str;
|
|
387
|
+
}
|
|
388
|
+
styleUsage(str) {
|
|
389
|
+
return str.split(' ').map(word => {
|
|
390
|
+
if (word === '[options]') return this.styleOptionText(word);
|
|
391
|
+
if (word === '[command]') return this.styleSubcommandText(word);
|
|
392
|
+
if (word[0] === '[' || word[0] === '<') return this.styleArgumentText(word);
|
|
393
|
+
return this.styleCommandText(word);
|
|
394
|
+
}).join(' ');
|
|
395
|
+
}
|
|
396
|
+
styleCommandDescription(str) {
|
|
397
|
+
return this.styleDescriptionText(str);
|
|
398
|
+
}
|
|
399
|
+
styleOptionDescription(str) {
|
|
400
|
+
return this.styleDescriptionText(str);
|
|
401
|
+
}
|
|
402
|
+
styleSubcommandDescription(str) {
|
|
403
|
+
return this.styleDescriptionText(str);
|
|
404
|
+
}
|
|
405
|
+
styleArgumentDescription(str) {
|
|
406
|
+
return this.styleDescriptionText(str);
|
|
407
|
+
}
|
|
408
|
+
styleDescriptionText(str) {
|
|
409
|
+
return str;
|
|
410
|
+
}
|
|
411
|
+
styleOptionTerm(str) {
|
|
412
|
+
return this.styleOptionText(str);
|
|
413
|
+
}
|
|
414
|
+
styleSubcommandTerm(str) {
|
|
415
|
+
return str.split(' ').map(word => {
|
|
416
|
+
if (word === '[options]') return this.styleOptionText(word);
|
|
417
|
+
if (word[0] === '[' || word[0] === '<') return this.styleArgumentText(word);
|
|
418
|
+
return this.styleSubcommandText(word);
|
|
419
|
+
}).join(' ');
|
|
420
|
+
}
|
|
421
|
+
styleArgumentTerm(str) {
|
|
422
|
+
return this.styleArgumentText(str);
|
|
423
|
+
}
|
|
424
|
+
styleOptionText(str) {
|
|
425
|
+
return str;
|
|
426
|
+
}
|
|
427
|
+
styleArgumentText(str) {
|
|
428
|
+
return str;
|
|
429
|
+
}
|
|
430
|
+
styleSubcommandText(str) {
|
|
431
|
+
return str;
|
|
432
|
+
}
|
|
433
|
+
styleCommandText(str) {
|
|
434
|
+
return str;
|
|
435
|
+
}
|
|
365
436
|
padWidth(cmd, helper) {
|
|
366
437
|
return Math.max(helper.longestOptionTermLength(cmd, helper), helper.longestGlobalOptionTermLength(cmd, helper), helper.longestSubcommandTermLength(cmd, helper), helper.longestArgumentTermLength(cmd, helper));
|
|
367
438
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
const
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
const
|
|
376
|
-
const
|
|
377
|
-
const
|
|
378
|
-
const
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
439
|
+
preformatted(str) {
|
|
440
|
+
return /\n[^\S\r\n]/.test(str);
|
|
441
|
+
}
|
|
442
|
+
formatItem(term, termWidth, description, helper) {
|
|
443
|
+
const itemIndent = 2;
|
|
444
|
+
const itemIndentStr = ' '.repeat(itemIndent);
|
|
445
|
+
if (!description) return itemIndentStr + term;
|
|
446
|
+
const paddedTerm = term.padEnd(termWidth + term.length - helper.displayWidth(term));
|
|
447
|
+
const spacerWidth = 2;
|
|
448
|
+
const helpWidth = this.helpWidth ?? 80;
|
|
449
|
+
const remainingWidth = helpWidth - termWidth - spacerWidth - itemIndent;
|
|
450
|
+
let formattedDescription;
|
|
451
|
+
if (remainingWidth < this.minWidthToWrap || helper.preformatted(description)) {
|
|
452
|
+
formattedDescription = description;
|
|
453
|
+
} else {
|
|
454
|
+
const wrappedDescription = helper.boxWrap(description, remainingWidth);
|
|
455
|
+
formattedDescription = wrappedDescription.replace(/\n/g, '\n' + ' '.repeat(termWidth + spacerWidth));
|
|
456
|
+
}
|
|
457
|
+
return itemIndentStr + paddedTerm + ' '.repeat(spacerWidth) + formattedDescription.replace(/\n/g, `\n${itemIndentStr}`);
|
|
458
|
+
}
|
|
459
|
+
boxWrap(str, width) {
|
|
460
|
+
if (width < this.minWidthToWrap) return str;
|
|
461
|
+
const rawLines = str.split(/\r\n|\n/);
|
|
462
|
+
const chunkPattern = /[\s]*[^\s]+/g;
|
|
463
|
+
const wrappedLines = [];
|
|
464
|
+
rawLines.forEach(line => {
|
|
465
|
+
const chunks = line.match(chunkPattern);
|
|
466
|
+
if (chunks === null) {
|
|
467
|
+
wrappedLines.push('');
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
let sumChunks = [ chunks.shift() ];
|
|
471
|
+
let sumWidth = this.displayWidth(sumChunks[0]);
|
|
472
|
+
chunks.forEach(chunk => {
|
|
473
|
+
const visibleWidth = this.displayWidth(chunk);
|
|
474
|
+
if (sumWidth + visibleWidth <= width) {
|
|
475
|
+
sumChunks.push(chunk);
|
|
476
|
+
sumWidth += visibleWidth;
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
wrappedLines.push(sumChunks.join(''));
|
|
480
|
+
const nextChunk = chunk.trimStart();
|
|
481
|
+
sumChunks = [ nextChunk ];
|
|
482
|
+
sumWidth = this.displayWidth(nextChunk);
|
|
483
|
+
});
|
|
484
|
+
wrappedLines.push(sumChunks.join(''));
|
|
485
|
+
});
|
|
486
|
+
return wrappedLines.join('\n');
|
|
385
487
|
}
|
|
386
488
|
}
|
|
489
|
+
function stripColor(str) {
|
|
490
|
+
const sgrPattern = /\x1b\[\d*(;\d*)*m/g;
|
|
491
|
+
return str.replace(sgrPattern, '');
|
|
492
|
+
}
|
|
387
493
|
help.Help = Help;
|
|
494
|
+
help.stripColor = stripColor;
|
|
388
495
|
return help;
|
|
389
496
|
}
|
|
390
497
|
|
|
@@ -420,6 +527,7 @@ function requireOption() {
|
|
|
420
527
|
this.argChoices = undefined;
|
|
421
528
|
this.conflictsWith = [];
|
|
422
529
|
this.implied = undefined;
|
|
530
|
+
this.helpGroupHeading = undefined;
|
|
423
531
|
}
|
|
424
532
|
default(value, description) {
|
|
425
533
|
this.defaultValue = value;
|
|
@@ -460,11 +568,12 @@ function requireOption() {
|
|
|
460
568
|
this.hidden = !!hide;
|
|
461
569
|
return this;
|
|
462
570
|
}
|
|
463
|
-
|
|
571
|
+
_collectValue(value, previous) {
|
|
464
572
|
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
465
573
|
return [ value ];
|
|
466
574
|
}
|
|
467
|
-
|
|
575
|
+
previous.push(value);
|
|
576
|
+
return previous;
|
|
468
577
|
}
|
|
469
578
|
choices(values) {
|
|
470
579
|
this.argChoices = values.slice();
|
|
@@ -473,7 +582,7 @@ function requireOption() {
|
|
|
473
582
|
throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(', ')}.`);
|
|
474
583
|
}
|
|
475
584
|
if (this.variadic) {
|
|
476
|
-
return this.
|
|
585
|
+
return this._collectValue(arg, previous);
|
|
477
586
|
}
|
|
478
587
|
return arg;
|
|
479
588
|
};
|
|
@@ -486,7 +595,14 @@ function requireOption() {
|
|
|
486
595
|
return this.short.replace(/^-/, '');
|
|
487
596
|
}
|
|
488
597
|
attributeName() {
|
|
489
|
-
|
|
598
|
+
if (this.negate) {
|
|
599
|
+
return camelcase(this.name().replace(/^no-/, ''));
|
|
600
|
+
}
|
|
601
|
+
return camelcase(this.name());
|
|
602
|
+
}
|
|
603
|
+
helpGroup(heading) {
|
|
604
|
+
this.helpGroupHeading = heading;
|
|
605
|
+
return this;
|
|
490
606
|
}
|
|
491
607
|
is(arg) {
|
|
492
608
|
return this.short === arg || this.long === arg;
|
|
@@ -527,13 +643,25 @@ function requireOption() {
|
|
|
527
643
|
function splitOptionFlags(flags) {
|
|
528
644
|
let shortFlag;
|
|
529
645
|
let longFlag;
|
|
530
|
-
const
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
if (
|
|
646
|
+
const shortFlagExp = /^-[^-]$/;
|
|
647
|
+
const longFlagExp = /^--[^-]/;
|
|
648
|
+
const flagParts = flags.split(/[ |,]+/).concat('guard');
|
|
649
|
+
if (shortFlagExp.test(flagParts[0])) shortFlag = flagParts.shift();
|
|
650
|
+
if (longFlagExp.test(flagParts[0])) longFlag = flagParts.shift();
|
|
651
|
+
if (!shortFlag && shortFlagExp.test(flagParts[0])) shortFlag = flagParts.shift();
|
|
652
|
+
if (!shortFlag && longFlagExp.test(flagParts[0])) {
|
|
534
653
|
shortFlag = longFlag;
|
|
535
|
-
longFlag =
|
|
654
|
+
longFlag = flagParts.shift();
|
|
655
|
+
}
|
|
656
|
+
if (flagParts[0].startsWith('-')) {
|
|
657
|
+
const unsupportedFlag = flagParts[0];
|
|
658
|
+
const baseError = `option creation failed due to '${unsupportedFlag}' in option flags '${flags}'`;
|
|
659
|
+
if (/^-[^-][^-]/.test(unsupportedFlag)) throw new Error(`${baseError}\n- a short flag is a single dash and a single character\n - either use a single dash and a single character (for a short flag)\n - or use a double dash for a long option (and can have two, like '--ws, --workspace')`);
|
|
660
|
+
if (shortFlagExp.test(unsupportedFlag)) throw new Error(`${baseError}\n- too many short flags`);
|
|
661
|
+
if (longFlagExp.test(unsupportedFlag)) throw new Error(`${baseError}\n- too many long flags`);
|
|
662
|
+
throw new Error(`${baseError}\n- unrecognised flag format`);
|
|
536
663
|
}
|
|
664
|
+
if (shortFlag === undefined && longFlag === undefined) throw new Error(`option creation failed due to no flags found in '${flags}'.`);
|
|
537
665
|
return {
|
|
538
666
|
shortFlag: shortFlag,
|
|
539
667
|
longFlag: longFlag
|
|
@@ -630,7 +758,7 @@ function requireCommand() {
|
|
|
630
758
|
const process = process$1;
|
|
631
759
|
const {Argument: Argument, humanReadableArgName: humanReadableArgName} = requireArgument();
|
|
632
760
|
const {CommanderError: CommanderError} = requireError();
|
|
633
|
-
const {Help: Help} = requireHelp();
|
|
761
|
+
const {Help: Help, stripColor: stripColor} = requireHelp();
|
|
634
762
|
const {Option: Option, DualOptions: DualOptions} = requireOption();
|
|
635
763
|
const {suggestSimilar: suggestSimilar} = requireSuggestSimilar();
|
|
636
764
|
class Command extends EventEmitter {
|
|
@@ -640,7 +768,7 @@ function requireCommand() {
|
|
|
640
768
|
this.options = [];
|
|
641
769
|
this.parent = null;
|
|
642
770
|
this._allowUnknownOption = false;
|
|
643
|
-
this._allowExcessArguments =
|
|
771
|
+
this._allowExcessArguments = false;
|
|
644
772
|
this.registeredArguments = [];
|
|
645
773
|
this._args = this.registeredArguments;
|
|
646
774
|
this.args = [];
|
|
@@ -667,18 +795,25 @@ function requireCommand() {
|
|
|
667
795
|
this._lifeCycleHooks = {};
|
|
668
796
|
this._showHelpAfterError = false;
|
|
669
797
|
this._showSuggestionAfterError = true;
|
|
798
|
+
this._savedState = null;
|
|
670
799
|
this._outputConfiguration = {
|
|
671
800
|
writeOut: str => process.stdout.write(str),
|
|
672
801
|
writeErr: str => process.stderr.write(str),
|
|
802
|
+
outputError: (str, write) => write(str),
|
|
673
803
|
getOutHelpWidth: () => process.stdout.isTTY ? process.stdout.columns : undefined,
|
|
674
804
|
getErrHelpWidth: () => process.stderr.isTTY ? process.stderr.columns : undefined,
|
|
675
|
-
|
|
805
|
+
getOutHasColors: () => useColor() ?? (process.stdout.isTTY && process.stdout.hasColors?.()),
|
|
806
|
+
getErrHasColors: () => useColor() ?? (process.stderr.isTTY && process.stderr.hasColors?.()),
|
|
807
|
+
stripColor: str => stripColor(str)
|
|
676
808
|
};
|
|
677
809
|
this._hidden = false;
|
|
678
810
|
this._helpOption = undefined;
|
|
679
811
|
this._addImplicitHelpCommand = undefined;
|
|
680
812
|
this._helpCommand = undefined;
|
|
681
813
|
this._helpConfiguration = {};
|
|
814
|
+
this._helpGroupHeading = undefined;
|
|
815
|
+
this._defaultCommandGroup = undefined;
|
|
816
|
+
this._defaultOptionGroup = undefined;
|
|
682
817
|
}
|
|
683
818
|
copyInheritedSettings(sourceCommand) {
|
|
684
819
|
this._outputConfiguration = sourceCommand._outputConfiguration;
|
|
@@ -738,7 +873,10 @@ function requireCommand() {
|
|
|
738
873
|
}
|
|
739
874
|
configureOutput(configuration) {
|
|
740
875
|
if (configuration === undefined) return this._outputConfiguration;
|
|
741
|
-
|
|
876
|
+
this._outputConfiguration = {
|
|
877
|
+
...this._outputConfiguration,
|
|
878
|
+
...configuration
|
|
879
|
+
};
|
|
742
880
|
return this;
|
|
743
881
|
}
|
|
744
882
|
showHelpAfterError(displayHelp = true) {
|
|
@@ -765,12 +903,12 @@ function requireCommand() {
|
|
|
765
903
|
createArgument(name, description) {
|
|
766
904
|
return new Argument(name, description);
|
|
767
905
|
}
|
|
768
|
-
argument(name, description,
|
|
906
|
+
argument(name, description, parseArg, defaultValue) {
|
|
769
907
|
const argument = this.createArgument(name, description);
|
|
770
|
-
if (typeof
|
|
771
|
-
argument.default(defaultValue).argParser(
|
|
908
|
+
if (typeof parseArg === 'function') {
|
|
909
|
+
argument.default(defaultValue).argParser(parseArg);
|
|
772
910
|
} else {
|
|
773
|
-
argument.default(
|
|
911
|
+
argument.default(parseArg);
|
|
774
912
|
}
|
|
775
913
|
this.addArgument(argument);
|
|
776
914
|
return this;
|
|
@@ -783,7 +921,7 @@ function requireCommand() {
|
|
|
783
921
|
}
|
|
784
922
|
addArgument(argument) {
|
|
785
923
|
const previousArgument = this.registeredArguments.slice(-1)[0];
|
|
786
|
-
if (previousArgument
|
|
924
|
+
if (previousArgument?.variadic) {
|
|
787
925
|
throw new Error(`only the last argument can be variadic '${previousArgument.name()}'`);
|
|
788
926
|
}
|
|
789
927
|
if (argument.required && argument.defaultValue !== undefined && argument.parseArg === undefined) {
|
|
@@ -795,10 +933,13 @@ function requireCommand() {
|
|
|
795
933
|
helpCommand(enableOrNameAndArgs, description) {
|
|
796
934
|
if (typeof enableOrNameAndArgs === 'boolean') {
|
|
797
935
|
this._addImplicitHelpCommand = enableOrNameAndArgs;
|
|
936
|
+
if (enableOrNameAndArgs && this._defaultCommandGroup) {
|
|
937
|
+
this._initCommandGroup(this._getHelpCommand());
|
|
938
|
+
}
|
|
798
939
|
return this;
|
|
799
940
|
}
|
|
800
|
-
|
|
801
|
-
const [, helpName, helpArgs] =
|
|
941
|
+
const nameAndArgs = enableOrNameAndArgs ?? 'help [command]';
|
|
942
|
+
const [, helpName, helpArgs] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
802
943
|
const helpDescription = description ?? 'display help for command';
|
|
803
944
|
const helpCommand = this.createCommand(helpName);
|
|
804
945
|
helpCommand.helpOption(false);
|
|
@@ -806,6 +947,7 @@ function requireCommand() {
|
|
|
806
947
|
if (helpDescription) helpCommand.description(helpDescription);
|
|
807
948
|
this._addImplicitHelpCommand = true;
|
|
808
949
|
this._helpCommand = helpCommand;
|
|
950
|
+
if (enableOrNameAndArgs || description) this._initCommandGroup(helpCommand);
|
|
809
951
|
return this;
|
|
810
952
|
}
|
|
811
953
|
addHelpCommand(helpCommand, deprecatedDescription) {
|
|
@@ -815,6 +957,7 @@ function requireCommand() {
|
|
|
815
957
|
}
|
|
816
958
|
this._addImplicitHelpCommand = true;
|
|
817
959
|
this._helpCommand = helpCommand;
|
|
960
|
+
this._initCommandGroup(helpCommand);
|
|
818
961
|
return this;
|
|
819
962
|
}
|
|
820
963
|
_getHelpCommand() {
|
|
@@ -895,6 +1038,7 @@ function requireCommand() {
|
|
|
895
1038
|
const matchingFlag = option.long && this._findOption(option.long) ? option.long : option.short;
|
|
896
1039
|
throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'\n- already used by option '${matchingOption.flags}'`);
|
|
897
1040
|
}
|
|
1041
|
+
this._initOptionGroup(option);
|
|
898
1042
|
this.options.push(option);
|
|
899
1043
|
}
|
|
900
1044
|
_registerCommand(command) {
|
|
@@ -905,6 +1049,7 @@ function requireCommand() {
|
|
|
905
1049
|
const newCmd = knownBy(command).join('|');
|
|
906
1050
|
throw new Error(`cannot add command '${newCmd}' as already have command '${existingCmd}'`);
|
|
907
1051
|
}
|
|
1052
|
+
this._initCommandGroup(command);
|
|
908
1053
|
this.commands.push(command);
|
|
909
1054
|
}
|
|
910
1055
|
addOption(option) {
|
|
@@ -927,7 +1072,7 @@ function requireCommand() {
|
|
|
927
1072
|
if (val !== null && option.parseArg) {
|
|
928
1073
|
val = this._callParseArg(option, val, oldValue, invalidValueMessage);
|
|
929
1074
|
} else if (val !== null && option.variadic) {
|
|
930
|
-
val = option.
|
|
1075
|
+
val = option._collectValue(val, oldValue);
|
|
931
1076
|
}
|
|
932
1077
|
if (val == null) {
|
|
933
1078
|
if (option.negate) {
|
|
@@ -1097,15 +1242,55 @@ function requireCommand() {
|
|
|
1097
1242
|
return userArgs;
|
|
1098
1243
|
}
|
|
1099
1244
|
parse(argv, parseOptions) {
|
|
1245
|
+
this._prepareForParse();
|
|
1100
1246
|
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1101
1247
|
this._parseCommand([], userArgs);
|
|
1102
1248
|
return this;
|
|
1103
1249
|
}
|
|
1104
1250
|
async parseAsync(argv, parseOptions) {
|
|
1251
|
+
this._prepareForParse();
|
|
1105
1252
|
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1106
1253
|
await this._parseCommand([], userArgs);
|
|
1107
1254
|
return this;
|
|
1108
1255
|
}
|
|
1256
|
+
_prepareForParse() {
|
|
1257
|
+
if (this._savedState === null) {
|
|
1258
|
+
this.saveStateBeforeParse();
|
|
1259
|
+
} else {
|
|
1260
|
+
this.restoreStateBeforeParse();
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
saveStateBeforeParse() {
|
|
1264
|
+
this._savedState = {
|
|
1265
|
+
_name: this._name,
|
|
1266
|
+
_optionValues: {
|
|
1267
|
+
...this._optionValues
|
|
1268
|
+
},
|
|
1269
|
+
_optionValueSources: {
|
|
1270
|
+
...this._optionValueSources
|
|
1271
|
+
}
|
|
1272
|
+
};
|
|
1273
|
+
}
|
|
1274
|
+
restoreStateBeforeParse() {
|
|
1275
|
+
if (this._storeOptionsAsProperties) throw new Error(`Can not call parse again when storeOptionsAsProperties is true.\n- either make a new Command for each call to parse, or stop storing options as properties`);
|
|
1276
|
+
this._name = this._savedState._name;
|
|
1277
|
+
this._scriptPath = null;
|
|
1278
|
+
this.rawArgs = [];
|
|
1279
|
+
this._optionValues = {
|
|
1280
|
+
...this._savedState._optionValues
|
|
1281
|
+
};
|
|
1282
|
+
this._optionValueSources = {
|
|
1283
|
+
...this._savedState._optionValueSources
|
|
1284
|
+
};
|
|
1285
|
+
this.args = [];
|
|
1286
|
+
this.processedArgs = [];
|
|
1287
|
+
}
|
|
1288
|
+
_checkForMissingExecutable(executableFile, executableDir, subcommandName) {
|
|
1289
|
+
if (fs.existsSync(executableFile)) return;
|
|
1290
|
+
const executableDirMessage = executableDir ? `searched for local subcommand relative to directory '${executableDir}'` : 'no directory for search for local subcommand, use .executableDir() to supply a custom directory';
|
|
1291
|
+
const executableMissing = `'${executableFile}' does not exist\n - if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead\n - if the default executable name is not suitable, use the executableFile option to supply a custom name or path\n - ${executableDirMessage}`;
|
|
1292
|
+
throw new Error(executableMissing);
|
|
1293
|
+
}
|
|
1109
1294
|
_executeSubCommand(subcommand, args) {
|
|
1110
1295
|
args = args.slice();
|
|
1111
1296
|
let launchWithNode = false;
|
|
@@ -1126,7 +1311,7 @@ function requireCommand() {
|
|
|
1126
1311
|
let resolvedScriptPath;
|
|
1127
1312
|
try {
|
|
1128
1313
|
resolvedScriptPath = fs.realpathSync(this._scriptPath);
|
|
1129
|
-
} catch
|
|
1314
|
+
} catch {
|
|
1130
1315
|
resolvedScriptPath = this._scriptPath;
|
|
1131
1316
|
}
|
|
1132
1317
|
executableDir = path.resolve(path.dirname(resolvedScriptPath), executableDir);
|
|
@@ -1156,6 +1341,7 @@ function requireCommand() {
|
|
|
1156
1341
|
});
|
|
1157
1342
|
}
|
|
1158
1343
|
} else {
|
|
1344
|
+
this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
|
|
1159
1345
|
args.unshift(executableFile);
|
|
1160
1346
|
args = incrementNodeInspectorPort(process.execArgv).concat(args);
|
|
1161
1347
|
proc = childProcess.spawn(process.execPath, args, {
|
|
@@ -1183,9 +1369,7 @@ function requireCommand() {
|
|
|
1183
1369
|
});
|
|
1184
1370
|
proc.on('error', err => {
|
|
1185
1371
|
if (err.code === 'ENOENT') {
|
|
1186
|
-
|
|
1187
|
-
const executableMissing = `'${executableFile}' does not exist\n - if '${subcommand._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead\n - if the default executable name is not suitable, use the executableFile option to supply a custom name or path\n - ${executableDirMessage}`;
|
|
1188
|
-
throw new Error(executableMissing);
|
|
1372
|
+
this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
|
|
1189
1373
|
} else if (err.code === 'EACCES') {
|
|
1190
1374
|
throw new Error(`'${executableFile}' not executable`);
|
|
1191
1375
|
}
|
|
@@ -1204,6 +1388,7 @@ function requireCommand() {
|
|
|
1204
1388
|
if (!subCommand) this.help({
|
|
1205
1389
|
error: true
|
|
1206
1390
|
});
|
|
1391
|
+
subCommand._prepareForParse();
|
|
1207
1392
|
let promiseChain;
|
|
1208
1393
|
promiseChain = this._chainOrCallSubCommandHook(promiseChain, subCommand, 'preSubcommand');
|
|
1209
1394
|
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
@@ -1271,7 +1456,7 @@ function requireCommand() {
|
|
|
1271
1456
|
this.processedArgs = processedArgs;
|
|
1272
1457
|
}
|
|
1273
1458
|
_chainOrCall(promise, fn) {
|
|
1274
|
-
if (promise
|
|
1459
|
+
if (promise?.then && typeof promise.then === 'function') {
|
|
1275
1460
|
return promise.then(() => fn());
|
|
1276
1461
|
}
|
|
1277
1462
|
return fn();
|
|
@@ -1349,7 +1534,7 @@ function requireCommand() {
|
|
|
1349
1534
|
promiseChain = this._chainOrCallHooks(promiseChain, 'postAction');
|
|
1350
1535
|
return promiseChain;
|
|
1351
1536
|
}
|
|
1352
|
-
if (this.parent
|
|
1537
|
+
if (this.parent?.listenerCount(commandEvent)) {
|
|
1353
1538
|
checkForUnknownOptions();
|
|
1354
1539
|
this._processArguments();
|
|
1355
1540
|
this.parent.emit(commandEvent, operands, unknown);
|
|
@@ -1412,23 +1597,29 @@ function requireCommand() {
|
|
|
1412
1597
|
cmd._checkForConflictingLocalOptions();
|
|
1413
1598
|
});
|
|
1414
1599
|
}
|
|
1415
|
-
parseOptions(
|
|
1600
|
+
parseOptions(args) {
|
|
1416
1601
|
const operands = [];
|
|
1417
1602
|
const unknown = [];
|
|
1418
1603
|
let dest = operands;
|
|
1419
|
-
const args = argv.slice();
|
|
1420
1604
|
function maybeOption(arg) {
|
|
1421
1605
|
return arg.length > 1 && arg[0] === '-';
|
|
1422
1606
|
}
|
|
1607
|
+
const negativeNumberArg = arg => {
|
|
1608
|
+
if (!/^-\d*\.?\d+(e[+-]?\d+)?$/.test(arg)) return false;
|
|
1609
|
+
return !this._getCommandAndAncestors().some(cmd => cmd.options.map(opt => opt.short).some(short => /^-\d$/.test(short)));
|
|
1610
|
+
};
|
|
1423
1611
|
let activeVariadicOption = null;
|
|
1424
|
-
|
|
1425
|
-
|
|
1612
|
+
let activeGroup = null;
|
|
1613
|
+
let i = 0;
|
|
1614
|
+
while (i < args.length || activeGroup) {
|
|
1615
|
+
const arg = activeGroup ?? args[i++];
|
|
1616
|
+
activeGroup = null;
|
|
1426
1617
|
if (arg === '--') {
|
|
1427
1618
|
if (dest === unknown) dest.push(arg);
|
|
1428
|
-
dest.push(...args);
|
|
1619
|
+
dest.push(...args.slice(i));
|
|
1429
1620
|
break;
|
|
1430
1621
|
}
|
|
1431
|
-
if (activeVariadicOption && !maybeOption(arg)) {
|
|
1622
|
+
if (activeVariadicOption && (!maybeOption(arg) || negativeNumberArg(arg))) {
|
|
1432
1623
|
this.emit(`option:${activeVariadicOption.name()}`, arg);
|
|
1433
1624
|
continue;
|
|
1434
1625
|
}
|
|
@@ -1437,13 +1628,13 @@ function requireCommand() {
|
|
|
1437
1628
|
const option = this._findOption(arg);
|
|
1438
1629
|
if (option) {
|
|
1439
1630
|
if (option.required) {
|
|
1440
|
-
const value = args
|
|
1631
|
+
const value = args[i++];
|
|
1441
1632
|
if (value === undefined) this.optionMissingArgument(option);
|
|
1442
1633
|
this.emit(`option:${option.name()}`, value);
|
|
1443
1634
|
} else if (option.optional) {
|
|
1444
1635
|
let value = null;
|
|
1445
|
-
if (args.length
|
|
1446
|
-
value = args
|
|
1636
|
+
if (i < args.length && (!maybeOption(args[i]) || negativeNumberArg(args[i]))) {
|
|
1637
|
+
value = args[i++];
|
|
1447
1638
|
}
|
|
1448
1639
|
this.emit(`option:${option.name()}`, value);
|
|
1449
1640
|
} else {
|
|
@@ -1460,7 +1651,7 @@ function requireCommand() {
|
|
|
1460
1651
|
this.emit(`option:${option.name()}`, arg.slice(2));
|
|
1461
1652
|
} else {
|
|
1462
1653
|
this.emit(`option:${option.name()}`);
|
|
1463
|
-
|
|
1654
|
+
activeGroup = `-${arg.slice(2)}`;
|
|
1464
1655
|
}
|
|
1465
1656
|
continue;
|
|
1466
1657
|
}
|
|
@@ -1473,27 +1664,24 @@ function requireCommand() {
|
|
|
1473
1664
|
continue;
|
|
1474
1665
|
}
|
|
1475
1666
|
}
|
|
1476
|
-
if (maybeOption(arg)) {
|
|
1667
|
+
if (dest === operands && maybeOption(arg) && !(this.commands.length === 0 && negativeNumberArg(arg))) {
|
|
1477
1668
|
dest = unknown;
|
|
1478
1669
|
}
|
|
1479
1670
|
if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
|
|
1480
1671
|
if (this._findCommand(arg)) {
|
|
1481
1672
|
operands.push(arg);
|
|
1482
|
-
|
|
1673
|
+
unknown.push(...args.slice(i));
|
|
1483
1674
|
break;
|
|
1484
1675
|
} else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
|
|
1485
|
-
operands.push(arg);
|
|
1486
|
-
if (args.length > 0) operands.push(...args);
|
|
1676
|
+
operands.push(arg, ...args.slice(i));
|
|
1487
1677
|
break;
|
|
1488
1678
|
} else if (this._defaultCommandName) {
|
|
1489
|
-
unknown.push(arg);
|
|
1490
|
-
if (args.length > 0) unknown.push(...args);
|
|
1679
|
+
unknown.push(arg, ...args.slice(i));
|
|
1491
1680
|
break;
|
|
1492
1681
|
}
|
|
1493
1682
|
}
|
|
1494
1683
|
if (this._passThroughOptions) {
|
|
1495
|
-
dest.push(arg);
|
|
1496
|
-
if (args.length > 0) dest.push(...args);
|
|
1684
|
+
dest.push(arg, ...args.slice(i));
|
|
1497
1685
|
break;
|
|
1498
1686
|
}
|
|
1499
1687
|
dest.push(arg);
|
|
@@ -1704,6 +1892,27 @@ function requireCommand() {
|
|
|
1704
1892
|
this._name = str;
|
|
1705
1893
|
return this;
|
|
1706
1894
|
}
|
|
1895
|
+
helpGroup(heading) {
|
|
1896
|
+
if (heading === undefined) return this._helpGroupHeading ?? '';
|
|
1897
|
+
this._helpGroupHeading = heading;
|
|
1898
|
+
return this;
|
|
1899
|
+
}
|
|
1900
|
+
commandsGroup(heading) {
|
|
1901
|
+
if (heading === undefined) return this._defaultCommandGroup ?? '';
|
|
1902
|
+
this._defaultCommandGroup = heading;
|
|
1903
|
+
return this;
|
|
1904
|
+
}
|
|
1905
|
+
optionsGroup(heading) {
|
|
1906
|
+
if (heading === undefined) return this._defaultOptionGroup ?? '';
|
|
1907
|
+
this._defaultOptionGroup = heading;
|
|
1908
|
+
return this;
|
|
1909
|
+
}
|
|
1910
|
+
_initOptionGroup(option) {
|
|
1911
|
+
if (this._defaultOptionGroup && !option.helpGroupHeading) option.helpGroup(this._defaultOptionGroup);
|
|
1912
|
+
}
|
|
1913
|
+
_initCommandGroup(cmd) {
|
|
1914
|
+
if (this._defaultCommandGroup && !cmd.helpGroup()) cmd.helpGroup(this._defaultCommandGroup);
|
|
1915
|
+
}
|
|
1707
1916
|
nameFromFilename(filename) {
|
|
1708
1917
|
this._name = path.basename(filename, path.extname(filename));
|
|
1709
1918
|
return this;
|
|
@@ -1715,25 +1924,41 @@ function requireCommand() {
|
|
|
1715
1924
|
}
|
|
1716
1925
|
helpInformation(contextOptions) {
|
|
1717
1926
|
const helper = this.createHelp();
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1927
|
+
const context = this._getOutputContext(contextOptions);
|
|
1928
|
+
helper.prepareContext({
|
|
1929
|
+
error: context.error,
|
|
1930
|
+
helpWidth: context.helpWidth,
|
|
1931
|
+
outputHasColors: context.hasColors
|
|
1932
|
+
});
|
|
1933
|
+
const text = helper.formatHelp(this, helper);
|
|
1934
|
+
if (context.hasColors) return text;
|
|
1935
|
+
return this._outputConfiguration.stripColor(text);
|
|
1722
1936
|
}
|
|
1723
|
-
|
|
1937
|
+
_getOutputContext(contextOptions) {
|
|
1724
1938
|
contextOptions = contextOptions || {};
|
|
1725
|
-
const
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
let
|
|
1729
|
-
if (
|
|
1730
|
-
|
|
1939
|
+
const error = !!contextOptions.error;
|
|
1940
|
+
let baseWrite;
|
|
1941
|
+
let hasColors;
|
|
1942
|
+
let helpWidth;
|
|
1943
|
+
if (error) {
|
|
1944
|
+
baseWrite = str => this._outputConfiguration.writeErr(str);
|
|
1945
|
+
hasColors = this._outputConfiguration.getErrHasColors();
|
|
1946
|
+
helpWidth = this._outputConfiguration.getErrHelpWidth();
|
|
1731
1947
|
} else {
|
|
1732
|
-
|
|
1948
|
+
baseWrite = str => this._outputConfiguration.writeOut(str);
|
|
1949
|
+
hasColors = this._outputConfiguration.getOutHasColors();
|
|
1950
|
+
helpWidth = this._outputConfiguration.getOutHelpWidth();
|
|
1733
1951
|
}
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1952
|
+
const write = str => {
|
|
1953
|
+
if (!hasColors) str = this._outputConfiguration.stripColor(str);
|
|
1954
|
+
return baseWrite(str);
|
|
1955
|
+
};
|
|
1956
|
+
return {
|
|
1957
|
+
error: error,
|
|
1958
|
+
write: write,
|
|
1959
|
+
hasColors: hasColors,
|
|
1960
|
+
helpWidth: helpWidth
|
|
1961
|
+
};
|
|
1737
1962
|
}
|
|
1738
1963
|
outputHelp(contextOptions) {
|
|
1739
1964
|
let deprecatedCallback;
|
|
@@ -1741,35 +1966,44 @@ function requireCommand() {
|
|
|
1741
1966
|
deprecatedCallback = contextOptions;
|
|
1742
1967
|
contextOptions = undefined;
|
|
1743
1968
|
}
|
|
1744
|
-
const
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1969
|
+
const outputContext = this._getOutputContext(contextOptions);
|
|
1970
|
+
const eventContext = {
|
|
1971
|
+
error: outputContext.error,
|
|
1972
|
+
write: outputContext.write,
|
|
1973
|
+
command: this
|
|
1974
|
+
};
|
|
1975
|
+
this._getCommandAndAncestors().reverse().forEach(command => command.emit('beforeAllHelp', eventContext));
|
|
1976
|
+
this.emit('beforeHelp', eventContext);
|
|
1977
|
+
let helpInformation = this.helpInformation({
|
|
1978
|
+
error: outputContext.error
|
|
1979
|
+
});
|
|
1748
1980
|
if (deprecatedCallback) {
|
|
1749
1981
|
helpInformation = deprecatedCallback(helpInformation);
|
|
1750
1982
|
if (typeof helpInformation !== 'string' && !Buffer.isBuffer(helpInformation)) {
|
|
1751
1983
|
throw new Error('outputHelp callback must return a string or a Buffer');
|
|
1752
1984
|
}
|
|
1753
1985
|
}
|
|
1754
|
-
|
|
1986
|
+
outputContext.write(helpInformation);
|
|
1755
1987
|
if (this._getHelpOption()?.long) {
|
|
1756
1988
|
this.emit(this._getHelpOption().long);
|
|
1757
1989
|
}
|
|
1758
|
-
this.emit('afterHelp',
|
|
1759
|
-
this._getCommandAndAncestors().forEach(command => command.emit('afterAllHelp',
|
|
1990
|
+
this.emit('afterHelp', eventContext);
|
|
1991
|
+
this._getCommandAndAncestors().forEach(command => command.emit('afterAllHelp', eventContext));
|
|
1760
1992
|
}
|
|
1761
1993
|
helpOption(flags, description) {
|
|
1762
1994
|
if (typeof flags === 'boolean') {
|
|
1763
1995
|
if (flags) {
|
|
1764
|
-
this._helpOption
|
|
1996
|
+
if (this._helpOption === null) this._helpOption = undefined;
|
|
1997
|
+
if (this._defaultOptionGroup) {
|
|
1998
|
+
this._initOptionGroup(this._getHelpOption());
|
|
1999
|
+
}
|
|
1765
2000
|
} else {
|
|
1766
2001
|
this._helpOption = null;
|
|
1767
2002
|
}
|
|
1768
2003
|
return this;
|
|
1769
2004
|
}
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
this._helpOption = this.createOption(flags, description);
|
|
2005
|
+
this._helpOption = this.createOption(flags ?? '-h, --help', description ?? 'display help for command');
|
|
2006
|
+
if (flags || description) this._initOptionGroup(this._helpOption);
|
|
1773
2007
|
return this;
|
|
1774
2008
|
}
|
|
1775
2009
|
_getHelpOption() {
|
|
@@ -1780,11 +2014,12 @@ function requireCommand() {
|
|
|
1780
2014
|
}
|
|
1781
2015
|
addHelpOption(option) {
|
|
1782
2016
|
this._helpOption = option;
|
|
2017
|
+
this._initOptionGroup(option);
|
|
1783
2018
|
return this;
|
|
1784
2019
|
}
|
|
1785
2020
|
help(contextOptions) {
|
|
1786
2021
|
this.outputHelp(contextOptions);
|
|
1787
|
-
let exitCode = process.exitCode
|
|
2022
|
+
let exitCode = Number(process.exitCode ?? 0);
|
|
1788
2023
|
if (exitCode === 0 && contextOptions && typeof contextOptions !== 'function' && contextOptions.error) {
|
|
1789
2024
|
exitCode = 1;
|
|
1790
2025
|
}
|
|
@@ -1850,7 +2085,13 @@ function requireCommand() {
|
|
|
1850
2085
|
return arg;
|
|
1851
2086
|
});
|
|
1852
2087
|
}
|
|
2088
|
+
function useColor() {
|
|
2089
|
+
if (process.env.NO_COLOR || process.env.FORCE_COLOR === '0' || process.env.FORCE_COLOR === 'false') return false;
|
|
2090
|
+
if (process.env.FORCE_COLOR || process.env.CLICOLOR_FORCE !== undefined) return true;
|
|
2091
|
+
return undefined;
|
|
2092
|
+
}
|
|
1853
2093
|
command.Command = Command;
|
|
2094
|
+
command.useColor = useColor;
|
|
1854
2095
|
return command;
|
|
1855
2096
|
}
|
|
1856
2097
|
|
|
@@ -12728,7 +12969,7 @@ function requireStat() {
|
|
|
12728
12969
|
return checkParentPathsSync(src, srcStat, destParent, funcName);
|
|
12729
12970
|
}
|
|
12730
12971
|
function areIdentical(srcStat, destStat) {
|
|
12731
|
-
return destStat.ino && destStat.dev && destStat.ino === srcStat.ino && destStat.dev === srcStat.dev;
|
|
12972
|
+
return destStat.ino !== undefined && destStat.dev !== undefined && destStat.ino === srcStat.ino && destStat.dev === srcStat.dev;
|
|
12732
12973
|
}
|
|
12733
12974
|
function isSrcSubdir(src, dest) {
|
|
12734
12975
|
const srcArr = path.resolve(src).split(path.sep).filter(i => i);
|
|
@@ -12749,6 +12990,28 @@ function requireStat() {
|
|
|
12749
12990
|
return stat;
|
|
12750
12991
|
}
|
|
12751
12992
|
|
|
12993
|
+
var async;
|
|
12994
|
+
|
|
12995
|
+
var hasRequiredAsync;
|
|
12996
|
+
|
|
12997
|
+
function requireAsync() {
|
|
12998
|
+
if (hasRequiredAsync) return async;
|
|
12999
|
+
hasRequiredAsync = 1;
|
|
13000
|
+
async function asyncIteratorConcurrentProcess(iterator, fn) {
|
|
13001
|
+
const promises = [];
|
|
13002
|
+
for await (const item of iterator) {
|
|
13003
|
+
promises.push(fn(item).then(() => null, err => err ?? new Error('unknown error')));
|
|
13004
|
+
}
|
|
13005
|
+
await Promise.all(promises.map(promise => promise.then(possibleErr => {
|
|
13006
|
+
if (possibleErr !== null) throw possibleErr;
|
|
13007
|
+
})));
|
|
13008
|
+
}
|
|
13009
|
+
async = {
|
|
13010
|
+
asyncIteratorConcurrentProcess: asyncIteratorConcurrentProcess
|
|
13011
|
+
};
|
|
13012
|
+
return async;
|
|
13013
|
+
}
|
|
13014
|
+
|
|
12752
13015
|
var copy_1;
|
|
12753
13016
|
|
|
12754
13017
|
var hasRequiredCopy$1;
|
|
@@ -12762,6 +13025,7 @@ function requireCopy$1() {
|
|
|
12762
13025
|
const {pathExists: pathExists} = requirePathExists();
|
|
12763
13026
|
const {utimesMillis: utimesMillis} = requireUtimes();
|
|
12764
13027
|
const stat = requireStat();
|
|
13028
|
+
const {asyncIteratorConcurrentProcess: asyncIteratorConcurrentProcess} = requireAsync();
|
|
12765
13029
|
async function copy(src, dest, opts = {}) {
|
|
12766
13030
|
if (typeof opts === 'function') {
|
|
12767
13031
|
opts = {
|
|
@@ -12829,17 +13093,15 @@ function requireCopy$1() {
|
|
|
12829
13093
|
if (!destStat) {
|
|
12830
13094
|
await fs.mkdir(dest);
|
|
12831
13095
|
}
|
|
12832
|
-
|
|
12833
|
-
for await (const item of await fs.opendir(src)) {
|
|
13096
|
+
await asyncIteratorConcurrentProcess(await fs.opendir(src), async item => {
|
|
12834
13097
|
const srcItem = path.join(src, item.name);
|
|
12835
13098
|
const destItem = path.join(dest, item.name);
|
|
12836
|
-
|
|
12837
|
-
|
|
12838
|
-
|
|
12839
|
-
|
|
12840
|
-
}
|
|
12841
|
-
}
|
|
12842
|
-
await Promise.all(promises);
|
|
13099
|
+
const include = await runFilter(srcItem, destItem, opts);
|
|
13100
|
+
if (include) {
|
|
13101
|
+
const {destStat: destStat} = await stat.checkPaths(srcItem, destItem, 'copy', opts);
|
|
13102
|
+
await getStatsAndPerformCopy(destStat, srcItem, destItem, opts);
|
|
13103
|
+
}
|
|
13104
|
+
});
|
|
12843
13105
|
if (!destStat) {
|
|
12844
13106
|
await fs.chmod(dest, srcStat.mode);
|
|
12845
13107
|
}
|
|
@@ -13431,12 +13693,12 @@ function requireUtils() {
|
|
|
13431
13693
|
return utils;
|
|
13432
13694
|
}
|
|
13433
13695
|
|
|
13434
|
-
var
|
|
13696
|
+
var jsonfile$1;
|
|
13435
13697
|
|
|
13436
13698
|
var hasRequiredJsonfile$1;
|
|
13437
13699
|
|
|
13438
13700
|
function requireJsonfile$1() {
|
|
13439
|
-
if (hasRequiredJsonfile$1) return
|
|
13701
|
+
if (hasRequiredJsonfile$1) return jsonfile$1;
|
|
13440
13702
|
hasRequiredJsonfile$1 = 1;
|
|
13441
13703
|
let _fs;
|
|
13442
13704
|
try {
|
|
@@ -13502,14 +13764,13 @@ function requireJsonfile$1() {
|
|
|
13502
13764
|
const str = stringify(obj, options);
|
|
13503
13765
|
return fs.writeFileSync(file, str, options);
|
|
13504
13766
|
}
|
|
13505
|
-
|
|
13767
|
+
jsonfile$1 = {
|
|
13506
13768
|
readFile: readFile,
|
|
13507
13769
|
readFileSync: readFileSync,
|
|
13508
13770
|
writeFile: writeFile,
|
|
13509
13771
|
writeFileSync: writeFileSync
|
|
13510
13772
|
};
|
|
13511
|
-
|
|
13512
|
-
return jsonfile_1;
|
|
13773
|
+
return jsonfile$1;
|
|
13513
13774
|
}
|
|
13514
13775
|
|
|
13515
13776
|
var jsonfile;
|
|
@@ -16908,6 +17169,8 @@ API.v500 = API.fromSimpleString('5.0.0');
|
|
|
16908
17169
|
|
|
16909
17170
|
API.v510 = API.fromSimpleString('5.1.0');
|
|
16910
17171
|
|
|
17172
|
+
API.v520 = API.fromSimpleString('5.2.0');
|
|
17173
|
+
|
|
16911
17174
|
API.v540 = API.fromSimpleString('5.4.0');
|
|
16912
17175
|
|
|
16913
17176
|
function equals$1(a, b, itemEquals = (a, b) => a === b) {
|
|
@@ -17949,7 +18212,7 @@ class SingleTsServer {
|
|
|
17949
18212
|
tryCancelRequest(seq, command) {
|
|
17950
18213
|
try {
|
|
17951
18214
|
if (this._requestQueue.tryDeletePendingRequest(seq)) {
|
|
17952
|
-
this.logTrace(`Canceled request with sequence number ${seq}`);
|
|
18215
|
+
this.logTrace(`Canceled pending request with sequence number ${seq}`);
|
|
17953
18216
|
return true;
|
|
17954
18217
|
}
|
|
17955
18218
|
if (this._requestCanceller.tryCancelOngoingRequest(seq)) {
|
|
@@ -19063,7 +19326,8 @@ class TsClient {
|
|
|
19063
19326
|
executions[0].catch(err => this.fatalError(command, err));
|
|
19064
19327
|
}
|
|
19065
19328
|
if (command === CommandTypes.UpdateOpen) {
|
|
19066
|
-
|
|
19329
|
+
const executionsWithResults = executions.filter(e => e !== undefined);
|
|
19330
|
+
Promise.all(executionsWithResults).then(() => {
|
|
19067
19331
|
this.loadingIndicator.reset();
|
|
19068
19332
|
});
|
|
19069
19333
|
}
|
|
@@ -19133,30 +19397,73 @@ class TsClient {
|
|
|
19133
19397
|
}
|
|
19134
19398
|
}
|
|
19135
19399
|
|
|
19136
|
-
const pDebounce = (
|
|
19400
|
+
const pDebounce = (function_, wait, options = {}) => {
|
|
19137
19401
|
if (!Number.isFinite(wait)) {
|
|
19138
19402
|
throw new TypeError('Expected `wait` to be a finite number');
|
|
19139
19403
|
}
|
|
19140
19404
|
let leadingValue;
|
|
19141
19405
|
let timeout;
|
|
19142
19406
|
let resolveList = [];
|
|
19407
|
+
let rejectList = [];
|
|
19408
|
+
const onAbort = () => {
|
|
19409
|
+
clearTimeout(timeout);
|
|
19410
|
+
timeout = null;
|
|
19411
|
+
try {
|
|
19412
|
+
options.signal?.throwIfAborted();
|
|
19413
|
+
} catch (error) {
|
|
19414
|
+
for (const reject of rejectList) {
|
|
19415
|
+
reject(error);
|
|
19416
|
+
}
|
|
19417
|
+
resolveList = [];
|
|
19418
|
+
rejectList = [];
|
|
19419
|
+
}
|
|
19420
|
+
};
|
|
19143
19421
|
return function(...arguments_) {
|
|
19144
|
-
return new Promise(resolve => {
|
|
19422
|
+
return new Promise((resolve, reject) => {
|
|
19423
|
+
try {
|
|
19424
|
+
options.signal?.throwIfAborted();
|
|
19425
|
+
} catch (error) {
|
|
19426
|
+
reject(error);
|
|
19427
|
+
return;
|
|
19428
|
+
}
|
|
19145
19429
|
const shouldCallNow = options.before && !timeout;
|
|
19146
19430
|
clearTimeout(timeout);
|
|
19147
|
-
timeout = setTimeout(() => {
|
|
19431
|
+
timeout = setTimeout(async () => {
|
|
19148
19432
|
timeout = null;
|
|
19149
|
-
const
|
|
19150
|
-
|
|
19151
|
-
resolve(result);
|
|
19152
|
-
}
|
|
19433
|
+
const currentResolveList = resolveList;
|
|
19434
|
+
const currentRejectList = rejectList;
|
|
19153
19435
|
resolveList = [];
|
|
19436
|
+
rejectList = [];
|
|
19437
|
+
try {
|
|
19438
|
+
const result = options.before ? leadingValue : await function_.apply(this, arguments_);
|
|
19439
|
+
for (const resolveFunction of currentResolveList) {
|
|
19440
|
+
resolveFunction(result);
|
|
19441
|
+
}
|
|
19442
|
+
} catch (error) {
|
|
19443
|
+
for (const rejectFunction of currentRejectList) {
|
|
19444
|
+
rejectFunction(error);
|
|
19445
|
+
}
|
|
19446
|
+
}
|
|
19447
|
+
leadingValue = undefined;
|
|
19448
|
+
options.signal?.removeEventListener('abort', onAbort);
|
|
19154
19449
|
}, wait);
|
|
19155
19450
|
if (shouldCallNow) {
|
|
19156
|
-
|
|
19157
|
-
|
|
19451
|
+
(async () => {
|
|
19452
|
+
try {
|
|
19453
|
+
leadingValue = await function_.apply(this, arguments_);
|
|
19454
|
+
resolve(leadingValue);
|
|
19455
|
+
} catch (error) {
|
|
19456
|
+
reject(error);
|
|
19457
|
+
}
|
|
19458
|
+
})();
|
|
19158
19459
|
} else {
|
|
19159
19460
|
resolveList.push(resolve);
|
|
19461
|
+
rejectList.push(reject);
|
|
19462
|
+
if (options.signal && resolveList.length === 1) {
|
|
19463
|
+
options.signal.addEventListener('abort', onAbort, {
|
|
19464
|
+
once: true
|
|
19465
|
+
});
|
|
19466
|
+
}
|
|
19160
19467
|
}
|
|
19161
19468
|
});
|
|
19162
19469
|
};
|
|
@@ -19499,7 +19806,7 @@ class FileDiagnostics {
|
|
|
19499
19806
|
}
|
|
19500
19807
|
}
|
|
19501
19808
|
|
|
19502
|
-
class
|
|
19809
|
+
class DiagnosticsManager {
|
|
19503
19810
|
constructor(publishDiagnostics, client, features, logger) {
|
|
19504
19811
|
this.publishDiagnostics = publishDiagnostics;
|
|
19505
19812
|
this.client = client;
|
|
@@ -19616,8 +19923,6 @@ class TSServerRequestCommand {
|
|
|
19616
19923
|
TSServerRequestCommand.id = 'typescript.tsserverRequest';
|
|
19617
19924
|
|
|
19618
19925
|
const Commands = {
|
|
19619
|
-
APPLY_WORKSPACE_EDIT: '_typescript.applyWorkspaceEdit',
|
|
19620
|
-
APPLY_CODE_ACTION: '_typescript.applyCodeAction',
|
|
19621
19926
|
APPLY_REFACTORING: '_typescript.applyRefactoring',
|
|
19622
19927
|
CONFIGURE_PLUGIN: '_typescript.configurePlugin',
|
|
19623
19928
|
ORGANIZE_IMPORTS: '_typescript.organizeImports',
|
|
@@ -20440,43 +20745,41 @@ function toTsTriggerReason(context) {
|
|
|
20440
20745
|
}
|
|
20441
20746
|
}
|
|
20442
20747
|
|
|
20443
|
-
|
|
20444
|
-
if (!response?.body) {
|
|
20445
|
-
return [];
|
|
20446
|
-
}
|
|
20447
|
-
return response.body.map(fix => mainExports$2.CodeAction.create(fix.description, {
|
|
20448
|
-
title: fix.description,
|
|
20449
|
-
command: Commands.APPLY_WORKSPACE_EDIT,
|
|
20450
|
-
arguments: [ {
|
|
20451
|
-
documentChanges: fix.changes.map(c => toTextDocumentEdit(c, client))
|
|
20452
|
-
} ]
|
|
20453
|
-
}, mainExports$2.CodeActionKind.QuickFix));
|
|
20454
|
-
}
|
|
20748
|
+
var CodeActionKind$1;
|
|
20455
20749
|
|
|
20456
|
-
function
|
|
20457
|
-
|
|
20458
|
-
|
|
20459
|
-
|
|
20750
|
+
(function(CodeActionKind) {
|
|
20751
|
+
CodeActionKind.RefactorMove = 'refactor.move';
|
|
20752
|
+
})(CodeActionKind$1 || (CodeActionKind$1 = {}));
|
|
20753
|
+
|
|
20754
|
+
function provideRefactors(refactors, args, features) {
|
|
20460
20755
|
const actions = [];
|
|
20461
|
-
for (const
|
|
20462
|
-
if (
|
|
20463
|
-
actions.push(asSelectRefactoring(
|
|
20756
|
+
for (const refactor of refactors) {
|
|
20757
|
+
if (refactor.inlineable === false) {
|
|
20758
|
+
actions.push(asSelectRefactoring(refactor, args));
|
|
20464
20759
|
} else {
|
|
20465
|
-
const relevantActions =
|
|
20760
|
+
const relevantActions = refactor.actions.filter(action => {
|
|
20761
|
+
if (action.notApplicableReason && !features.codeActionDisabledSupport) {
|
|
20762
|
+
return false;
|
|
20763
|
+
}
|
|
20764
|
+
if (action.isInteractive && (!features.moveToFileCodeActionSupport || action.name !== 'Move to file')) {
|
|
20765
|
+
return false;
|
|
20766
|
+
}
|
|
20767
|
+
return true;
|
|
20768
|
+
});
|
|
20466
20769
|
for (const action of relevantActions) {
|
|
20467
|
-
actions.push(asApplyRefactoring(action,
|
|
20770
|
+
actions.push(asApplyRefactoring(action, refactor, args));
|
|
20468
20771
|
}
|
|
20469
20772
|
}
|
|
20470
20773
|
}
|
|
20471
20774
|
return actions;
|
|
20472
20775
|
}
|
|
20473
20776
|
|
|
20474
|
-
function asSelectRefactoring(
|
|
20475
|
-
return mainExports$2.CodeAction.create(
|
|
20777
|
+
function asSelectRefactoring(refactor, args) {
|
|
20778
|
+
return mainExports$2.CodeAction.create(refactor.description, mainExports$2.Command.create(refactor.description, Commands.SELECT_REFACTORING, refactor, args), mainExports$2.CodeActionKind.Refactor);
|
|
20476
20779
|
}
|
|
20477
20780
|
|
|
20478
|
-
function asApplyRefactoring(action,
|
|
20479
|
-
const codeAction = mainExports$2.CodeAction.create(action.description, asKind(
|
|
20781
|
+
function asApplyRefactoring(action, refactor, args) {
|
|
20782
|
+
const codeAction = mainExports$2.CodeAction.create(action.description, asKind(action));
|
|
20480
20783
|
if (action.notApplicableReason) {
|
|
20481
20784
|
codeAction.disabled = {
|
|
20482
20785
|
reason: action.notApplicableReason
|
|
@@ -20484,20 +20787,46 @@ function asApplyRefactoring(action, info, args) {
|
|
|
20484
20787
|
} else {
|
|
20485
20788
|
codeAction.command = mainExports$2.Command.create(action.description, Commands.APPLY_REFACTORING, {
|
|
20486
20789
|
...args,
|
|
20487
|
-
refactor:
|
|
20790
|
+
refactor: refactor.name,
|
|
20488
20791
|
action: action.name
|
|
20489
20792
|
});
|
|
20490
20793
|
}
|
|
20491
20794
|
return codeAction;
|
|
20492
20795
|
}
|
|
20493
20796
|
|
|
20494
|
-
function asKind(
|
|
20495
|
-
if (
|
|
20797
|
+
function asKind(action) {
|
|
20798
|
+
if (action.kind) {
|
|
20799
|
+
return action.kind;
|
|
20800
|
+
}
|
|
20801
|
+
if (action.name.startsWith('function_')) {
|
|
20496
20802
|
return `${mainExports$2.CodeActionKind.RefactorExtract}.function`;
|
|
20497
|
-
}
|
|
20803
|
+
}
|
|
20804
|
+
if (action.name.startsWith('constant_')) {
|
|
20498
20805
|
return `${mainExports$2.CodeActionKind.RefactorExtract}.constant`;
|
|
20499
|
-
}
|
|
20500
|
-
|
|
20806
|
+
}
|
|
20807
|
+
if (action.name.startsWith('Extract to type alias')) {
|
|
20808
|
+
return `${mainExports$2.CodeActionKind.RefactorExtract}.type`;
|
|
20809
|
+
}
|
|
20810
|
+
if (action.name.startsWith('Extract to interface')) {
|
|
20811
|
+
return `${mainExports$2.CodeActionKind.RefactorExtract}.interface`;
|
|
20812
|
+
}
|
|
20813
|
+
if (action.name.startsWith('Move to file')) {
|
|
20814
|
+
return `${CodeActionKind$1.RefactorMove}.file`;
|
|
20815
|
+
}
|
|
20816
|
+
if (action.name.startsWith('Move to a new file')) {
|
|
20817
|
+
return `${CodeActionKind$1.RefactorMove}.newFile`;
|
|
20818
|
+
}
|
|
20819
|
+
if (action.name.startsWith('Convert namespace import') || action.name.startsWith('Convert named imports')) {
|
|
20820
|
+
return `${mainExports$2.CodeActionKind.RefactorRewrite}.import`;
|
|
20821
|
+
}
|
|
20822
|
+
if (action.name.startsWith('Convert default export') || action.name.startsWith('Convert named export')) {
|
|
20823
|
+
return `${mainExports$2.CodeActionKind.RefactorRewrite}.export`;
|
|
20824
|
+
}
|
|
20825
|
+
if (action.name.startsWith('Convert parameters to destructured object')) {
|
|
20826
|
+
return `${mainExports$2.CodeActionKind.RefactorRewrite}.parameters.toDestructured`;
|
|
20827
|
+
}
|
|
20828
|
+
if (action.name.startsWith('Generate \'get\' and \'set\' accessors')) {
|
|
20829
|
+
return `${mainExports$2.CodeActionKind.RefactorRewrite}.property.generateAccessors`;
|
|
20501
20830
|
}
|
|
20502
20831
|
return mainExports$2.CodeActionKind.Refactor;
|
|
20503
20832
|
}
|
|
@@ -21161,235 +21490,54 @@ class FileConfigurationManager {
|
|
|
21161
21490
|
}
|
|
21162
21491
|
}
|
|
21163
21492
|
|
|
21164
|
-
|
|
21165
|
-
|
|
21166
|
-
|
|
21167
|
-
|
|
21168
|
-
const incorrectlyImplementsInterface = new Set([ 2420 ]);
|
|
21169
|
-
|
|
21170
|
-
const cannotFindName = new Set([ 2552, 2304 ]);
|
|
21171
|
-
|
|
21172
|
-
const asyncOnlyAllowedInAsyncFunctions = new Set([ 1308 ]);
|
|
21173
|
-
|
|
21174
|
-
const awaitInSyncFunction = 'fixAwaitInSyncFunction';
|
|
21175
|
-
|
|
21176
|
-
const classIncorrectlyImplementsInterface = 'fixClassIncorrectlyImplementsInterface';
|
|
21177
|
-
|
|
21178
|
-
const unreachableCode = 'fixUnreachableCode';
|
|
21493
|
+
function escapeRegExp(text) {
|
|
21494
|
+
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
|
|
21495
|
+
}
|
|
21179
21496
|
|
|
21180
|
-
|
|
21497
|
+
var CodeLensType;
|
|
21181
21498
|
|
|
21182
|
-
|
|
21499
|
+
(function(CodeLensType) {
|
|
21500
|
+
CodeLensType[CodeLensType['Reference'] = 0] = 'Reference';
|
|
21501
|
+
CodeLensType[CodeLensType['Implementation'] = 1] = 'Implementation';
|
|
21502
|
+
})(CodeLensType || (CodeLensType = {}));
|
|
21183
21503
|
|
|
21184
|
-
|
|
21185
|
-
|
|
21186
|
-
|
|
21187
|
-
|
|
21188
|
-
|
|
21189
|
-
|
|
21190
|
-
|
|
21191
|
-
|
|
21192
|
-
|
|
21193
|
-
|
|
21194
|
-
|
|
21195
|
-
|
|
21196
|
-
|
|
21197
|
-
|
|
21198
|
-
|
|
21199
|
-
|
|
21200
|
-
if (fix) {
|
|
21201
|
-
edits.push(...fix.changes.map(change => toTextDocumentEdit(change, client)));
|
|
21202
|
-
break;
|
|
21203
|
-
}
|
|
21504
|
+
class TypeScriptBaseCodeLensProvider {
|
|
21505
|
+
constructor(client, cachedResponse, fileConfigurationManager) {
|
|
21506
|
+
this.client = client;
|
|
21507
|
+
this.cachedResponse = cachedResponse;
|
|
21508
|
+
this.fileConfigurationManager = fileConfigurationManager;
|
|
21509
|
+
}
|
|
21510
|
+
async provideCodeLenses(document, token) {
|
|
21511
|
+
const configuration = this.fileConfigurationManager.getWorkspacePreferencesForFile(document);
|
|
21512
|
+
if (this.type === CodeLensType.Implementation && !configuration.implementationsCodeLens?.enabled || this.type === CodeLensType.Reference && !configuration.referencesCodeLens?.enabled) {
|
|
21513
|
+
return [];
|
|
21514
|
+
}
|
|
21515
|
+
const response = await this.cachedResponse.execute(document, () => this.client.execute(CommandTypes.NavTree, {
|
|
21516
|
+
file: document.filepath
|
|
21517
|
+
}, token));
|
|
21518
|
+
if (response.type !== 'response') {
|
|
21519
|
+
return [];
|
|
21204
21520
|
}
|
|
21521
|
+
const referenceableSpans = [];
|
|
21522
|
+
response.body?.childItems?.forEach(item => this.walkNavTree(document, item, undefined, referenceableSpans));
|
|
21523
|
+
return referenceableSpans.map(span => mainExports.CodeLens.create(span, {
|
|
21524
|
+
uri: document.uri.toString(),
|
|
21525
|
+
type: this.type
|
|
21526
|
+
}));
|
|
21205
21527
|
}
|
|
21206
|
-
|
|
21207
|
-
|
|
21208
|
-
|
|
21209
|
-
|
|
21210
|
-
const edits = [];
|
|
21211
|
-
for (const diagnostic of diagnostics) {
|
|
21212
|
-
for (const {codes: codes, fixName: fixName} of fixes) {
|
|
21213
|
-
if (!codes.has(diagnostic.code)) {
|
|
21214
|
-
continue;
|
|
21215
|
-
}
|
|
21216
|
-
const args = {
|
|
21217
|
-
...Range.toFileRangeRequestArgs(file, diagnostic.range),
|
|
21218
|
-
errorCodes: [ +diagnostic.code ]
|
|
21219
|
-
};
|
|
21220
|
-
const response = await client.execute(CommandTypes.GetCodeFixes, args);
|
|
21221
|
-
if (response.type !== 'response' || !response.body?.length) {
|
|
21222
|
-
continue;
|
|
21223
|
-
}
|
|
21224
|
-
const fix = response.body?.find(fix => fix.fixName === fixName);
|
|
21225
|
-
if (!fix) {
|
|
21226
|
-
continue;
|
|
21227
|
-
}
|
|
21228
|
-
if (!fix.fixId) {
|
|
21229
|
-
edits.push(...fix.changes.map(change => toTextDocumentEdit(change, client)));
|
|
21230
|
-
return edits;
|
|
21231
|
-
}
|
|
21232
|
-
const combinedArgs = {
|
|
21233
|
-
scope: {
|
|
21234
|
-
type: 'file',
|
|
21235
|
-
args: {
|
|
21236
|
-
file: file
|
|
21237
|
-
}
|
|
21238
|
-
},
|
|
21239
|
-
fixId: fix.fixId
|
|
21240
|
-
};
|
|
21241
|
-
const combinedResponse = await client.execute(CommandTypes.GetCombinedCodeFix, combinedArgs);
|
|
21242
|
-
if (combinedResponse.type !== 'response' || !combinedResponse.body) {
|
|
21243
|
-
return edits;
|
|
21244
|
-
}
|
|
21245
|
-
edits.push(...combinedResponse.body.changes.map(change => toTextDocumentEdit(change, client)));
|
|
21246
|
-
return edits;
|
|
21528
|
+
walkNavTree(document, item, parent, results) {
|
|
21529
|
+
const range = this.extractSymbol(document, item, parent);
|
|
21530
|
+
if (range) {
|
|
21531
|
+
results.push(range);
|
|
21247
21532
|
}
|
|
21533
|
+
item.childItems?.forEach(child => this.walkNavTree(document, child, item, results));
|
|
21248
21534
|
}
|
|
21249
|
-
return edits;
|
|
21250
21535
|
}
|
|
21251
21536
|
|
|
21252
|
-
|
|
21253
|
-
|
|
21254
|
-
|
|
21255
|
-
|
|
21256
|
-
super(...arguments);
|
|
21257
|
-
this.title = 'Fix all';
|
|
21258
|
-
}
|
|
21259
|
-
async build(client, file, diagnostics) {
|
|
21260
|
-
const edits = [];
|
|
21261
|
-
edits.push(...await buildIndividualFixes([ {
|
|
21262
|
-
codes: incorrectlyImplementsInterface,
|
|
21263
|
-
fixName: classIncorrectlyImplementsInterface
|
|
21264
|
-
}, {
|
|
21265
|
-
codes: asyncOnlyAllowedInAsyncFunctions,
|
|
21266
|
-
fixName: awaitInSyncFunction
|
|
21267
|
-
} ], client, file, diagnostics));
|
|
21268
|
-
edits.push(...await buildCombinedFix([ {
|
|
21269
|
-
codes: unreachableCode$1,
|
|
21270
|
-
fixName: unreachableCode
|
|
21271
|
-
} ], client, file, diagnostics));
|
|
21272
|
-
if (!edits.length) {
|
|
21273
|
-
return null;
|
|
21274
|
-
}
|
|
21275
|
-
return mainExports$2.CodeAction.create(this.title, {
|
|
21276
|
-
documentChanges: edits
|
|
21277
|
-
}, SourceFixAll.kind.value);
|
|
21278
|
-
}
|
|
21279
|
-
}
|
|
21280
|
-
|
|
21281
|
-
SourceFixAll.kind = CodeActionKind.SourceFixAllTs;
|
|
21282
|
-
|
|
21283
|
-
class SourceRemoveUnused extends SourceAction {
|
|
21284
|
-
constructor() {
|
|
21285
|
-
super(...arguments);
|
|
21286
|
-
this.title = 'Remove all unused code';
|
|
21287
|
-
}
|
|
21288
|
-
async build(client, file, diagnostics) {
|
|
21289
|
-
const edits = await buildCombinedFix([ {
|
|
21290
|
-
codes: variableDeclaredButNeverUsed,
|
|
21291
|
-
fixName: unusedIdentifier
|
|
21292
|
-
} ], client, file, diagnostics);
|
|
21293
|
-
if (!edits.length) {
|
|
21294
|
-
return null;
|
|
21295
|
-
}
|
|
21296
|
-
return mainExports$2.CodeAction.create(this.title, {
|
|
21297
|
-
documentChanges: edits
|
|
21298
|
-
}, SourceRemoveUnused.kind.value);
|
|
21299
|
-
}
|
|
21300
|
-
}
|
|
21301
|
-
|
|
21302
|
-
SourceRemoveUnused.kind = CodeActionKind.SourceRemoveUnusedTs;
|
|
21303
|
-
|
|
21304
|
-
class SourceAddMissingImports extends SourceAction {
|
|
21305
|
-
constructor() {
|
|
21306
|
-
super(...arguments);
|
|
21307
|
-
this.title = 'Add all missing imports';
|
|
21308
|
-
}
|
|
21309
|
-
async build(client, file, diagnostics) {
|
|
21310
|
-
const edits = await buildCombinedFix([ {
|
|
21311
|
-
codes: cannotFindName,
|
|
21312
|
-
fixName: fixImport
|
|
21313
|
-
} ], client, file, diagnostics);
|
|
21314
|
-
if (!edits.length) {
|
|
21315
|
-
return null;
|
|
21316
|
-
}
|
|
21317
|
-
return mainExports$2.CodeAction.create(this.title, {
|
|
21318
|
-
documentChanges: edits
|
|
21319
|
-
}, SourceAddMissingImports.kind.value);
|
|
21320
|
-
}
|
|
21321
|
-
}
|
|
21322
|
-
|
|
21323
|
-
SourceAddMissingImports.kind = CodeActionKind.SourceAddMissingImportsTs;
|
|
21324
|
-
|
|
21325
|
-
class TypeScriptAutoFixProvider {
|
|
21326
|
-
static get kinds() {
|
|
21327
|
-
return TypeScriptAutoFixProvider.kindProviders.map(provider => provider.kind);
|
|
21328
|
-
}
|
|
21329
|
-
constructor(client) {
|
|
21330
|
-
this.client = client;
|
|
21331
|
-
}
|
|
21332
|
-
async provideCodeActions(kinds, file, diagnostics) {
|
|
21333
|
-
const results = [];
|
|
21334
|
-
for (const provider of TypeScriptAutoFixProvider.kindProviders) {
|
|
21335
|
-
if (kinds.some(kind => kind.contains(provider.kind))) {
|
|
21336
|
-
results.push((new provider).build(this.client, file, diagnostics));
|
|
21337
|
-
}
|
|
21338
|
-
}
|
|
21339
|
-
return (await Promise.all(results)).flatMap(result => result || []);
|
|
21340
|
-
}
|
|
21341
|
-
}
|
|
21342
|
-
|
|
21343
|
-
TypeScriptAutoFixProvider.kindProviders = [ SourceFixAll, SourceRemoveUnused, SourceAddMissingImports ];
|
|
21344
|
-
|
|
21345
|
-
function escapeRegExp(text) {
|
|
21346
|
-
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
|
|
21347
|
-
}
|
|
21348
|
-
|
|
21349
|
-
var CodeLensType;
|
|
21350
|
-
|
|
21351
|
-
(function(CodeLensType) {
|
|
21352
|
-
CodeLensType[CodeLensType['Reference'] = 0] = 'Reference';
|
|
21353
|
-
CodeLensType[CodeLensType['Implementation'] = 1] = 'Implementation';
|
|
21354
|
-
})(CodeLensType || (CodeLensType = {}));
|
|
21355
|
-
|
|
21356
|
-
class TypeScriptBaseCodeLensProvider {
|
|
21357
|
-
constructor(client, cachedResponse, fileConfigurationManager) {
|
|
21358
|
-
this.client = client;
|
|
21359
|
-
this.cachedResponse = cachedResponse;
|
|
21360
|
-
this.fileConfigurationManager = fileConfigurationManager;
|
|
21361
|
-
}
|
|
21362
|
-
async provideCodeLenses(document, token) {
|
|
21363
|
-
const configuration = this.fileConfigurationManager.getWorkspacePreferencesForFile(document);
|
|
21364
|
-
if (this.type === CodeLensType.Implementation && !configuration.implementationsCodeLens?.enabled || this.type === CodeLensType.Reference && !configuration.referencesCodeLens?.enabled) {
|
|
21365
|
-
return [];
|
|
21366
|
-
}
|
|
21367
|
-
const response = await this.cachedResponse.execute(document, () => this.client.execute(CommandTypes.NavTree, {
|
|
21368
|
-
file: document.filepath
|
|
21369
|
-
}, token));
|
|
21370
|
-
if (response.type !== 'response') {
|
|
21371
|
-
return [];
|
|
21372
|
-
}
|
|
21373
|
-
const referenceableSpans = [];
|
|
21374
|
-
response.body?.childItems?.forEach(item => this.walkNavTree(document, item, undefined, referenceableSpans));
|
|
21375
|
-
return referenceableSpans.map(span => mainExports.CodeLens.create(span, {
|
|
21376
|
-
uri: document.uri.toString(),
|
|
21377
|
-
type: this.type
|
|
21378
|
-
}));
|
|
21379
|
-
}
|
|
21380
|
-
walkNavTree(document, item, parent, results) {
|
|
21381
|
-
const range = this.extractSymbol(document, item, parent);
|
|
21382
|
-
if (range) {
|
|
21383
|
-
results.push(range);
|
|
21384
|
-
}
|
|
21385
|
-
item.childItems?.forEach(child => this.walkNavTree(document, child, item, results));
|
|
21386
|
-
}
|
|
21387
|
-
}
|
|
21388
|
-
|
|
21389
|
-
TypeScriptBaseCodeLensProvider.cancelledCommand = {
|
|
21390
|
-
title: '',
|
|
21391
|
-
command: ''
|
|
21392
|
-
};
|
|
21537
|
+
TypeScriptBaseCodeLensProvider.cancelledCommand = {
|
|
21538
|
+
title: '',
|
|
21539
|
+
command: ''
|
|
21540
|
+
};
|
|
21393
21541
|
|
|
21394
21542
|
TypeScriptBaseCodeLensProvider.errorCommand = {
|
|
21395
21543
|
title: 'Could not determine references',
|
|
@@ -21998,85 +22146,31 @@ var libExports = requireLib();
|
|
|
21998
22146
|
|
|
21999
22147
|
const which = getDefaultExportFromCjs(libExports);
|
|
22000
22148
|
|
|
22001
|
-
const
|
|
22002
|
-
directory: 'isDirectory',
|
|
22003
|
-
file: 'isFile'
|
|
22004
|
-
};
|
|
22005
|
-
|
|
22006
|
-
function checkType(type) {
|
|
22007
|
-
if (Object.hasOwnProperty.call(typeMappings, type)) {
|
|
22008
|
-
return;
|
|
22009
|
-
}
|
|
22010
|
-
throw new Error(`Invalid type specified: ${type}`);
|
|
22011
|
-
}
|
|
22012
|
-
|
|
22013
|
-
const matchType = (type, stat) => stat[typeMappings[type]]();
|
|
22014
|
-
|
|
22015
|
-
const toPath$1 = urlOrPath => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
|
|
22149
|
+
const toPath = urlOrPath => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
|
|
22016
22150
|
|
|
22017
|
-
function
|
|
22018
|
-
|
|
22019
|
-
|
|
22020
|
-
|
|
22021
|
-
|
|
22151
|
+
function findUpSync(name, {cwd: cwd = process$1.cwd(), type: type = 'file', stopAt: stopAt} = {}) {
|
|
22152
|
+
let directory = path__default.resolve(toPath(cwd) ?? '');
|
|
22153
|
+
const {root: root} = path__default.parse(directory);
|
|
22154
|
+
stopAt = path__default.resolve(directory, toPath(stopAt) ?? root);
|
|
22155
|
+
const isAbsoluteName = path__default.isAbsolute(name);
|
|
22156
|
+
while (directory) {
|
|
22157
|
+
const filePath = isAbsoluteName ? name : path__default.join(directory, name);
|
|
22022
22158
|
try {
|
|
22023
|
-
const
|
|
22159
|
+
const stats = fs$2.statSync(filePath, {
|
|
22024
22160
|
throwIfNoEntry: false
|
|
22025
22161
|
});
|
|
22026
|
-
if (
|
|
22027
|
-
|
|
22028
|
-
}
|
|
22029
|
-
if (matchType(type, stat)) {
|
|
22030
|
-
return path_;
|
|
22162
|
+
if (type === 'file' && stats?.isFile() || type === 'directory' && stats?.isDirectory()) {
|
|
22163
|
+
return filePath;
|
|
22031
22164
|
}
|
|
22032
22165
|
} catch {}
|
|
22033
|
-
|
|
22034
|
-
}
|
|
22035
|
-
|
|
22036
|
-
const toPath = urlOrPath => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
|
|
22037
|
-
|
|
22038
|
-
const findUpStop = Symbol('findUpStop');
|
|
22039
|
-
|
|
22040
|
-
function findUpMultipleSync(name, options = {}) {
|
|
22041
|
-
let directory = path__default.resolve(toPath(options.cwd) || '');
|
|
22042
|
-
const {root: root} = path__default.parse(directory);
|
|
22043
|
-
const stopAt = options.stopAt || root;
|
|
22044
|
-
const limit = options.limit || Number.POSITIVE_INFINITY;
|
|
22045
|
-
const paths = [ name ].flat();
|
|
22046
|
-
const runMatcher = locateOptions => {
|
|
22047
|
-
{
|
|
22048
|
-
return locatePathSync(paths, locateOptions);
|
|
22049
|
-
}
|
|
22050
|
-
};
|
|
22051
|
-
const matches = [];
|
|
22052
|
-
while (true) {
|
|
22053
|
-
const foundPath = runMatcher({
|
|
22054
|
-
...options,
|
|
22055
|
-
cwd: directory
|
|
22056
|
-
});
|
|
22057
|
-
if (foundPath === findUpStop) {
|
|
22058
|
-
break;
|
|
22059
|
-
}
|
|
22060
|
-
if (foundPath) {
|
|
22061
|
-
matches.push(path__default.resolve(directory, foundPath));
|
|
22062
|
-
}
|
|
22063
|
-
if (directory === stopAt || matches.length >= limit) {
|
|
22166
|
+
if (directory === stopAt || directory === root) {
|
|
22064
22167
|
break;
|
|
22065
22168
|
}
|
|
22066
22169
|
directory = path__default.dirname(directory);
|
|
22067
22170
|
}
|
|
22068
|
-
return matches;
|
|
22069
22171
|
}
|
|
22070
22172
|
|
|
22071
|
-
function
|
|
22072
|
-
const matches = findUpMultipleSync(name, {
|
|
22073
|
-
...options,
|
|
22074
|
-
limit: 1
|
|
22075
|
-
});
|
|
22076
|
-
return matches[0];
|
|
22077
|
-
}
|
|
22078
|
-
|
|
22079
|
-
function pkgUpSync({cwd: cwd} = {}) {
|
|
22173
|
+
function packageUpSync({cwd: cwd = process$1.cwd()} = {}) {
|
|
22080
22174
|
return findUpSync('package.json', {
|
|
22081
22175
|
cwd: cwd
|
|
22082
22176
|
});
|
|
@@ -22203,7 +22297,7 @@ class TypeScriptVersionProvider {
|
|
|
22203
22297
|
this.logger.log(`Resolved directory path from a file path: ${resolvedPath}`);
|
|
22204
22298
|
}
|
|
22205
22299
|
try {
|
|
22206
|
-
const packageJsonPath =
|
|
22300
|
+
const packageJsonPath = packageUpSync({
|
|
22207
22301
|
cwd: resolvedPath
|
|
22208
22302
|
});
|
|
22209
22303
|
this.logger.log(`Resolved package.json location: "${packageJsonPath}"`);
|
|
@@ -22240,12 +22334,732 @@ class TypeScriptVersionProvider {
|
|
|
22240
22334
|
}
|
|
22241
22335
|
}
|
|
22242
22336
|
|
|
22337
|
+
class CommandManager {
|
|
22338
|
+
constructor() {
|
|
22339
|
+
this.commands = new Map;
|
|
22340
|
+
}
|
|
22341
|
+
dispose() {
|
|
22342
|
+
this.commands.clear();
|
|
22343
|
+
}
|
|
22344
|
+
register(command) {
|
|
22345
|
+
const entry = this.commands.get(command.id);
|
|
22346
|
+
if (!entry) {
|
|
22347
|
+
this.commands.set(command.id, command);
|
|
22348
|
+
}
|
|
22349
|
+
}
|
|
22350
|
+
async handle(commandId, ...args) {
|
|
22351
|
+
const entry = this.commands.get(commandId);
|
|
22352
|
+
if (entry) {
|
|
22353
|
+
await entry.execute(...args);
|
|
22354
|
+
return true;
|
|
22355
|
+
}
|
|
22356
|
+
return false;
|
|
22357
|
+
}
|
|
22358
|
+
}
|
|
22359
|
+
|
|
22360
|
+
const variableDeclaredButNeverUsed = new Set([ 6196, 6133 ]);
|
|
22361
|
+
|
|
22362
|
+
const unreachableCode$1 = new Set([ 7027 ]);
|
|
22363
|
+
|
|
22364
|
+
const incorrectlyImplementsInterface = new Set([ 2420 ]);
|
|
22365
|
+
|
|
22366
|
+
const cannotFindName = new Set([ 2552, 2304 ]);
|
|
22367
|
+
|
|
22368
|
+
const asyncOnlyAllowedInAsyncFunctions = new Set([ 1308 ]);
|
|
22369
|
+
|
|
22370
|
+
const addMissingAwait = 'addMissingAwait';
|
|
22371
|
+
|
|
22372
|
+
const addMissingNewOperator = 'addMissingNewOperator';
|
|
22373
|
+
|
|
22374
|
+
const addMissingOverride = 'fixOverrideModifier';
|
|
22375
|
+
|
|
22376
|
+
const annotateWithTypeFromJSDoc = 'annotateWithTypeFromJSDoc';
|
|
22377
|
+
|
|
22378
|
+
const awaitInSyncFunction = 'fixAwaitInSyncFunction';
|
|
22379
|
+
|
|
22380
|
+
const classDoesntImplementInheritedAbstractMember = 'fixClassDoesntImplementInheritedAbstractMember';
|
|
22381
|
+
|
|
22382
|
+
const classIncorrectlyImplementsInterface = 'fixClassIncorrectlyImplementsInterface';
|
|
22383
|
+
|
|
22384
|
+
const constructorForDerivedNeedSuperCall = 'constructorForDerivedNeedSuperCall';
|
|
22385
|
+
|
|
22386
|
+
const extendsInterfaceBecomesImplements = 'extendsInterfaceBecomesImplements';
|
|
22387
|
+
|
|
22388
|
+
const fixImport = 'import';
|
|
22389
|
+
|
|
22390
|
+
const forgottenThisPropertyAccess = 'forgottenThisPropertyAccess';
|
|
22391
|
+
|
|
22392
|
+
const removeUnnecessaryAwait = 'removeUnnecessaryAwait';
|
|
22393
|
+
|
|
22394
|
+
const spelling = 'spelling';
|
|
22395
|
+
|
|
22396
|
+
const unreachableCode = 'fixUnreachableCode';
|
|
22397
|
+
|
|
22398
|
+
const unusedIdentifier = 'unusedIdentifier';
|
|
22399
|
+
|
|
22400
|
+
class TsCodeAction {
|
|
22401
|
+
constructor(title, kind) {
|
|
22402
|
+
this.title = title;
|
|
22403
|
+
this.kind = kind;
|
|
22404
|
+
}
|
|
22405
|
+
toLspCodeAction() {
|
|
22406
|
+
const codeAction = mainExports$2.CodeAction.create(this.title, this.kind);
|
|
22407
|
+
if (this.command !== undefined) {
|
|
22408
|
+
codeAction.command = this.command;
|
|
22409
|
+
}
|
|
22410
|
+
if (this.diagnostics !== undefined) {
|
|
22411
|
+
codeAction.diagnostics = this.diagnostics;
|
|
22412
|
+
}
|
|
22413
|
+
if (this.disabled !== undefined) {
|
|
22414
|
+
codeAction.disabled = this.disabled;
|
|
22415
|
+
}
|
|
22416
|
+
if (this.edit !== undefined) {
|
|
22417
|
+
codeAction.edit = this.edit;
|
|
22418
|
+
}
|
|
22419
|
+
if (this.isPreferred !== undefined) {
|
|
22420
|
+
codeAction.isPreferred = this.isPreferred;
|
|
22421
|
+
}
|
|
22422
|
+
return codeAction;
|
|
22423
|
+
}
|
|
22424
|
+
}
|
|
22425
|
+
|
|
22426
|
+
async function buildIndividualFixes(fixes, client, file, diagnostics, token) {
|
|
22427
|
+
const documentChanges = [];
|
|
22428
|
+
for (const diagnostic of diagnostics) {
|
|
22429
|
+
for (const {codes: codes, fixName: fixName} of fixes) {
|
|
22430
|
+
if (token.isCancellationRequested) {
|
|
22431
|
+
return;
|
|
22432
|
+
}
|
|
22433
|
+
if (!codes.has(diagnostic.code)) {
|
|
22434
|
+
continue;
|
|
22435
|
+
}
|
|
22436
|
+
const args = {
|
|
22437
|
+
...Range.toFileRangeRequestArgs(file, diagnostic.range),
|
|
22438
|
+
errorCodes: [ +diagnostic.code ]
|
|
22439
|
+
};
|
|
22440
|
+
const response = await client.execute(CommandTypes.GetCodeFixes, args, token);
|
|
22441
|
+
if (response.type !== 'response') {
|
|
22442
|
+
continue;
|
|
22443
|
+
}
|
|
22444
|
+
const fix = response.body?.find(fix => fix.fixName === fixName);
|
|
22445
|
+
if (fix) {
|
|
22446
|
+
documentChanges.push(...fix.changes.map(change => toTextDocumentEdit(change, client)));
|
|
22447
|
+
break;
|
|
22448
|
+
}
|
|
22449
|
+
}
|
|
22450
|
+
}
|
|
22451
|
+
return {
|
|
22452
|
+
documentChanges: documentChanges
|
|
22453
|
+
};
|
|
22454
|
+
}
|
|
22455
|
+
|
|
22456
|
+
async function buildCombinedFix(fixes, client, file, diagnostics, token) {
|
|
22457
|
+
for (const diagnostic of diagnostics) {
|
|
22458
|
+
for (const {codes: codes, fixName: fixName} of fixes) {
|
|
22459
|
+
if (token.isCancellationRequested) {
|
|
22460
|
+
return;
|
|
22461
|
+
}
|
|
22462
|
+
if (!codes.has(diagnostic.code)) {
|
|
22463
|
+
continue;
|
|
22464
|
+
}
|
|
22465
|
+
const args = {
|
|
22466
|
+
...Range.toFileRangeRequestArgs(file, diagnostic.range),
|
|
22467
|
+
errorCodes: [ +diagnostic.code ]
|
|
22468
|
+
};
|
|
22469
|
+
const response = await client.execute(CommandTypes.GetCodeFixes, args, token);
|
|
22470
|
+
if (response.type !== 'response' || !response.body?.length) {
|
|
22471
|
+
continue;
|
|
22472
|
+
}
|
|
22473
|
+
const fix = response.body?.find(fix => fix.fixName === fixName);
|
|
22474
|
+
if (!fix) {
|
|
22475
|
+
continue;
|
|
22476
|
+
}
|
|
22477
|
+
if (!fix.fixId) {
|
|
22478
|
+
return {
|
|
22479
|
+
documentChanges: fix.changes.map(change => toTextDocumentEdit(change, client))
|
|
22480
|
+
};
|
|
22481
|
+
}
|
|
22482
|
+
const combinedArgs = {
|
|
22483
|
+
scope: {
|
|
22484
|
+
type: 'file',
|
|
22485
|
+
args: {
|
|
22486
|
+
file: file
|
|
22487
|
+
}
|
|
22488
|
+
},
|
|
22489
|
+
fixId: fix.fixId
|
|
22490
|
+
};
|
|
22491
|
+
const combinedResponse = await client.execute(CommandTypes.GetCombinedCodeFix, combinedArgs, token);
|
|
22492
|
+
if (combinedResponse.type !== 'response' || !combinedResponse.body) {
|
|
22493
|
+
return;
|
|
22494
|
+
}
|
|
22495
|
+
return {
|
|
22496
|
+
documentChanges: combinedResponse.body.changes.map(change => toTextDocumentEdit(change, client))
|
|
22497
|
+
};
|
|
22498
|
+
}
|
|
22499
|
+
}
|
|
22500
|
+
}
|
|
22501
|
+
|
|
22502
|
+
class SourceAction extends TsCodeAction {}
|
|
22503
|
+
|
|
22504
|
+
class SourceFixAll extends SourceAction {
|
|
22505
|
+
constructor() {
|
|
22506
|
+
super('Fix all fixable JS/TS issues', SourceFixAll.kind.value);
|
|
22507
|
+
}
|
|
22508
|
+
async build(client, file, diagnostics, token) {
|
|
22509
|
+
this.edit = await buildIndividualFixes([ {
|
|
22510
|
+
codes: incorrectlyImplementsInterface,
|
|
22511
|
+
fixName: classIncorrectlyImplementsInterface
|
|
22512
|
+
}, {
|
|
22513
|
+
codes: asyncOnlyAllowedInAsyncFunctions,
|
|
22514
|
+
fixName: awaitInSyncFunction
|
|
22515
|
+
} ], client, file, diagnostics, token);
|
|
22516
|
+
const edits = await buildCombinedFix([ {
|
|
22517
|
+
codes: unreachableCode$1,
|
|
22518
|
+
fixName: unreachableCode
|
|
22519
|
+
} ], client, file, diagnostics, token);
|
|
22520
|
+
if (edits?.documentChanges) {
|
|
22521
|
+
this.edit?.documentChanges?.push(...edits.documentChanges);
|
|
22522
|
+
}
|
|
22523
|
+
}
|
|
22524
|
+
}
|
|
22525
|
+
|
|
22526
|
+
SourceFixAll.kind = CodeActionKind.SourceFixAllTs;
|
|
22527
|
+
|
|
22528
|
+
class SourceRemoveUnused extends SourceAction {
|
|
22529
|
+
constructor() {
|
|
22530
|
+
super('Remove all unused code', SourceRemoveUnused.kind.value);
|
|
22531
|
+
}
|
|
22532
|
+
async build(client, file, diagnostics, token) {
|
|
22533
|
+
this.edit = await buildCombinedFix([ {
|
|
22534
|
+
codes: variableDeclaredButNeverUsed,
|
|
22535
|
+
fixName: unusedIdentifier
|
|
22536
|
+
} ], client, file, diagnostics, token);
|
|
22537
|
+
}
|
|
22538
|
+
}
|
|
22539
|
+
|
|
22540
|
+
SourceRemoveUnused.kind = CodeActionKind.SourceRemoveUnusedTs;
|
|
22541
|
+
|
|
22542
|
+
class SourceAddMissingImports extends SourceAction {
|
|
22543
|
+
constructor() {
|
|
22544
|
+
super('Add all missing imports', SourceAddMissingImports.kind.value);
|
|
22545
|
+
}
|
|
22546
|
+
async build(client, file, diagnostics, token) {
|
|
22547
|
+
this.edit = await buildCombinedFix([ {
|
|
22548
|
+
codes: cannotFindName,
|
|
22549
|
+
fixName: fixImport
|
|
22550
|
+
} ], client, file, diagnostics, token);
|
|
22551
|
+
}
|
|
22552
|
+
}
|
|
22553
|
+
|
|
22554
|
+
SourceAddMissingImports.kind = CodeActionKind.SourceAddMissingImportsTs;
|
|
22555
|
+
|
|
22556
|
+
class TypeScriptAutoFixProvider {
|
|
22557
|
+
constructor(client, fileConfigurationManager, diagnosticsManager) {
|
|
22558
|
+
this.client = client;
|
|
22559
|
+
this.fileConfigurationManager = fileConfigurationManager;
|
|
22560
|
+
this.diagnosticsManager = diagnosticsManager;
|
|
22561
|
+
}
|
|
22562
|
+
getMetadata() {
|
|
22563
|
+
return {
|
|
22564
|
+
providedCodeActionKinds: TypeScriptAutoFixProvider.kindProviders.map(x => x.kind.value)
|
|
22565
|
+
};
|
|
22566
|
+
}
|
|
22567
|
+
async provideCodeActions(document, _range, context, token) {
|
|
22568
|
+
if (!context.only?.length) {
|
|
22569
|
+
return undefined;
|
|
22570
|
+
}
|
|
22571
|
+
const sourceKinds = context.only.map(kind => new CodeActionKind(kind)).filter(codeActionKind => CodeActionKind.Source.intersects(codeActionKind));
|
|
22572
|
+
if (!sourceKinds.length) {
|
|
22573
|
+
return undefined;
|
|
22574
|
+
}
|
|
22575
|
+
if (this.client.hasPendingDiagnostics(document.uri)) {
|
|
22576
|
+
return undefined;
|
|
22577
|
+
}
|
|
22578
|
+
const actions = this.getFixAllActions(sourceKinds);
|
|
22579
|
+
const diagnostics = this.diagnosticsManager.getDiagnosticsForFile(document.filepath);
|
|
22580
|
+
if (!diagnostics.length) {
|
|
22581
|
+
return actions;
|
|
22582
|
+
}
|
|
22583
|
+
await this.fileConfigurationManager.ensureConfigurationForDocument(document, token);
|
|
22584
|
+
if (token.isCancellationRequested) {
|
|
22585
|
+
return undefined;
|
|
22586
|
+
}
|
|
22587
|
+
await Promise.all(actions.map(action => action.build(this.client, document.filepath, diagnostics, token)));
|
|
22588
|
+
return actions;
|
|
22589
|
+
}
|
|
22590
|
+
isCodeActionResolvable(_codeAction) {
|
|
22591
|
+
return false;
|
|
22592
|
+
}
|
|
22593
|
+
getFixAllActions(kinds) {
|
|
22594
|
+
return TypeScriptAutoFixProvider.kindProviders.filter(provider => kinds.some(only => only.intersects(provider.kind))).map(provider => new provider);
|
|
22595
|
+
}
|
|
22596
|
+
}
|
|
22597
|
+
|
|
22598
|
+
TypeScriptAutoFixProvider.kindProviders = [ SourceFixAll, SourceRemoveUnused, SourceAddMissingImports ];
|
|
22599
|
+
|
|
22600
|
+
class Lazy {
|
|
22601
|
+
constructor(executor) {
|
|
22602
|
+
this.executor = executor;
|
|
22603
|
+
this._didRun = false;
|
|
22604
|
+
}
|
|
22605
|
+
get hasValue() {
|
|
22606
|
+
return this._didRun;
|
|
22607
|
+
}
|
|
22608
|
+
get value() {
|
|
22609
|
+
if (!this._didRun) {
|
|
22610
|
+
try {
|
|
22611
|
+
this._value = this.executor();
|
|
22612
|
+
} catch (err) {
|
|
22613
|
+
this._error = err;
|
|
22614
|
+
} finally {
|
|
22615
|
+
this._didRun = true;
|
|
22616
|
+
}
|
|
22617
|
+
}
|
|
22618
|
+
if (this._error) {
|
|
22619
|
+
throw this._error;
|
|
22620
|
+
}
|
|
22621
|
+
return this._value;
|
|
22622
|
+
}
|
|
22623
|
+
get rawValue() {
|
|
22624
|
+
return this._value;
|
|
22625
|
+
}
|
|
22626
|
+
}
|
|
22627
|
+
|
|
22628
|
+
function getEditForCodeAction(client, action) {
|
|
22629
|
+
return action.changes?.length ? {
|
|
22630
|
+
documentChanges: action.changes.map(change => toTextDocumentEdit(change, client))
|
|
22631
|
+
} : undefined;
|
|
22632
|
+
}
|
|
22633
|
+
|
|
22634
|
+
async function applyCodeActionCommands(client, commands, token) {
|
|
22635
|
+
if (commands?.length) {
|
|
22636
|
+
for (const command of commands) {
|
|
22637
|
+
await client.execute(CommandTypes.ApplyCodeActionCommand, {
|
|
22638
|
+
command: command
|
|
22639
|
+
}, token);
|
|
22640
|
+
}
|
|
22641
|
+
}
|
|
22642
|
+
return true;
|
|
22643
|
+
}
|
|
22644
|
+
|
|
22645
|
+
class ApplyCodeActionCommand {
|
|
22646
|
+
constructor(client) {
|
|
22647
|
+
this.client = client;
|
|
22648
|
+
this.id = ApplyCodeActionCommand.ID;
|
|
22649
|
+
}
|
|
22650
|
+
async execute({action: action}) {
|
|
22651
|
+
const codeActionResult = await applyCodeActionCommands(this.client, action.commands);
|
|
22652
|
+
return codeActionResult;
|
|
22653
|
+
}
|
|
22654
|
+
}
|
|
22655
|
+
|
|
22656
|
+
ApplyCodeActionCommand.ID = '_typescript.applyCodeActionCommand';
|
|
22657
|
+
|
|
22658
|
+
class ApplyFixAllCodeAction {
|
|
22659
|
+
constructor(client, tsCodeActionProvider) {
|
|
22660
|
+
this.client = client;
|
|
22661
|
+
this.tsCodeActionProvider = tsCodeActionProvider;
|
|
22662
|
+
this.id = ApplyFixAllCodeAction.ID;
|
|
22663
|
+
}
|
|
22664
|
+
async execute(args) {
|
|
22665
|
+
const tsAction = this.tsCodeActionProvider.getQuickFixAllTsCodeActionByFixName(args.tsActionId);
|
|
22666
|
+
if (tsAction instanceof TsQuickFixAllCodeAction && tsAction.combinedResponse) {
|
|
22667
|
+
await applyCodeActionCommands(this.client, tsAction.combinedResponse.body.commands);
|
|
22668
|
+
}
|
|
22669
|
+
}
|
|
22670
|
+
}
|
|
22671
|
+
|
|
22672
|
+
ApplyFixAllCodeAction.ID = '_typescript.applyFixAllCodeAction';
|
|
22673
|
+
|
|
22674
|
+
class DiagnosticsSet {
|
|
22675
|
+
static from(diagnostics) {
|
|
22676
|
+
const values = new Map;
|
|
22677
|
+
for (const diagnostic of diagnostics) {
|
|
22678
|
+
values.set(DiagnosticsSet.key(diagnostic), diagnostic);
|
|
22679
|
+
}
|
|
22680
|
+
return new DiagnosticsSet(values);
|
|
22681
|
+
}
|
|
22682
|
+
static key(diagnostic) {
|
|
22683
|
+
const {start: start, end: end} = diagnostic.range;
|
|
22684
|
+
return `${diagnostic.code}-${start.line},${start.character}-${end.line},${end.character}`;
|
|
22685
|
+
}
|
|
22686
|
+
constructor(_values) {
|
|
22687
|
+
this._values = _values;
|
|
22688
|
+
}
|
|
22689
|
+
get values() {
|
|
22690
|
+
return this._values.values();
|
|
22691
|
+
}
|
|
22692
|
+
get size() {
|
|
22693
|
+
return this._values.size;
|
|
22694
|
+
}
|
|
22695
|
+
}
|
|
22696
|
+
|
|
22697
|
+
class TsQuickFixCodeAction extends TsCodeAction {
|
|
22698
|
+
constructor(tsAction, title, kind) {
|
|
22699
|
+
super(title, kind);
|
|
22700
|
+
this.tsAction = tsAction;
|
|
22701
|
+
}
|
|
22702
|
+
}
|
|
22703
|
+
|
|
22704
|
+
class TsQuickFixAllCodeAction extends TsQuickFixCodeAction {
|
|
22705
|
+
constructor(tsAction, file, title, kind) {
|
|
22706
|
+
super(tsAction, title, kind);
|
|
22707
|
+
this.file = file;
|
|
22708
|
+
}
|
|
22709
|
+
}
|
|
22710
|
+
|
|
22711
|
+
class CodeActionSet {
|
|
22712
|
+
constructor() {
|
|
22713
|
+
this._actions = new Set;
|
|
22714
|
+
this._fixAllActions = new Map;
|
|
22715
|
+
this._aiActions = new Set;
|
|
22716
|
+
}
|
|
22717
|
+
* values() {
|
|
22718
|
+
yield* this._actions;
|
|
22719
|
+
yield* this._aiActions;
|
|
22720
|
+
}
|
|
22721
|
+
addAction(action) {
|
|
22722
|
+
for (const existing of this._actions) {
|
|
22723
|
+
if (action.tsAction.fixName === existing.tsAction.fixName && equals(action.edit, existing.edit)) {
|
|
22724
|
+
this._actions.delete(existing);
|
|
22725
|
+
}
|
|
22726
|
+
}
|
|
22727
|
+
this._actions.add(action);
|
|
22728
|
+
if (action.tsAction.fixId) {
|
|
22729
|
+
const existingFixAll = this._fixAllActions.get(action.tsAction.fixId);
|
|
22730
|
+
if (existingFixAll) {
|
|
22731
|
+
this._actions.delete(existingFixAll);
|
|
22732
|
+
this._actions.add(existingFixAll);
|
|
22733
|
+
}
|
|
22734
|
+
}
|
|
22735
|
+
}
|
|
22736
|
+
addFixAllAction(fixId, action) {
|
|
22737
|
+
const existing = this._fixAllActions.get(fixId);
|
|
22738
|
+
if (existing) {
|
|
22739
|
+
this._actions.delete(existing);
|
|
22740
|
+
}
|
|
22741
|
+
this.addAction(action);
|
|
22742
|
+
this._fixAllActions.set(fixId, action);
|
|
22743
|
+
}
|
|
22744
|
+
hasFixAllAction(fixId) {
|
|
22745
|
+
return this._fixAllActions.has(fixId);
|
|
22746
|
+
}
|
|
22747
|
+
}
|
|
22748
|
+
|
|
22749
|
+
class SupportedCodeActionProvider {
|
|
22750
|
+
constructor(client) {
|
|
22751
|
+
this.client = client;
|
|
22752
|
+
this.fixableDiagnosticCodes = new Lazy(() => this.client.execute(CommandTypes.GetSupportedCodeFixes, null).then(response => response.type === 'response' ? response.body || [] : []).then(codes => new Set(codes)));
|
|
22753
|
+
}
|
|
22754
|
+
async getFixableDiagnosticsForContext(diagnostics) {
|
|
22755
|
+
const fixableCodes = await this.fixableDiagnosticCodes.value;
|
|
22756
|
+
return DiagnosticsSet.from(diagnostics.filter(diagnostic => typeof diagnostic.code !== 'undefined' && fixableCodes.has(diagnostic.code + '')));
|
|
22757
|
+
}
|
|
22758
|
+
}
|
|
22759
|
+
|
|
22760
|
+
class TypeScriptQuickFixProvider {
|
|
22761
|
+
constructor(client, fileConfigurationManager, commandManager, diagnosticsManager, features) {
|
|
22762
|
+
this.client = client;
|
|
22763
|
+
this.fileConfigurationManager = fileConfigurationManager;
|
|
22764
|
+
this.diagnosticsManager = diagnosticsManager;
|
|
22765
|
+
this.features = features;
|
|
22766
|
+
this._quickFixAllTsCodeActionMap = new Map;
|
|
22767
|
+
commandManager.register(new ApplyCodeActionCommand(client));
|
|
22768
|
+
commandManager.register(new ApplyFixAllCodeAction(client, this));
|
|
22769
|
+
this.supportedCodeActionProvider = new SupportedCodeActionProvider(client);
|
|
22770
|
+
}
|
|
22771
|
+
getMetadata() {
|
|
22772
|
+
return {
|
|
22773
|
+
providedCodeActionKinds: [ CodeActionKind.QuickFix.value ]
|
|
22774
|
+
};
|
|
22775
|
+
}
|
|
22776
|
+
async provideCodeActions(document, range, context, token) {
|
|
22777
|
+
this._quickFixAllTsCodeActionMap.clear();
|
|
22778
|
+
let diagnostics = context.diagnostics;
|
|
22779
|
+
if (this.client.hasPendingDiagnostics(document.uri)) {
|
|
22780
|
+
await new Promise(resolve => {
|
|
22781
|
+
setTimeout(resolve, 500);
|
|
22782
|
+
});
|
|
22783
|
+
if (token.isCancellationRequested) {
|
|
22784
|
+
return;
|
|
22785
|
+
}
|
|
22786
|
+
const allDiagnostics = [];
|
|
22787
|
+
for (const diagnostic of this.diagnosticsManager.getDiagnosticsForFile(document.filepath)) {
|
|
22788
|
+
if (Range.intersection(range, diagnostic.range)) {
|
|
22789
|
+
const newLen = allDiagnostics.push(diagnostic);
|
|
22790
|
+
if (newLen > TypeScriptQuickFixProvider._maxCodeActionsPerFile) {
|
|
22791
|
+
break;
|
|
22792
|
+
}
|
|
22793
|
+
}
|
|
22794
|
+
}
|
|
22795
|
+
diagnostics = allDiagnostics;
|
|
22796
|
+
}
|
|
22797
|
+
const fixableDiagnostics = await this.supportedCodeActionProvider.getFixableDiagnosticsForContext(diagnostics);
|
|
22798
|
+
if (!fixableDiagnostics.size || token.isCancellationRequested) {
|
|
22799
|
+
return;
|
|
22800
|
+
}
|
|
22801
|
+
await this.fileConfigurationManager.ensureConfigurationForDocument(document, token);
|
|
22802
|
+
if (token.isCancellationRequested) {
|
|
22803
|
+
return;
|
|
22804
|
+
}
|
|
22805
|
+
const results = new CodeActionSet;
|
|
22806
|
+
for (const diagnostic of fixableDiagnostics.values) {
|
|
22807
|
+
await this.getFixesForDiagnostic(document, diagnostic, results, token);
|
|
22808
|
+
if (token.isCancellationRequested) {
|
|
22809
|
+
return;
|
|
22810
|
+
}
|
|
22811
|
+
}
|
|
22812
|
+
const allActions = Array.from(results.values());
|
|
22813
|
+
for (const action of allActions) {
|
|
22814
|
+
action.isPreferred = isPreferredFix(action, allActions);
|
|
22815
|
+
}
|
|
22816
|
+
return allActions;
|
|
22817
|
+
}
|
|
22818
|
+
isCodeActionResolvable(codeAction) {
|
|
22819
|
+
return codeAction instanceof TsQuickFixAllCodeAction;
|
|
22820
|
+
}
|
|
22821
|
+
async resolveCodeAction(codeAction, token) {
|
|
22822
|
+
if (!this.isCodeActionResolvable(codeAction) || !codeAction.tsAction.fixId) {
|
|
22823
|
+
return codeAction;
|
|
22824
|
+
}
|
|
22825
|
+
const arg = {
|
|
22826
|
+
scope: {
|
|
22827
|
+
type: 'file',
|
|
22828
|
+
args: {
|
|
22829
|
+
file: codeAction.file
|
|
22830
|
+
}
|
|
22831
|
+
},
|
|
22832
|
+
fixId: codeAction.tsAction.fixId
|
|
22833
|
+
};
|
|
22834
|
+
const response = await this.client.execute(CommandTypes.GetCombinedCodeFix, arg, token);
|
|
22835
|
+
if (response.type === 'response') {
|
|
22836
|
+
codeAction.combinedResponse = response;
|
|
22837
|
+
codeAction.edit = {
|
|
22838
|
+
documentChanges: response.body.changes.map(change => toTextDocumentEdit(change, this.client))
|
|
22839
|
+
};
|
|
22840
|
+
}
|
|
22841
|
+
return codeAction;
|
|
22842
|
+
}
|
|
22843
|
+
getQuickFixAllTsCodeActionByFixName(fixName) {
|
|
22844
|
+
return this._quickFixAllTsCodeActionMap.get(fixName);
|
|
22845
|
+
}
|
|
22846
|
+
async getFixesForDiagnostic(document, diagnostic, results, token) {
|
|
22847
|
+
const args = {
|
|
22848
|
+
...Range.toFileRangeRequestArgs(document.filepath, diagnostic.range),
|
|
22849
|
+
errorCodes: [ +diagnostic.code ]
|
|
22850
|
+
};
|
|
22851
|
+
const response = await this.client.execute(CommandTypes.GetCodeFixes, args, token);
|
|
22852
|
+
if (response.type !== 'response' || !response.body) {
|
|
22853
|
+
return results;
|
|
22854
|
+
}
|
|
22855
|
+
for (const tsCodeFix of response.body) {
|
|
22856
|
+
for (const action of this.getFixesForTsCodeAction(document, diagnostic, tsCodeFix)) {
|
|
22857
|
+
results.addAction(action);
|
|
22858
|
+
}
|
|
22859
|
+
if (this.features.codeActionResolveSupport) {
|
|
22860
|
+
this.addFixAllForTsCodeAction(results, document.uri, document.filepath, diagnostic, tsCodeFix);
|
|
22861
|
+
}
|
|
22862
|
+
}
|
|
22863
|
+
return results;
|
|
22864
|
+
}
|
|
22865
|
+
getFixesForTsCodeAction(document, diagnostic, action) {
|
|
22866
|
+
const actions = [];
|
|
22867
|
+
const codeAction = new TsQuickFixCodeAction(action, action.description, mainExports$2.CodeActionKind.QuickFix);
|
|
22868
|
+
codeAction.edit = getEditForCodeAction(this.client, action);
|
|
22869
|
+
codeAction.diagnostics = [ diagnostic ];
|
|
22870
|
+
codeAction.command = {
|
|
22871
|
+
command: ApplyCodeActionCommand.ID,
|
|
22872
|
+
arguments: [ {
|
|
22873
|
+
action: action,
|
|
22874
|
+
diagnostic: diagnostic,
|
|
22875
|
+
documentUri: document.uri.toString()
|
|
22876
|
+
} ],
|
|
22877
|
+
title: ''
|
|
22878
|
+
};
|
|
22879
|
+
actions.push(codeAction);
|
|
22880
|
+
return actions;
|
|
22881
|
+
}
|
|
22882
|
+
addFixAllForTsCodeAction(results, _resource, file, diagnostic, tsAction) {
|
|
22883
|
+
if (!tsAction.fixId || results.hasFixAllAction(tsAction.fixId)) {
|
|
22884
|
+
return results;
|
|
22885
|
+
}
|
|
22886
|
+
if (!this.diagnosticsManager.getDiagnosticsForFile(file).some(x => {
|
|
22887
|
+
if (x === diagnostic) {
|
|
22888
|
+
return false;
|
|
22889
|
+
}
|
|
22890
|
+
return x.code === diagnostic.code || fixAllErrorCodes.has(x.code) && fixAllErrorCodes.get(x.code) === fixAllErrorCodes.get(diagnostic.code);
|
|
22891
|
+
})) {
|
|
22892
|
+
return results;
|
|
22893
|
+
}
|
|
22894
|
+
const action = new TsQuickFixAllCodeAction(tsAction, file, tsAction.fixAllDescription || `${tsAction.description} (Fix all in file)`, mainExports$2.CodeActionKind.QuickFix);
|
|
22895
|
+
action.diagnostics = [ diagnostic ];
|
|
22896
|
+
action.command = {
|
|
22897
|
+
command: ApplyFixAllCodeAction.ID,
|
|
22898
|
+
arguments: [ {
|
|
22899
|
+
tsActionId: tsAction.fixName
|
|
22900
|
+
} ],
|
|
22901
|
+
title: ''
|
|
22902
|
+
};
|
|
22903
|
+
this._quickFixAllTsCodeActionMap.set(tsAction.fixName, action);
|
|
22904
|
+
results.addFixAllAction(tsAction.fixId, action);
|
|
22905
|
+
return results;
|
|
22906
|
+
}
|
|
22907
|
+
}
|
|
22908
|
+
|
|
22909
|
+
TypeScriptQuickFixProvider._maxCodeActionsPerFile = 1e3;
|
|
22910
|
+
|
|
22911
|
+
const fixAllErrorCodes = new Map([ [ 2339, 2339 ], [ 2345, 2339 ] ]);
|
|
22912
|
+
|
|
22913
|
+
const preferredFixes = new Map([ [ annotateWithTypeFromJSDoc, {
|
|
22914
|
+
priority: 2
|
|
22915
|
+
} ], [ constructorForDerivedNeedSuperCall, {
|
|
22916
|
+
priority: 2
|
|
22917
|
+
} ], [ extendsInterfaceBecomesImplements, {
|
|
22918
|
+
priority: 2
|
|
22919
|
+
} ], [ awaitInSyncFunction, {
|
|
22920
|
+
priority: 2
|
|
22921
|
+
} ], [ removeUnnecessaryAwait, {
|
|
22922
|
+
priority: 2
|
|
22923
|
+
} ], [ classIncorrectlyImplementsInterface, {
|
|
22924
|
+
priority: 3
|
|
22925
|
+
} ], [ classDoesntImplementInheritedAbstractMember, {
|
|
22926
|
+
priority: 3
|
|
22927
|
+
} ], [ unreachableCode, {
|
|
22928
|
+
priority: 2
|
|
22929
|
+
} ], [ unusedIdentifier, {
|
|
22930
|
+
priority: 2
|
|
22931
|
+
} ], [ forgottenThisPropertyAccess, {
|
|
22932
|
+
priority: 2
|
|
22933
|
+
} ], [ spelling, {
|
|
22934
|
+
priority: 0
|
|
22935
|
+
} ], [ addMissingAwait, {
|
|
22936
|
+
priority: 2
|
|
22937
|
+
} ], [ addMissingOverride, {
|
|
22938
|
+
priority: 2
|
|
22939
|
+
} ], [ addMissingNewOperator, {
|
|
22940
|
+
priority: 2
|
|
22941
|
+
} ], [ fixImport, {
|
|
22942
|
+
priority: 1,
|
|
22943
|
+
thereCanOnlyBeOne: true
|
|
22944
|
+
} ] ]);
|
|
22945
|
+
|
|
22946
|
+
function isPreferredFix(action, allActions) {
|
|
22947
|
+
if (action instanceof TsQuickFixAllCodeAction) {
|
|
22948
|
+
return false;
|
|
22949
|
+
}
|
|
22950
|
+
const fixPriority = preferredFixes.get(action.tsAction.fixName);
|
|
22951
|
+
if (!fixPriority) {
|
|
22952
|
+
return false;
|
|
22953
|
+
}
|
|
22954
|
+
return allActions.every(otherAction => {
|
|
22955
|
+
if (otherAction === action) {
|
|
22956
|
+
return true;
|
|
22957
|
+
}
|
|
22958
|
+
if (otherAction instanceof TsQuickFixAllCodeAction) {
|
|
22959
|
+
return true;
|
|
22960
|
+
}
|
|
22961
|
+
const otherFixPriority = preferredFixes.get(otherAction.tsAction.fixName);
|
|
22962
|
+
if (!otherFixPriority || otherFixPriority.priority < fixPriority.priority) {
|
|
22963
|
+
return true;
|
|
22964
|
+
} else if (otherFixPriority.priority > fixPriority.priority) {
|
|
22965
|
+
return false;
|
|
22966
|
+
}
|
|
22967
|
+
if (fixPriority.thereCanOnlyBeOne && action.tsAction.fixName === otherAction.tsAction.fixName) {
|
|
22968
|
+
return false;
|
|
22969
|
+
}
|
|
22970
|
+
return true;
|
|
22971
|
+
});
|
|
22972
|
+
}
|
|
22973
|
+
|
|
22974
|
+
const noopDisposable = mainExports$2.Disposable.create(() => {});
|
|
22975
|
+
|
|
22976
|
+
const nulToken = {
|
|
22977
|
+
isCancellationRequested: false,
|
|
22978
|
+
onCancellationRequested: () => noopDisposable
|
|
22979
|
+
};
|
|
22980
|
+
|
|
22981
|
+
class CodeActionManager {
|
|
22982
|
+
constructor(client, fileConfigurationManager, commandManager, diagnosticsManager, features) {
|
|
22983
|
+
this.features = features;
|
|
22984
|
+
this.providerMap = new Map;
|
|
22985
|
+
this.nextProviderId = 1;
|
|
22986
|
+
this.resolveCodeActionsMap = new Map;
|
|
22987
|
+
this.nextGlobalCodeActionId = 1;
|
|
22988
|
+
this.addProvider(new TypeScriptAutoFixProvider(client, fileConfigurationManager, diagnosticsManager));
|
|
22989
|
+
this.addProvider(new TypeScriptQuickFixProvider(client, fileConfigurationManager, commandManager, diagnosticsManager, features));
|
|
22990
|
+
}
|
|
22991
|
+
get kinds() {
|
|
22992
|
+
const allKinds = [];
|
|
22993
|
+
for (const [_, provider] of this.providerMap) {
|
|
22994
|
+
allKinds.push(...provider.getMetadata().providedCodeActionKinds || []);
|
|
22995
|
+
}
|
|
22996
|
+
return allKinds;
|
|
22997
|
+
}
|
|
22998
|
+
async provideCodeActions(document, range, context, token) {
|
|
22999
|
+
this.resolveCodeActionsMap.clear();
|
|
23000
|
+
const allCodeActions = [];
|
|
23001
|
+
for (const [providerId, provider] of this.providerMap.entries()) {
|
|
23002
|
+
const codeActions = await provider.provideCodeActions(document, range, context, token || nulToken);
|
|
23003
|
+
if (!codeActions) {
|
|
23004
|
+
continue;
|
|
23005
|
+
}
|
|
23006
|
+
for (const action of codeActions) {
|
|
23007
|
+
if (mainExports$2.Command.is(action)) {
|
|
23008
|
+
allCodeActions.push(action);
|
|
23009
|
+
continue;
|
|
23010
|
+
}
|
|
23011
|
+
const lspCodeAction = action.toLspCodeAction();
|
|
23012
|
+
if (provider.isCodeActionResolvable(action)) {
|
|
23013
|
+
const globalId = this.nextGlobalCodeActionId++;
|
|
23014
|
+
this.resolveCodeActionsMap.set(globalId, action);
|
|
23015
|
+
lspCodeAction.data = {
|
|
23016
|
+
globalId: globalId,
|
|
23017
|
+
providerId: providerId
|
|
23018
|
+
};
|
|
23019
|
+
}
|
|
23020
|
+
allCodeActions.push(lspCodeAction);
|
|
23021
|
+
}
|
|
23022
|
+
}
|
|
23023
|
+
return allCodeActions;
|
|
23024
|
+
}
|
|
23025
|
+
async resolveCodeAction(codeAction, token) {
|
|
23026
|
+
if (!this.features.codeActionResolveSupport) {
|
|
23027
|
+
return codeAction;
|
|
23028
|
+
}
|
|
23029
|
+
const {globalId: globalId, providerId: providerId} = codeAction.data || {};
|
|
23030
|
+
if (globalId === undefined || providerId === undefined) {
|
|
23031
|
+
return codeAction;
|
|
23032
|
+
}
|
|
23033
|
+
const provider = this.providerMap.get(providerId);
|
|
23034
|
+
if (!provider || !provider.resolveCodeAction) {
|
|
23035
|
+
return codeAction;
|
|
23036
|
+
}
|
|
23037
|
+
const tsCodeAction = this.resolveCodeActionsMap.get(globalId);
|
|
23038
|
+
if (!tsCodeAction || !providerId) {
|
|
23039
|
+
return codeAction;
|
|
23040
|
+
}
|
|
23041
|
+
const resolvedTsCodeAction = await provider.resolveCodeAction(tsCodeAction, token || nulToken);
|
|
23042
|
+
if (!resolvedTsCodeAction) {
|
|
23043
|
+
return codeAction;
|
|
23044
|
+
}
|
|
23045
|
+
const lspCodeAction = resolvedTsCodeAction.toLspCodeAction();
|
|
23046
|
+
for (const property of this.features.codeActionResolveSupport.properties) {
|
|
23047
|
+
if (property in lspCodeAction) {
|
|
23048
|
+
codeAction[property] = lspCodeAction[property];
|
|
23049
|
+
}
|
|
23050
|
+
}
|
|
23051
|
+
return codeAction;
|
|
23052
|
+
}
|
|
23053
|
+
addProvider(provider) {
|
|
23054
|
+
this.providerMap.set(this.nextProviderId++, provider);
|
|
23055
|
+
}
|
|
23056
|
+
}
|
|
23057
|
+
|
|
22243
23058
|
class LspServer {
|
|
22244
23059
|
constructor(options) {
|
|
22245
23060
|
this.options = options;
|
|
22246
23061
|
this.initializeParams = null;
|
|
22247
23062
|
this.completionDataCache = new CompletionDataCache;
|
|
22248
|
-
this.typeScriptAutoFixProvider = null;
|
|
22249
23063
|
this.features = {};
|
|
22250
23064
|
this.cachedNavTreeResponse = new CachedResponse;
|
|
22251
23065
|
this.implementationsCodeLensProvider = null;
|
|
@@ -22253,7 +23067,9 @@ class LspServer {
|
|
|
22253
23067
|
this.logger = new PrefixingLogger(options.logger, '[lspserver]');
|
|
22254
23068
|
this.tsClient = new TsClient(onCaseInsensitiveFileSystem(), this.logger, options.lspClient);
|
|
22255
23069
|
this.fileConfigurationManager = new FileConfigurationManager(this.tsClient, onCaseInsensitiveFileSystem());
|
|
22256
|
-
this.
|
|
23070
|
+
this.commandManager = new CommandManager;
|
|
23071
|
+
this.diagnosticsManager = new DiagnosticsManager(diagnostics => this.options.lspClient.publishDiagnostics(diagnostics), this.tsClient, this.features, this.logger);
|
|
23072
|
+
this.codeActionsManager = new CodeActionManager(this.tsClient, this.fileConfigurationManager, this.commandManager, this.diagnosticsManager, this.features);
|
|
22257
23073
|
}
|
|
22258
23074
|
closeAllForTesting() {
|
|
22259
23075
|
for (const document of this.tsClient.documentsForTesting.values()) {
|
|
@@ -22265,7 +23081,7 @@ class LspServer {
|
|
|
22265
23081
|
if (!document) {
|
|
22266
23082
|
throw new Error(`Document not open: ${uri}`);
|
|
22267
23083
|
}
|
|
22268
|
-
await this.
|
|
23084
|
+
await this.diagnosticsManager.waitForDiagnosticsForTesting(document.filepath);
|
|
22269
23085
|
}
|
|
22270
23086
|
shutdown() {
|
|
22271
23087
|
this.tsClient.shutdown();
|
|
@@ -22287,11 +23103,13 @@ class LspServer {
|
|
|
22287
23103
|
}
|
|
22288
23104
|
this.fileConfigurationManager.mergeTsPreferences(userInitializationOptions.preferences || {});
|
|
22289
23105
|
this.features.completionDisableFilterText = userInitializationOptions.completionDisableFilterText ?? false;
|
|
23106
|
+
this.features.moveToFileCodeActionSupport = userInitializationOptions.supportsMoveToFileCodeAction && typescriptVersion.version?.gte(API.v520);
|
|
22290
23107
|
const {textDocument: textDocument} = clientCapabilities;
|
|
22291
23108
|
if (textDocument) {
|
|
22292
23109
|
const {codeAction: codeAction, completion: completion, definition: definition, publishDiagnostics: publishDiagnostics} = textDocument;
|
|
22293
23110
|
if (codeAction) {
|
|
22294
23111
|
this.features.codeActionDisabledSupport = codeAction.disabledSupport;
|
|
23112
|
+
this.features.codeActionResolveSupport = codeAction.resolveSupport;
|
|
22295
23113
|
}
|
|
22296
23114
|
if (completion) {
|
|
22297
23115
|
const {completionItem: completionItem} = completion;
|
|
@@ -22342,10 +23160,10 @@ class LspServer {
|
|
|
22342
23160
|
process.on('SIGINT', () => {
|
|
22343
23161
|
process.exit();
|
|
22344
23162
|
});
|
|
22345
|
-
this.typeScriptAutoFixProvider = new TypeScriptAutoFixProvider(this.tsClient);
|
|
22346
23163
|
this.fileConfigurationManager.setGlobalConfiguration(this.workspaceRoot, hostInfo);
|
|
22347
23164
|
this.registerHandlers();
|
|
22348
23165
|
const prepareSupport = textDocument?.rename?.prepareSupport && this.tsClient.apiVersion.gte(API.v310);
|
|
23166
|
+
const {codeActionLiteralSupport: codeActionLiteralSupport, resolveSupport: codeActionResolveSupport} = textDocument?.codeAction || {};
|
|
22349
23167
|
const initializeResult = {
|
|
22350
23168
|
capabilities: {
|
|
22351
23169
|
textDocumentSync: mainExports$2.TextDocumentSyncKind.Incremental,
|
|
@@ -22353,8 +23171,13 @@ class LspServer {
|
|
|
22353
23171
|
triggerCharacters: [ '.', '"', '\'', '/', '@', '<' ],
|
|
22354
23172
|
resolveProvider: true
|
|
22355
23173
|
},
|
|
22356
|
-
codeActionProvider:
|
|
22357
|
-
|
|
23174
|
+
codeActionProvider: codeActionLiteralSupport || codeActionResolveSupport ? {
|
|
23175
|
+
...codeActionLiteralSupport ? {
|
|
23176
|
+
codeActionKinds: [ ...this.codeActionsManager.kinds, CodeActionKind.SourceOrganizeImportsTs.value, CodeActionKind.SourceRemoveUnusedImportsTs.value, CodeActionKind.SourceSortImportsTs.value, CodeActionKind.Refactor.value ]
|
|
23177
|
+
} : {},
|
|
23178
|
+
...codeActionResolveSupport ? {
|
|
23179
|
+
resolveProvider: true
|
|
23180
|
+
} : {}
|
|
22358
23181
|
} : true,
|
|
22359
23182
|
codeLensProvider: {
|
|
22360
23183
|
resolveProvider: true
|
|
@@ -22365,7 +23188,7 @@ class LspServer {
|
|
|
22365
23188
|
documentHighlightProvider: true,
|
|
22366
23189
|
documentSymbolProvider: true,
|
|
22367
23190
|
executeCommandProvider: {
|
|
22368
|
-
commands: [ Commands.
|
|
23191
|
+
commands: [ Commands.APPLY_REFACTORING, Commands.CONFIGURE_PLUGIN, Commands.ORGANIZE_IMPORTS, Commands.APPLY_RENAME_FILE, Commands.SOURCE_DEFINITION, Commands.TS_SERVER_REQUEST ]
|
|
22369
23192
|
},
|
|
22370
23193
|
hoverProvider: true,
|
|
22371
23194
|
inlayHintProvider: true,
|
|
@@ -22476,7 +23299,7 @@ class LspServer {
|
|
|
22476
23299
|
didChangeConfiguration(params) {
|
|
22477
23300
|
this.fileConfigurationManager.setWorkspaceConfiguration(params.settings || {});
|
|
22478
23301
|
const ignoredDiagnosticCodes = this.fileConfigurationManager.workspaceConfiguration.diagnostics?.ignoredCodes || [];
|
|
22479
|
-
this.tsClient.interruptGetErr(() => this.
|
|
23302
|
+
this.tsClient.interruptGetErr(() => this.diagnosticsManager.updateIgnoredDiagnosticCodes(ignoredDiagnosticCodes));
|
|
22480
23303
|
}
|
|
22481
23304
|
didOpenTextDocument(params) {
|
|
22482
23305
|
if (this.tsClient.toOpenDocument(params.textDocument.uri, {
|
|
@@ -22498,7 +23321,7 @@ class LspServer {
|
|
|
22498
23321
|
}
|
|
22499
23322
|
this.cachedNavTreeResponse.onDocumentClose(document);
|
|
22500
23323
|
this.tsClient.onDidCloseTextDocument(uri);
|
|
22501
|
-
this.
|
|
23324
|
+
this.diagnosticsManager.onDidCloseFile(document.filepath);
|
|
22502
23325
|
this.fileConfigurationManager.onDidCloseTextDocument(document.uri);
|
|
22503
23326
|
}
|
|
22504
23327
|
didChangeTextDocument(params) {
|
|
@@ -22822,15 +23645,11 @@ class LspServer {
|
|
|
22822
23645
|
if (!document) {
|
|
22823
23646
|
return [];
|
|
22824
23647
|
}
|
|
22825
|
-
await this.
|
|
23648
|
+
const actions = await this.codeActionsManager.provideCodeActions(document, params.range, params.context, token);
|
|
22826
23649
|
const fileRangeArgs = Range.toFileRangeRequestArgs(document.filepath, params.range);
|
|
22827
|
-
const actions = [];
|
|
22828
23650
|
const kinds = params.context.only?.map(kind => new CodeActionKind(kind));
|
|
22829
|
-
if (!kinds || kinds.some(kind =>
|
|
22830
|
-
actions.push(...
|
|
22831
|
-
}
|
|
22832
|
-
if (!kinds || kinds.some(kind => kind.contains(CodeActionKind.Refactor))) {
|
|
22833
|
-
actions.push(...provideRefactors(await this.getRefactors(fileRangeArgs, params.context, token), fileRangeArgs, this.features));
|
|
23651
|
+
if (!kinds || kinds.some(kind => CodeActionKind.Refactor.contains(kind))) {
|
|
23652
|
+
actions.push(...provideRefactors(await this.getRefactors(fileRangeArgs, params.context, this.features, token), fileRangeArgs, this.features));
|
|
22834
23653
|
}
|
|
22835
23654
|
for (const kind of kinds || []) {
|
|
22836
23655
|
for (const command of organizeImportsCommands) {
|
|
@@ -22858,57 +23677,36 @@ class LspServer {
|
|
|
22858
23677
|
}
|
|
22859
23678
|
}
|
|
22860
23679
|
}
|
|
22861
|
-
if (kinds && !this.tsClient.hasPendingDiagnostics(document.uri)) {
|
|
22862
|
-
const diagnostics = this.diagnosticQueue.getDiagnosticsForFile(document.filepath) || [];
|
|
22863
|
-
if (diagnostics.length) {
|
|
22864
|
-
actions.push(...await this.typeScriptAutoFixProvider.provideCodeActions(kinds, document.filepath, diagnostics));
|
|
22865
|
-
}
|
|
22866
|
-
}
|
|
22867
23680
|
return actions;
|
|
22868
23681
|
}
|
|
22869
|
-
async
|
|
22870
|
-
const
|
|
22871
|
-
const
|
|
22872
|
-
|
|
22873
|
-
|
|
22874
|
-
|
|
22875
|
-
|
|
22876
|
-
|
|
23682
|
+
async getRefactors(fileRangeArgs, context, features, token) {
|
|
23683
|
+
const kinds = context.only || [ undefined ];
|
|
23684
|
+
const responses = await Promise.all(kinds.map(async kind => {
|
|
23685
|
+
const args = {
|
|
23686
|
+
...fileRangeArgs,
|
|
23687
|
+
triggerReason: context.triggerKind === mainExports$2.CodeActionTriggerKind.Invoked ? 'invoked' : undefined,
|
|
23688
|
+
kind: kind,
|
|
23689
|
+
includeInteractiveActions: features.moveToFileCodeActionSupport
|
|
23690
|
+
};
|
|
23691
|
+
const response = await this.tsClient.execute(CommandTypes.GetApplicableRefactors, args, token);
|
|
23692
|
+
return response.type === 'response' && response.body ? response.body : [];
|
|
23693
|
+
}));
|
|
23694
|
+
return responses.flat();
|
|
22877
23695
|
}
|
|
22878
|
-
async
|
|
22879
|
-
|
|
22880
|
-
...fileRangeArgs,
|
|
22881
|
-
triggerReason: context.triggerKind === mainExports$2.CodeActionTriggerKind.Invoked ? 'invoked' : undefined,
|
|
22882
|
-
kind: context.only?.length === 1 ? context.only[0] : undefined
|
|
22883
|
-
};
|
|
22884
|
-
const response = await this.tsClient.execute(CommandTypes.GetApplicableRefactors, args, token);
|
|
22885
|
-
return response.type === 'response' ? response : undefined;
|
|
23696
|
+
async codeActionResolve(params, _token) {
|
|
23697
|
+
return this.codeActionsManager.resolveCodeAction(params);
|
|
22886
23698
|
}
|
|
22887
23699
|
async executeCommand(params, token, workDoneProgress) {
|
|
22888
|
-
if (params.command === Commands.
|
|
22889
|
-
const edit = params.arguments[0];
|
|
22890
|
-
await this.options.lspClient.applyWorkspaceEdit({
|
|
22891
|
-
edit: edit
|
|
22892
|
-
});
|
|
22893
|
-
} else if (params.command === Commands.APPLY_CODE_ACTION && params.arguments) {
|
|
22894
|
-
const codeAction = params.arguments[0];
|
|
22895
|
-
if (!await this.applyFileCodeEdits(codeAction.changes)) {
|
|
22896
|
-
return;
|
|
22897
|
-
}
|
|
22898
|
-
if (codeAction.commands?.length) {
|
|
22899
|
-
for (const command of codeAction.commands) {
|
|
22900
|
-
await this.tsClient.execute(CommandTypes.ApplyCodeActionCommand, {
|
|
22901
|
-
command: command
|
|
22902
|
-
}, token);
|
|
22903
|
-
}
|
|
22904
|
-
}
|
|
22905
|
-
} else if (params.command === Commands.APPLY_REFACTORING && params.arguments) {
|
|
23700
|
+
if (await this.commandManager.handle(params.command, ...params.arguments || [])) ; else if (params.command === Commands.APPLY_REFACTORING && params.arguments) {
|
|
22906
23701
|
const args = params.arguments[0];
|
|
22907
23702
|
const response = await this.tsClient.execute(CommandTypes.GetEditsForRefactor, args, token);
|
|
22908
23703
|
if (response.type !== 'response' || !response.body) {
|
|
22909
23704
|
return;
|
|
22910
23705
|
}
|
|
22911
23706
|
const {body: body} = response;
|
|
23707
|
+
if (body?.notApplicableReason) {
|
|
23708
|
+
throw new Error(body.notApplicableReason);
|
|
23709
|
+
}
|
|
22912
23710
|
if (!body?.edits.length) {
|
|
22913
23711
|
return;
|
|
22914
23712
|
}
|
|
@@ -23154,7 +23952,7 @@ class LspServer {
|
|
|
23154
23952
|
const diagnosticEvent = event;
|
|
23155
23953
|
if (diagnosticEvent.body?.diagnostics) {
|
|
23156
23954
|
const {file: file, diagnostics: diagnostics} = diagnosticEvent.body;
|
|
23157
|
-
this.
|
|
23955
|
+
this.diagnosticsManager.updateDiagnostics(getDignosticsKind(event), file, diagnostics);
|
|
23158
23956
|
}
|
|
23159
23957
|
}
|
|
23160
23958
|
}
|
|
@@ -23325,6 +24123,7 @@ function createLspConnection(options) {
|
|
|
23325
24123
|
connection.onDidCloseTextDocument(server.didCloseTextDocument.bind(server));
|
|
23326
24124
|
connection.onDidChangeTextDocument(server.didChangeTextDocument.bind(server));
|
|
23327
24125
|
connection.onCodeAction(server.codeAction.bind(server));
|
|
24126
|
+
connection.onCodeActionResolve(server.codeActionResolve.bind(server));
|
|
23328
24127
|
connection.onCodeLens(server.codeLens.bind(server));
|
|
23329
24128
|
connection.onCodeLensResolve(server.codeLensResolve.bind(server));
|
|
23330
24129
|
connection.onCompletion(server.completion.bind(server));
|