typescript-language-server 5.0.0 → 5.1.0
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 +16 -0
- package/README.md +119 -112
- package/lib/cli.mjs +1022 -344
- package/lib/cli.mjs.map +1 -1
- package/package.json +18 -18
package/lib/cli.mjs
CHANGED
|
@@ -1,21 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import fs$2, { promises, statSync, existsSync, readFileSync } from 'node:fs';
|
|
3
3
|
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
import require$$1 from 'node:child_process';
|
|
7
|
-
|
|
8
|
-
import * as path from 'node:path';
|
|
9
|
-
|
|
10
|
-
import path__default, { extname, resolve } from 'node:path';
|
|
11
|
-
|
|
12
|
-
import process$1 from 'node:process';
|
|
13
|
-
|
|
14
|
-
import require$$0$4, { promisify as promisify$1 } from 'node:util';
|
|
4
|
+
import { createRequire } from 'node:module';
|
|
15
5
|
|
|
16
|
-
import require$$0
|
|
6
|
+
import require$$0, { promisify } from 'util';
|
|
17
7
|
|
|
18
|
-
import require$$1
|
|
8
|
+
import require$$1 from 'path';
|
|
19
9
|
|
|
20
10
|
import require$$2 from 'os';
|
|
21
11
|
|
|
@@ -23,15 +13,19 @@ import crypto from 'crypto';
|
|
|
23
13
|
|
|
24
14
|
import require$$4 from 'net';
|
|
25
15
|
|
|
26
|
-
import require$$0$
|
|
16
|
+
import require$$0$1 from 'url';
|
|
27
17
|
|
|
28
|
-
import require$$0$
|
|
18
|
+
import require$$0$2 from 'fs';
|
|
29
19
|
|
|
30
20
|
import require$$3 from 'child_process';
|
|
31
21
|
|
|
32
|
-
import
|
|
22
|
+
import * as path from 'node:path';
|
|
23
|
+
|
|
24
|
+
import path__default, { extname, resolve } from 'node:path';
|
|
25
|
+
|
|
26
|
+
import require$$0$3 from 'constants';
|
|
33
27
|
|
|
34
|
-
import require$$0$
|
|
28
|
+
import require$$0$4 from 'stream';
|
|
35
29
|
|
|
36
30
|
import require$$5 from 'assert';
|
|
37
31
|
|
|
@@ -41,9 +35,13 @@ import 'node:fs/promises';
|
|
|
41
35
|
|
|
42
36
|
import stream from 'node:stream';
|
|
43
37
|
|
|
44
|
-
import {
|
|
38
|
+
import { promisify as promisify$1 } from 'node:util';
|
|
39
|
+
|
|
40
|
+
import ChildProcess from 'node:child_process';
|
|
41
|
+
|
|
42
|
+
import require$$1$1 from 'fs/promises';
|
|
45
43
|
|
|
46
|
-
import
|
|
44
|
+
import process$1 from 'node:process';
|
|
47
45
|
|
|
48
46
|
import { fileURLToPath } from 'node:url';
|
|
49
47
|
|
|
@@ -173,6 +171,36 @@ function requireArgument() {
|
|
|
173
171
|
|
|
174
172
|
var command = {};
|
|
175
173
|
|
|
174
|
+
const require$5 = createRequire(import.meta.url);
|
|
175
|
+
|
|
176
|
+
function __require$5() {
|
|
177
|
+
return require$5('node:events');
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const require$4 = createRequire(import.meta.url);
|
|
181
|
+
|
|
182
|
+
function __require$4() {
|
|
183
|
+
return require$4('node:child_process');
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const require$3 = createRequire(import.meta.url);
|
|
187
|
+
|
|
188
|
+
function __require$3() {
|
|
189
|
+
return require$3('node:path');
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const require$2 = createRequire(import.meta.url);
|
|
193
|
+
|
|
194
|
+
function __require$2() {
|
|
195
|
+
return require$2('node:fs');
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const require$1 = createRequire(import.meta.url);
|
|
199
|
+
|
|
200
|
+
function __require$1() {
|
|
201
|
+
return require$1('node:process');
|
|
202
|
+
}
|
|
203
|
+
|
|
176
204
|
var help = {};
|
|
177
205
|
|
|
178
206
|
var hasRequiredHelp;
|
|
@@ -751,11 +779,11 @@ var hasRequiredCommand;
|
|
|
751
779
|
function requireCommand() {
|
|
752
780
|
if (hasRequiredCommand) return command;
|
|
753
781
|
hasRequiredCommand = 1;
|
|
754
|
-
const EventEmitter =
|
|
755
|
-
const childProcess =
|
|
756
|
-
const path =
|
|
757
|
-
const fs =
|
|
758
|
-
const process =
|
|
782
|
+
const EventEmitter = __require$5().EventEmitter;
|
|
783
|
+
const childProcess = __require$4();
|
|
784
|
+
const path = __require$3();
|
|
785
|
+
const fs = __require$2();
|
|
786
|
+
const process = __require$1();
|
|
759
787
|
const {Argument: Argument, humanReadableArgName: humanReadableArgName} = requireArgument();
|
|
760
788
|
const {CommanderError: CommanderError} = requireError();
|
|
761
789
|
const {Help: Help, stripColor: stripColor} = requireHelp();
|
|
@@ -1605,7 +1633,7 @@ function requireCommand() {
|
|
|
1605
1633
|
return arg.length > 1 && arg[0] === '-';
|
|
1606
1634
|
}
|
|
1607
1635
|
const negativeNumberArg = arg => {
|
|
1608
|
-
if (
|
|
1636
|
+
if (!/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(arg)) return false;
|
|
1609
1637
|
return !this._getCommandAndAncestors().some(cmd => cmd.options.map(opt => opt.short).some(short => /^-\d$/.test(short)));
|
|
1610
1638
|
};
|
|
1611
1639
|
let activeVariadicOption = null;
|
|
@@ -2127,6 +2155,12 @@ const {program: program$1, createCommand: createCommand, createArgument: createA
|
|
|
2127
2155
|
|
|
2128
2156
|
var main$3 = {};
|
|
2129
2157
|
|
|
2158
|
+
const require = createRequire(import.meta.url);
|
|
2159
|
+
|
|
2160
|
+
function __require() {
|
|
2161
|
+
return require('node:util');
|
|
2162
|
+
}
|
|
2163
|
+
|
|
2130
2164
|
var is$2 = {};
|
|
2131
2165
|
|
|
2132
2166
|
var hasRequiredIs$2;
|
|
@@ -5334,7 +5368,7 @@ function requireRil() {
|
|
|
5334
5368
|
Object.defineProperty(ril, '__esModule', {
|
|
5335
5369
|
value: true
|
|
5336
5370
|
});
|
|
5337
|
-
const util_1 = require$$0
|
|
5371
|
+
const util_1 = require$$0;
|
|
5338
5372
|
const api_1 = requireApi$2();
|
|
5339
5373
|
class MessageBuffer extends api_1.AbstractMessageBuffer {
|
|
5340
5374
|
constructor(encoding = 'utf-8') {
|
|
@@ -5522,7 +5556,7 @@ function requireMain$3() {
|
|
|
5522
5556
|
exports.createMessageConnection = exports.createServerSocketTransport = exports.createClientSocketTransport = exports.createServerPipeTransport = exports.createClientPipeTransport = exports.generateRandomPipeName = exports.StreamMessageWriter = exports.StreamMessageReader = exports.SocketMessageWriter = exports.SocketMessageReader = exports.PortMessageWriter = exports.PortMessageReader = exports.IPCMessageWriter = exports.IPCMessageReader = void 0;
|
|
5523
5557
|
const ril_1 = requireRil();
|
|
5524
5558
|
ril_1.default.install();
|
|
5525
|
-
const path = require$$1
|
|
5559
|
+
const path = require$$1;
|
|
5526
5560
|
const os = require$$2;
|
|
5527
5561
|
const crypto_1 = crypto;
|
|
5528
5562
|
const net_1 = require$$4;
|
|
@@ -11133,9 +11167,9 @@ function requireFiles() {
|
|
|
11133
11167
|
value: true
|
|
11134
11168
|
});
|
|
11135
11169
|
files.resolveModulePath = files.FileSystem = files.resolveGlobalYarnPath = files.resolveGlobalNodePath = files.resolve = files.uriToFilePath = void 0;
|
|
11136
|
-
const url = require$$0$
|
|
11137
|
-
const path = require$$1
|
|
11138
|
-
const fs = require$$0$
|
|
11170
|
+
const url = require$$0$1;
|
|
11171
|
+
const path = require$$1;
|
|
11172
|
+
const fs = require$$0$2;
|
|
11139
11173
|
const child_process_1 = require$$3;
|
|
11140
11174
|
function uriToFilePath(uri) {
|
|
11141
11175
|
let parsed = url.parse(uri);
|
|
@@ -11468,7 +11502,7 @@ function requireMain() {
|
|
|
11468
11502
|
value: true
|
|
11469
11503
|
});
|
|
11470
11504
|
exports.createConnection = exports.Files = void 0;
|
|
11471
|
-
const node_util_1 =
|
|
11505
|
+
const node_util_1 = __require();
|
|
11472
11506
|
const Is = requireIs$2();
|
|
11473
11507
|
const server_1 = requireServer();
|
|
11474
11508
|
const fm = requireFiles();
|
|
@@ -11902,7 +11936,7 @@ var hasRequiredPolyfills;
|
|
|
11902
11936
|
function requirePolyfills() {
|
|
11903
11937
|
if (hasRequiredPolyfills) return polyfills;
|
|
11904
11938
|
hasRequiredPolyfills = 1;
|
|
11905
|
-
var constants = require$$0$
|
|
11939
|
+
var constants = require$$0$3;
|
|
11906
11940
|
var origCwd = process.cwd;
|
|
11907
11941
|
var cwd = null;
|
|
11908
11942
|
var platform = process.env.GRACEFUL_FS_PLATFORM || process.platform;
|
|
@@ -12174,7 +12208,7 @@ var hasRequiredLegacyStreams;
|
|
|
12174
12208
|
function requireLegacyStreams() {
|
|
12175
12209
|
if (hasRequiredLegacyStreams) return legacyStreams;
|
|
12176
12210
|
hasRequiredLegacyStreams = 1;
|
|
12177
|
-
var Stream = require$$0$
|
|
12211
|
+
var Stream = require$$0$4.Stream;
|
|
12178
12212
|
legacyStreams = legacy;
|
|
12179
12213
|
function legacy(fs) {
|
|
12180
12214
|
return {
|
|
@@ -12298,11 +12332,11 @@ var hasRequiredGracefulFs;
|
|
|
12298
12332
|
function requireGracefulFs() {
|
|
12299
12333
|
if (hasRequiredGracefulFs) return gracefulFs;
|
|
12300
12334
|
hasRequiredGracefulFs = 1;
|
|
12301
|
-
var fs = require$$0$
|
|
12335
|
+
var fs = require$$0$2;
|
|
12302
12336
|
var polyfills = requirePolyfills();
|
|
12303
12337
|
var legacy = requireLegacyStreams();
|
|
12304
12338
|
var clone = requireClone();
|
|
12305
|
-
var util = require$$0
|
|
12339
|
+
var util = require$$0;
|
|
12306
12340
|
var gracefulQueue;
|
|
12307
12341
|
var previousSymbol;
|
|
12308
12342
|
if (typeof Symbol === 'function' && typeof Symbol.for === 'function') {
|
|
@@ -12701,7 +12735,7 @@ var hasRequiredUtils$1;
|
|
|
12701
12735
|
function requireUtils$1() {
|
|
12702
12736
|
if (hasRequiredUtils$1) return utils$1;
|
|
12703
12737
|
hasRequiredUtils$1 = 1;
|
|
12704
|
-
const path = require$$1
|
|
12738
|
+
const path = require$$1;
|
|
12705
12739
|
utils$1.checkPath = function checkPath(pth) {
|
|
12706
12740
|
if (process.platform === 'win32') {
|
|
12707
12741
|
const pathHasInvalidWinCharacters = /[<>:"|?*]/.test(pth.replace(path.parse(pth).root, ''));
|
|
@@ -12834,7 +12868,7 @@ function requireStat() {
|
|
|
12834
12868
|
if (hasRequiredStat) return stat;
|
|
12835
12869
|
hasRequiredStat = 1;
|
|
12836
12870
|
const fs = requireFs();
|
|
12837
|
-
const path = require$$1
|
|
12871
|
+
const path = require$$1;
|
|
12838
12872
|
const u = requireUniversalify().fromPromise;
|
|
12839
12873
|
function getStats(src, dest, opts) {
|
|
12840
12874
|
const statFunc = opts.dereference ? file => fs.stat(file, {
|
|
@@ -12990,6 +13024,28 @@ function requireStat() {
|
|
|
12990
13024
|
return stat;
|
|
12991
13025
|
}
|
|
12992
13026
|
|
|
13027
|
+
var async;
|
|
13028
|
+
|
|
13029
|
+
var hasRequiredAsync;
|
|
13030
|
+
|
|
13031
|
+
function requireAsync() {
|
|
13032
|
+
if (hasRequiredAsync) return async;
|
|
13033
|
+
hasRequiredAsync = 1;
|
|
13034
|
+
async function asyncIteratorConcurrentProcess(iterator, fn) {
|
|
13035
|
+
const promises = [];
|
|
13036
|
+
for await (const item of iterator) {
|
|
13037
|
+
promises.push(fn(item).then(() => null, err => err ?? new Error('unknown error')));
|
|
13038
|
+
}
|
|
13039
|
+
await Promise.all(promises.map(promise => promise.then(possibleErr => {
|
|
13040
|
+
if (possibleErr !== null) throw possibleErr;
|
|
13041
|
+
})));
|
|
13042
|
+
}
|
|
13043
|
+
async = {
|
|
13044
|
+
asyncIteratorConcurrentProcess: asyncIteratorConcurrentProcess
|
|
13045
|
+
};
|
|
13046
|
+
return async;
|
|
13047
|
+
}
|
|
13048
|
+
|
|
12993
13049
|
var copy_1;
|
|
12994
13050
|
|
|
12995
13051
|
var hasRequiredCopy$1;
|
|
@@ -12998,11 +13054,12 @@ function requireCopy$1() {
|
|
|
12998
13054
|
if (hasRequiredCopy$1) return copy_1;
|
|
12999
13055
|
hasRequiredCopy$1 = 1;
|
|
13000
13056
|
const fs = requireFs();
|
|
13001
|
-
const path = require$$1
|
|
13057
|
+
const path = require$$1;
|
|
13002
13058
|
const {mkdirs: mkdirs} = requireMkdirs();
|
|
13003
13059
|
const {pathExists: pathExists} = requirePathExists();
|
|
13004
13060
|
const {utimesMillis: utimesMillis} = requireUtimes();
|
|
13005
13061
|
const stat = requireStat();
|
|
13062
|
+
const {asyncIteratorConcurrentProcess: asyncIteratorConcurrentProcess} = requireAsync();
|
|
13006
13063
|
async function copy(src, dest, opts = {}) {
|
|
13007
13064
|
if (typeof opts === 'function') {
|
|
13008
13065
|
opts = {
|
|
@@ -13070,17 +13127,15 @@ function requireCopy$1() {
|
|
|
13070
13127
|
if (!destStat) {
|
|
13071
13128
|
await fs.mkdir(dest);
|
|
13072
13129
|
}
|
|
13073
|
-
|
|
13074
|
-
for await (const item of await fs.opendir(src)) {
|
|
13130
|
+
await asyncIteratorConcurrentProcess(await fs.opendir(src), async item => {
|
|
13075
13131
|
const srcItem = path.join(src, item.name);
|
|
13076
13132
|
const destItem = path.join(dest, item.name);
|
|
13077
|
-
|
|
13078
|
-
|
|
13079
|
-
|
|
13080
|
-
|
|
13081
|
-
}
|
|
13082
|
-
}
|
|
13083
|
-
await Promise.all(promises);
|
|
13133
|
+
const include = await runFilter(srcItem, destItem, opts);
|
|
13134
|
+
if (include) {
|
|
13135
|
+
const {destStat: destStat} = await stat.checkPaths(srcItem, destItem, 'copy', opts);
|
|
13136
|
+
await getStatsAndPerformCopy(destStat, srcItem, destItem, opts);
|
|
13137
|
+
}
|
|
13138
|
+
});
|
|
13084
13139
|
if (!destStat) {
|
|
13085
13140
|
await fs.chmod(dest, srcStat.mode);
|
|
13086
13141
|
}
|
|
@@ -13124,7 +13179,7 @@ function requireCopySync() {
|
|
|
13124
13179
|
if (hasRequiredCopySync) return copySync_1;
|
|
13125
13180
|
hasRequiredCopySync = 1;
|
|
13126
13181
|
const fs = requireGracefulFs();
|
|
13127
|
-
const path = require$$1
|
|
13182
|
+
const path = require$$1;
|
|
13128
13183
|
const mkdirsSync = requireMkdirs().mkdirsSync;
|
|
13129
13184
|
const utimesMillisSync = requireUtimes().utimesMillisSync;
|
|
13130
13185
|
const stat = requireStat();
|
|
@@ -13301,7 +13356,7 @@ function requireEmpty() {
|
|
|
13301
13356
|
hasRequiredEmpty = 1;
|
|
13302
13357
|
const u = requireUniversalify().fromPromise;
|
|
13303
13358
|
const fs = requireFs();
|
|
13304
|
-
const path = require$$1
|
|
13359
|
+
const path = require$$1;
|
|
13305
13360
|
const mkdir = requireMkdirs();
|
|
13306
13361
|
const remove = requireRemove();
|
|
13307
13362
|
const emptyDir = u(async function emptyDir(dir) {
|
|
@@ -13342,7 +13397,7 @@ function requireFile() {
|
|
|
13342
13397
|
if (hasRequiredFile) return file$1;
|
|
13343
13398
|
hasRequiredFile = 1;
|
|
13344
13399
|
const u = requireUniversalify().fromPromise;
|
|
13345
|
-
const path = require$$1
|
|
13400
|
+
const path = require$$1;
|
|
13346
13401
|
const fs = requireFs();
|
|
13347
13402
|
const mkdir = requireMkdirs();
|
|
13348
13403
|
async function createFile(file) {
|
|
@@ -13401,7 +13456,7 @@ function requireLink() {
|
|
|
13401
13456
|
if (hasRequiredLink) return link;
|
|
13402
13457
|
hasRequiredLink = 1;
|
|
13403
13458
|
const u = requireUniversalify().fromPromise;
|
|
13404
|
-
const path = require$$1
|
|
13459
|
+
const path = require$$1;
|
|
13405
13460
|
const fs = requireFs();
|
|
13406
13461
|
const mkdir = requireMkdirs();
|
|
13407
13462
|
const {pathExists: pathExists} = requirePathExists();
|
|
@@ -13458,7 +13513,7 @@ var hasRequiredSymlinkPaths;
|
|
|
13458
13513
|
function requireSymlinkPaths() {
|
|
13459
13514
|
if (hasRequiredSymlinkPaths) return symlinkPaths_1;
|
|
13460
13515
|
hasRequiredSymlinkPaths = 1;
|
|
13461
|
-
const path = require$$1
|
|
13516
|
+
const path = require$$1;
|
|
13462
13517
|
const fs = requireFs();
|
|
13463
13518
|
const {pathExists: pathExists} = requirePathExists();
|
|
13464
13519
|
const u = requireUniversalify().fromPromise;
|
|
@@ -13571,7 +13626,7 @@ function requireSymlink() {
|
|
|
13571
13626
|
if (hasRequiredSymlink) return symlink;
|
|
13572
13627
|
hasRequiredSymlink = 1;
|
|
13573
13628
|
const u = requireUniversalify().fromPromise;
|
|
13574
|
-
const path = require$$1
|
|
13629
|
+
const path = require$$1;
|
|
13575
13630
|
const fs = requireFs();
|
|
13576
13631
|
const {mkdirs: mkdirs, mkdirsSync: mkdirsSync} = requireMkdirs();
|
|
13577
13632
|
const {symlinkPaths: symlinkPaths, symlinkPathsSync: symlinkPathsSync} = requireSymlinkPaths();
|
|
@@ -13683,7 +13738,7 @@ function requireJsonfile$1() {
|
|
|
13683
13738
|
try {
|
|
13684
13739
|
_fs = requireGracefulFs();
|
|
13685
13740
|
} catch (_) {
|
|
13686
|
-
_fs = require$$0$
|
|
13741
|
+
_fs = require$$0$2;
|
|
13687
13742
|
}
|
|
13688
13743
|
const universalify = requireUniversalify();
|
|
13689
13744
|
const {stringify: stringify, stripBom: stripBom} = requireUtils();
|
|
@@ -13778,7 +13833,7 @@ function requireOutputFile() {
|
|
|
13778
13833
|
hasRequiredOutputFile = 1;
|
|
13779
13834
|
const u = requireUniversalify().fromPromise;
|
|
13780
13835
|
const fs = requireFs();
|
|
13781
|
-
const path = require$$1
|
|
13836
|
+
const path = require$$1;
|
|
13782
13837
|
const mkdir = requireMkdirs();
|
|
13783
13838
|
const pathExists = requirePathExists().pathExists;
|
|
13784
13839
|
async function outputFile(file, data, encoding = 'utf-8') {
|
|
@@ -13865,7 +13920,7 @@ function requireMove$1() {
|
|
|
13865
13920
|
if (hasRequiredMove$1) return move_1;
|
|
13866
13921
|
hasRequiredMove$1 = 1;
|
|
13867
13922
|
const fs = requireFs();
|
|
13868
|
-
const path = require$$1
|
|
13923
|
+
const path = require$$1;
|
|
13869
13924
|
const {copy: copy} = requireCopy();
|
|
13870
13925
|
const {remove: remove} = requireRemove();
|
|
13871
13926
|
const {mkdirp: mkdirp} = requireMkdirs();
|
|
@@ -13920,7 +13975,7 @@ function requireMoveSync() {
|
|
|
13920
13975
|
if (hasRequiredMoveSync) return moveSync_1;
|
|
13921
13976
|
hasRequiredMoveSync = 1;
|
|
13922
13977
|
const fs = requireGracefulFs();
|
|
13923
|
-
const path = require$$1
|
|
13978
|
+
const path = require$$1;
|
|
13924
13979
|
const copySync = requireCopy().copySync;
|
|
13925
13980
|
const removeSync = requireRemove().removeSync;
|
|
13926
13981
|
const mkdirpSync = requireMkdirs().mkdirpSync;
|
|
@@ -15205,6 +15260,9 @@ function requireIdentifiers() {
|
|
|
15205
15260
|
hasRequiredIdentifiers = 1;
|
|
15206
15261
|
const numeric = /^[0-9]+$/;
|
|
15207
15262
|
const compareIdentifiers = (a, b) => {
|
|
15263
|
+
if (typeof a === 'number' && typeof b === 'number') {
|
|
15264
|
+
return a === b ? 0 : a < b ? -1 : 1;
|
|
15265
|
+
}
|
|
15208
15266
|
const anum = numeric.test(a);
|
|
15209
15267
|
const bnum = numeric.test(b);
|
|
15210
15268
|
if (anum && bnum) {
|
|
@@ -15312,7 +15370,25 @@ function requireSemver$1() {
|
|
|
15312
15370
|
if (!(other instanceof SemVer)) {
|
|
15313
15371
|
other = new SemVer(other, this.options);
|
|
15314
15372
|
}
|
|
15315
|
-
|
|
15373
|
+
if (this.major < other.major) {
|
|
15374
|
+
return -1;
|
|
15375
|
+
}
|
|
15376
|
+
if (this.major > other.major) {
|
|
15377
|
+
return 1;
|
|
15378
|
+
}
|
|
15379
|
+
if (this.minor < other.minor) {
|
|
15380
|
+
return -1;
|
|
15381
|
+
}
|
|
15382
|
+
if (this.minor > other.minor) {
|
|
15383
|
+
return 1;
|
|
15384
|
+
}
|
|
15385
|
+
if (this.patch < other.patch) {
|
|
15386
|
+
return -1;
|
|
15387
|
+
}
|
|
15388
|
+
if (this.patch > other.patch) {
|
|
15389
|
+
return 1;
|
|
15390
|
+
}
|
|
15391
|
+
return 0;
|
|
15316
15392
|
}
|
|
15317
15393
|
comparePre(other) {
|
|
15318
15394
|
if (!(other instanceof SemVer)) {
|
|
@@ -16140,6 +16216,7 @@ function requireRange() {
|
|
|
16140
16216
|
return result;
|
|
16141
16217
|
};
|
|
16142
16218
|
const parseComparator = (comp, options) => {
|
|
16219
|
+
comp = comp.replace(re[t.BUILD], '');
|
|
16143
16220
|
debug('comp', comp, options);
|
|
16144
16221
|
comp = replaceCarets(comp, options);
|
|
16145
16222
|
debug('caret', comp);
|
|
@@ -18191,7 +18268,7 @@ class SingleTsServer {
|
|
|
18191
18268
|
tryCancelRequest(seq, command) {
|
|
18192
18269
|
try {
|
|
18193
18270
|
if (this._requestQueue.tryDeletePendingRequest(seq)) {
|
|
18194
|
-
this.logTrace(`Canceled request with sequence number ${seq}`);
|
|
18271
|
+
this.logTrace(`Canceled pending request with sequence number ${seq}`);
|
|
18195
18272
|
return true;
|
|
18196
18273
|
}
|
|
18197
18274
|
if (this._requestCanceller.tryCancelOngoingRequest(seq)) {
|
|
@@ -18466,7 +18543,7 @@ class NodeTsServerProcessFactory {
|
|
|
18466
18543
|
if (useIpc) {
|
|
18467
18544
|
runtimeArgs.push('--useNodeIpc');
|
|
18468
18545
|
}
|
|
18469
|
-
const childProcess =
|
|
18546
|
+
const childProcess = ChildProcess.fork(tsServerPath, runtimeArgs, {
|
|
18470
18547
|
silent: true,
|
|
18471
18548
|
cwd: undefined,
|
|
18472
18549
|
env: generatePatchedEnv(process.env, tsServerPath),
|
|
@@ -19305,7 +19382,8 @@ class TsClient {
|
|
|
19305
19382
|
executions[0].catch(err => this.fatalError(command, err));
|
|
19306
19383
|
}
|
|
19307
19384
|
if (command === CommandTypes.UpdateOpen) {
|
|
19308
|
-
|
|
19385
|
+
const executionsWithResults = executions.filter(e => e !== undefined);
|
|
19386
|
+
Promise.all(executionsWithResults).then(() => {
|
|
19309
19387
|
this.loadingIndicator.reset();
|
|
19310
19388
|
});
|
|
19311
19389
|
}
|
|
@@ -19375,43 +19453,124 @@ class TsClient {
|
|
|
19375
19453
|
}
|
|
19376
19454
|
}
|
|
19377
19455
|
|
|
19378
|
-
const pDebounce = (
|
|
19456
|
+
const pDebounce = (functionToDebounce, wait, options = {}) => {
|
|
19379
19457
|
if (!Number.isFinite(wait)) {
|
|
19380
19458
|
throw new TypeError('Expected `wait` to be a finite number');
|
|
19381
19459
|
}
|
|
19382
19460
|
let leadingValue;
|
|
19383
19461
|
let timeout;
|
|
19384
|
-
let
|
|
19462
|
+
let promiseHandlers = [];
|
|
19463
|
+
const onAbort = () => {
|
|
19464
|
+
clearTimeout(timeout);
|
|
19465
|
+
timeout = undefined;
|
|
19466
|
+
try {
|
|
19467
|
+
options.signal?.throwIfAborted();
|
|
19468
|
+
} catch (error) {
|
|
19469
|
+
for (const {reject: reject} of promiseHandlers) {
|
|
19470
|
+
reject(error);
|
|
19471
|
+
}
|
|
19472
|
+
promiseHandlers = [];
|
|
19473
|
+
}
|
|
19474
|
+
};
|
|
19385
19475
|
return function(...arguments_) {
|
|
19386
|
-
return new Promise(resolve => {
|
|
19476
|
+
return new Promise((resolve, reject) => {
|
|
19477
|
+
try {
|
|
19478
|
+
options.signal?.throwIfAborted();
|
|
19479
|
+
} catch (error) {
|
|
19480
|
+
reject(error);
|
|
19481
|
+
return;
|
|
19482
|
+
}
|
|
19387
19483
|
const shouldCallNow = options.before && !timeout;
|
|
19388
19484
|
clearTimeout(timeout);
|
|
19389
|
-
timeout = setTimeout(() => {
|
|
19390
|
-
timeout =
|
|
19391
|
-
const
|
|
19392
|
-
|
|
19393
|
-
|
|
19485
|
+
timeout = setTimeout(async () => {
|
|
19486
|
+
timeout = undefined;
|
|
19487
|
+
const currentHandlers = promiseHandlers;
|
|
19488
|
+
promiseHandlers = [];
|
|
19489
|
+
try {
|
|
19490
|
+
const result = options.before ? leadingValue : await functionToDebounce.apply(this, arguments_);
|
|
19491
|
+
for (const {resolve: resolveFunction} of currentHandlers) {
|
|
19492
|
+
resolveFunction(result);
|
|
19493
|
+
}
|
|
19494
|
+
} catch (error) {
|
|
19495
|
+
for (const {reject: rejectFunction} of currentHandlers) {
|
|
19496
|
+
rejectFunction(error);
|
|
19497
|
+
}
|
|
19394
19498
|
}
|
|
19395
|
-
|
|
19499
|
+
leadingValue = undefined;
|
|
19500
|
+
options.signal?.removeEventListener('abort', onAbort);
|
|
19396
19501
|
}, wait);
|
|
19397
19502
|
if (shouldCallNow) {
|
|
19398
|
-
|
|
19399
|
-
|
|
19503
|
+
(async () => {
|
|
19504
|
+
try {
|
|
19505
|
+
leadingValue = await functionToDebounce.apply(this, arguments_);
|
|
19506
|
+
resolve(leadingValue);
|
|
19507
|
+
} catch (error) {
|
|
19508
|
+
reject(error);
|
|
19509
|
+
}
|
|
19510
|
+
})();
|
|
19400
19511
|
} else {
|
|
19401
|
-
|
|
19512
|
+
promiseHandlers.push({
|
|
19513
|
+
resolve: resolve,
|
|
19514
|
+
reject: reject
|
|
19515
|
+
});
|
|
19516
|
+
if (options.signal && promiseHandlers.length === 1) {
|
|
19517
|
+
options.signal.addEventListener('abort', onAbort, {
|
|
19518
|
+
once: true
|
|
19519
|
+
});
|
|
19520
|
+
}
|
|
19402
19521
|
}
|
|
19403
19522
|
});
|
|
19404
19523
|
};
|
|
19405
19524
|
};
|
|
19406
19525
|
|
|
19407
|
-
pDebounce.promise = function_ => {
|
|
19526
|
+
pDebounce.promise = (function_, options = {}) => {
|
|
19408
19527
|
let currentPromise;
|
|
19528
|
+
let queuedCall;
|
|
19409
19529
|
return async function(...arguments_) {
|
|
19410
19530
|
if (currentPromise) {
|
|
19411
|
-
|
|
19531
|
+
if (!options.after) {
|
|
19532
|
+
return currentPromise;
|
|
19533
|
+
}
|
|
19534
|
+
queuedCall ??= {
|
|
19535
|
+
resolvers: []
|
|
19536
|
+
};
|
|
19537
|
+
queuedCall.arguments = arguments_;
|
|
19538
|
+
queuedCall.context = this;
|
|
19539
|
+
return new Promise((resolve, reject) => {
|
|
19540
|
+
queuedCall.resolvers.push({
|
|
19541
|
+
resolve: resolve,
|
|
19542
|
+
reject: reject
|
|
19543
|
+
});
|
|
19544
|
+
});
|
|
19412
19545
|
}
|
|
19546
|
+
currentPromise = (async () => {
|
|
19547
|
+
let result;
|
|
19548
|
+
let initialError;
|
|
19549
|
+
try {
|
|
19550
|
+
result = await function_.apply(this, arguments_);
|
|
19551
|
+
} catch (error) {
|
|
19552
|
+
initialError = error;
|
|
19553
|
+
}
|
|
19554
|
+
while (queuedCall) {
|
|
19555
|
+
const call = queuedCall;
|
|
19556
|
+
queuedCall = undefined;
|
|
19557
|
+
try {
|
|
19558
|
+
const queuedResult = await function_.apply(call.context, call.arguments);
|
|
19559
|
+
for (const {resolve: resolve} of call.resolvers) {
|
|
19560
|
+
resolve(queuedResult);
|
|
19561
|
+
}
|
|
19562
|
+
} catch (error) {
|
|
19563
|
+
for (const {reject: reject} of call.resolvers) {
|
|
19564
|
+
reject(error);
|
|
19565
|
+
}
|
|
19566
|
+
}
|
|
19567
|
+
}
|
|
19568
|
+
if (initialError) {
|
|
19569
|
+
throw initialError;
|
|
19570
|
+
}
|
|
19571
|
+
return result;
|
|
19572
|
+
})();
|
|
19413
19573
|
try {
|
|
19414
|
-
currentPromise = function_.apply(this, arguments_);
|
|
19415
19574
|
return await currentPromise;
|
|
19416
19575
|
} finally {
|
|
19417
19576
|
currentPromise = undefined;
|
|
@@ -19741,7 +19900,7 @@ class FileDiagnostics {
|
|
|
19741
19900
|
}
|
|
19742
19901
|
}
|
|
19743
19902
|
|
|
19744
|
-
class
|
|
19903
|
+
class DiagnosticsManager {
|
|
19745
19904
|
constructor(publishDiagnostics, client, features, logger) {
|
|
19746
19905
|
this.publishDiagnostics = publishDiagnostics;
|
|
19747
19906
|
this.client = client;
|
|
@@ -19858,8 +20017,6 @@ class TSServerRequestCommand {
|
|
|
19858
20017
|
TSServerRequestCommand.id = 'typescript.tsserverRequest';
|
|
19859
20018
|
|
|
19860
20019
|
const Commands = {
|
|
19861
|
-
APPLY_WORKSPACE_EDIT: '_typescript.applyWorkspaceEdit',
|
|
19862
|
-
APPLY_CODE_ACTION: '_typescript.applyCodeAction',
|
|
19863
20020
|
APPLY_REFACTORING: '_typescript.applyRefactoring',
|
|
19864
20021
|
CONFIGURE_PLUGIN: '_typescript.configurePlugin',
|
|
19865
20022
|
ORGANIZE_IMPORTS: '_typescript.organizeImports',
|
|
@@ -20682,19 +20839,6 @@ function toTsTriggerReason(context) {
|
|
|
20682
20839
|
}
|
|
20683
20840
|
}
|
|
20684
20841
|
|
|
20685
|
-
function provideQuickFix(response, client) {
|
|
20686
|
-
if (!response?.body) {
|
|
20687
|
-
return [];
|
|
20688
|
-
}
|
|
20689
|
-
return response.body.map(fix => mainExports$2.CodeAction.create(fix.description, {
|
|
20690
|
-
title: fix.description,
|
|
20691
|
-
command: Commands.APPLY_WORKSPACE_EDIT,
|
|
20692
|
-
arguments: [ {
|
|
20693
|
-
documentChanges: fix.changes.map(c => toTextDocumentEdit(c, client))
|
|
20694
|
-
} ]
|
|
20695
|
-
}, mainExports$2.CodeActionKind.QuickFix));
|
|
20696
|
-
}
|
|
20697
|
-
|
|
20698
20842
|
var CodeActionKind$1;
|
|
20699
20843
|
|
|
20700
20844
|
(function(CodeActionKind) {
|
|
@@ -21298,8 +21442,9 @@ function areFileConfigurationsEqual(a, b) {
|
|
|
21298
21442
|
}
|
|
21299
21443
|
|
|
21300
21444
|
class FileConfigurationManager {
|
|
21301
|
-
constructor(client, onCaseInsensitiveFileSystem) {
|
|
21445
|
+
constructor(client, lspClient, onCaseInsensitiveFileSystem) {
|
|
21302
21446
|
this.client = client;
|
|
21447
|
+
this.lspClient = lspClient;
|
|
21303
21448
|
this.tsPreferences = deepmerge({}, DEFAULT_TSSERVER_PREFERENCES);
|
|
21304
21449
|
this.workspaceConfiguration = deepmerge({}, DEFAULT_WORKSPACE_CONFIGURATION);
|
|
21305
21450
|
this.formatOptions = new ResourceMap(undefined, {
|
|
@@ -21344,7 +21489,15 @@ class FileConfigurationManager {
|
|
|
21344
21489
|
});
|
|
21345
21490
|
}
|
|
21346
21491
|
async ensureConfigurationForDocument(document, token) {
|
|
21347
|
-
|
|
21492
|
+
const formattingOptions = await this.getFormattingOptions(document);
|
|
21493
|
+
return this.ensureConfigurationOptions(document, formattingOptions, token);
|
|
21494
|
+
}
|
|
21495
|
+
async getFormattingOptions(document) {
|
|
21496
|
+
const formatConfiguration = await this.lspClient.getWorkspaceConfiguration(document.uri.toString(), 'formattingOptions') || {};
|
|
21497
|
+
return {
|
|
21498
|
+
tabSize: typeof formatConfiguration.tabSize === 'number' ? formatConfiguration.tabSize : undefined,
|
|
21499
|
+
insertSpaces: typeof formatConfiguration.insertSpaces === 'boolean' ? formatConfiguration.insertSpaces : undefined
|
|
21500
|
+
};
|
|
21348
21501
|
}
|
|
21349
21502
|
async ensureConfigurationOptions(document, options, token) {
|
|
21350
21503
|
const currentOptions = this.getFileOptions(document, options);
|
|
@@ -21440,187 +21593,6 @@ class FileConfigurationManager {
|
|
|
21440
21593
|
}
|
|
21441
21594
|
}
|
|
21442
21595
|
|
|
21443
|
-
const variableDeclaredButNeverUsed = new Set([ 6196, 6133 ]);
|
|
21444
|
-
|
|
21445
|
-
const unreachableCode$1 = new Set([ 7027 ]);
|
|
21446
|
-
|
|
21447
|
-
const incorrectlyImplementsInterface = new Set([ 2420 ]);
|
|
21448
|
-
|
|
21449
|
-
const cannotFindName = new Set([ 2552, 2304 ]);
|
|
21450
|
-
|
|
21451
|
-
const asyncOnlyAllowedInAsyncFunctions = new Set([ 1308 ]);
|
|
21452
|
-
|
|
21453
|
-
const awaitInSyncFunction = 'fixAwaitInSyncFunction';
|
|
21454
|
-
|
|
21455
|
-
const classIncorrectlyImplementsInterface = 'fixClassIncorrectlyImplementsInterface';
|
|
21456
|
-
|
|
21457
|
-
const unreachableCode = 'fixUnreachableCode';
|
|
21458
|
-
|
|
21459
|
-
const unusedIdentifier = 'unusedIdentifier';
|
|
21460
|
-
|
|
21461
|
-
const fixImport = 'import';
|
|
21462
|
-
|
|
21463
|
-
async function buildIndividualFixes(fixes, client, file, diagnostics) {
|
|
21464
|
-
const edits = [];
|
|
21465
|
-
for (const diagnostic of diagnostics) {
|
|
21466
|
-
for (const {codes: codes, fixName: fixName} of fixes) {
|
|
21467
|
-
if (!codes.has(diagnostic.code)) {
|
|
21468
|
-
continue;
|
|
21469
|
-
}
|
|
21470
|
-
const args = {
|
|
21471
|
-
...Range.toFileRangeRequestArgs(file, diagnostic.range),
|
|
21472
|
-
errorCodes: [ +diagnostic.code ]
|
|
21473
|
-
};
|
|
21474
|
-
const response = await client.execute(CommandTypes.GetCodeFixes, args);
|
|
21475
|
-
if (response.type !== 'response') {
|
|
21476
|
-
continue;
|
|
21477
|
-
}
|
|
21478
|
-
const fix = response.body?.find(fix => fix.fixName === fixName);
|
|
21479
|
-
if (fix) {
|
|
21480
|
-
edits.push(...fix.changes.map(change => toTextDocumentEdit(change, client)));
|
|
21481
|
-
break;
|
|
21482
|
-
}
|
|
21483
|
-
}
|
|
21484
|
-
}
|
|
21485
|
-
return edits;
|
|
21486
|
-
}
|
|
21487
|
-
|
|
21488
|
-
async function buildCombinedFix(fixes, client, file, diagnostics) {
|
|
21489
|
-
const edits = [];
|
|
21490
|
-
for (const diagnostic of diagnostics) {
|
|
21491
|
-
for (const {codes: codes, fixName: fixName} of fixes) {
|
|
21492
|
-
if (!codes.has(diagnostic.code)) {
|
|
21493
|
-
continue;
|
|
21494
|
-
}
|
|
21495
|
-
const args = {
|
|
21496
|
-
...Range.toFileRangeRequestArgs(file, diagnostic.range),
|
|
21497
|
-
errorCodes: [ +diagnostic.code ]
|
|
21498
|
-
};
|
|
21499
|
-
const response = await client.execute(CommandTypes.GetCodeFixes, args);
|
|
21500
|
-
if (response.type !== 'response' || !response.body?.length) {
|
|
21501
|
-
continue;
|
|
21502
|
-
}
|
|
21503
|
-
const fix = response.body?.find(fix => fix.fixName === fixName);
|
|
21504
|
-
if (!fix) {
|
|
21505
|
-
continue;
|
|
21506
|
-
}
|
|
21507
|
-
if (!fix.fixId) {
|
|
21508
|
-
edits.push(...fix.changes.map(change => toTextDocumentEdit(change, client)));
|
|
21509
|
-
return edits;
|
|
21510
|
-
}
|
|
21511
|
-
const combinedArgs = {
|
|
21512
|
-
scope: {
|
|
21513
|
-
type: 'file',
|
|
21514
|
-
args: {
|
|
21515
|
-
file: file
|
|
21516
|
-
}
|
|
21517
|
-
},
|
|
21518
|
-
fixId: fix.fixId
|
|
21519
|
-
};
|
|
21520
|
-
const combinedResponse = await client.execute(CommandTypes.GetCombinedCodeFix, combinedArgs);
|
|
21521
|
-
if (combinedResponse.type !== 'response' || !combinedResponse.body) {
|
|
21522
|
-
return edits;
|
|
21523
|
-
}
|
|
21524
|
-
edits.push(...combinedResponse.body.changes.map(change => toTextDocumentEdit(change, client)));
|
|
21525
|
-
return edits;
|
|
21526
|
-
}
|
|
21527
|
-
}
|
|
21528
|
-
return edits;
|
|
21529
|
-
}
|
|
21530
|
-
|
|
21531
|
-
class SourceAction {}
|
|
21532
|
-
|
|
21533
|
-
class SourceFixAll extends SourceAction {
|
|
21534
|
-
constructor() {
|
|
21535
|
-
super(...arguments);
|
|
21536
|
-
this.title = 'Fix all';
|
|
21537
|
-
}
|
|
21538
|
-
async build(client, file, diagnostics) {
|
|
21539
|
-
const edits = [];
|
|
21540
|
-
edits.push(...await buildIndividualFixes([ {
|
|
21541
|
-
codes: incorrectlyImplementsInterface,
|
|
21542
|
-
fixName: classIncorrectlyImplementsInterface
|
|
21543
|
-
}, {
|
|
21544
|
-
codes: asyncOnlyAllowedInAsyncFunctions,
|
|
21545
|
-
fixName: awaitInSyncFunction
|
|
21546
|
-
} ], client, file, diagnostics));
|
|
21547
|
-
edits.push(...await buildCombinedFix([ {
|
|
21548
|
-
codes: unreachableCode$1,
|
|
21549
|
-
fixName: unreachableCode
|
|
21550
|
-
} ], client, file, diagnostics));
|
|
21551
|
-
if (!edits.length) {
|
|
21552
|
-
return null;
|
|
21553
|
-
}
|
|
21554
|
-
return mainExports$2.CodeAction.create(this.title, {
|
|
21555
|
-
documentChanges: edits
|
|
21556
|
-
}, SourceFixAll.kind.value);
|
|
21557
|
-
}
|
|
21558
|
-
}
|
|
21559
|
-
|
|
21560
|
-
SourceFixAll.kind = CodeActionKind.SourceFixAllTs;
|
|
21561
|
-
|
|
21562
|
-
class SourceRemoveUnused extends SourceAction {
|
|
21563
|
-
constructor() {
|
|
21564
|
-
super(...arguments);
|
|
21565
|
-
this.title = 'Remove all unused code';
|
|
21566
|
-
}
|
|
21567
|
-
async build(client, file, diagnostics) {
|
|
21568
|
-
const edits = await buildCombinedFix([ {
|
|
21569
|
-
codes: variableDeclaredButNeverUsed,
|
|
21570
|
-
fixName: unusedIdentifier
|
|
21571
|
-
} ], client, file, diagnostics);
|
|
21572
|
-
if (!edits.length) {
|
|
21573
|
-
return null;
|
|
21574
|
-
}
|
|
21575
|
-
return mainExports$2.CodeAction.create(this.title, {
|
|
21576
|
-
documentChanges: edits
|
|
21577
|
-
}, SourceRemoveUnused.kind.value);
|
|
21578
|
-
}
|
|
21579
|
-
}
|
|
21580
|
-
|
|
21581
|
-
SourceRemoveUnused.kind = CodeActionKind.SourceRemoveUnusedTs;
|
|
21582
|
-
|
|
21583
|
-
class SourceAddMissingImports extends SourceAction {
|
|
21584
|
-
constructor() {
|
|
21585
|
-
super(...arguments);
|
|
21586
|
-
this.title = 'Add all missing imports';
|
|
21587
|
-
}
|
|
21588
|
-
async build(client, file, diagnostics) {
|
|
21589
|
-
const edits = await buildCombinedFix([ {
|
|
21590
|
-
codes: cannotFindName,
|
|
21591
|
-
fixName: fixImport
|
|
21592
|
-
} ], client, file, diagnostics);
|
|
21593
|
-
if (!edits.length) {
|
|
21594
|
-
return null;
|
|
21595
|
-
}
|
|
21596
|
-
return mainExports$2.CodeAction.create(this.title, {
|
|
21597
|
-
documentChanges: edits
|
|
21598
|
-
}, SourceAddMissingImports.kind.value);
|
|
21599
|
-
}
|
|
21600
|
-
}
|
|
21601
|
-
|
|
21602
|
-
SourceAddMissingImports.kind = CodeActionKind.SourceAddMissingImportsTs;
|
|
21603
|
-
|
|
21604
|
-
class TypeScriptAutoFixProvider {
|
|
21605
|
-
static get kinds() {
|
|
21606
|
-
return TypeScriptAutoFixProvider.kindProviders.map(provider => provider.kind);
|
|
21607
|
-
}
|
|
21608
|
-
constructor(client) {
|
|
21609
|
-
this.client = client;
|
|
21610
|
-
}
|
|
21611
|
-
async provideCodeActions(kinds, file, diagnostics) {
|
|
21612
|
-
const results = [];
|
|
21613
|
-
for (const provider of TypeScriptAutoFixProvider.kindProviders) {
|
|
21614
|
-
if (kinds.some(kind => kind.contains(provider.kind))) {
|
|
21615
|
-
results.push((new provider).build(this.client, file, diagnostics));
|
|
21616
|
-
}
|
|
21617
|
-
}
|
|
21618
|
-
return (await Promise.all(results)).flatMap(result => result || []);
|
|
21619
|
-
}
|
|
21620
|
-
}
|
|
21621
|
-
|
|
21622
|
-
TypeScriptAutoFixProvider.kindProviders = [ SourceFixAll, SourceRemoveUnused, SourceAddMissingImports ];
|
|
21623
|
-
|
|
21624
21596
|
function escapeRegExp(text) {
|
|
21625
21597
|
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
|
|
21626
21598
|
}
|
|
@@ -22006,8 +21978,8 @@ function requirePosix() {
|
|
|
22006
21978
|
value: true
|
|
22007
21979
|
});
|
|
22008
21980
|
posix.sync = posix.isexe = void 0;
|
|
22009
|
-
const fs_1 = require$$0$
|
|
22010
|
-
const promises_1 = require$$1$
|
|
21981
|
+
const fs_1 = require$$0$2;
|
|
21982
|
+
const promises_1 = require$$1$1;
|
|
22011
21983
|
const isexe = async (path, options = {}) => {
|
|
22012
21984
|
const {ignoreErrors: ignoreErrors = false} = options;
|
|
22013
21985
|
try {
|
|
@@ -22062,8 +22034,8 @@ function requireWin32() {
|
|
|
22062
22034
|
value: true
|
|
22063
22035
|
});
|
|
22064
22036
|
win32.sync = win32.isexe = void 0;
|
|
22065
|
-
const fs_1 = require$$0$
|
|
22066
|
-
const promises_1 = require$$1$
|
|
22037
|
+
const fs_1 = require$$0$2;
|
|
22038
|
+
const promises_1 = require$$1$1;
|
|
22067
22039
|
const isexe = async (path, options = {}) => {
|
|
22068
22040
|
const {ignoreErrors: ignoreErrors = false} = options;
|
|
22069
22041
|
try {
|
|
@@ -22183,7 +22155,7 @@ function requireLib() {
|
|
|
22183
22155
|
if (hasRequiredLib) return lib;
|
|
22184
22156
|
hasRequiredLib = 1;
|
|
22185
22157
|
const {isexe: isexe, sync: isexeSync} = requireCjs();
|
|
22186
|
-
const {join: join, delimiter: delimiter, sep: sep, posix: posix} = require$$1
|
|
22158
|
+
const {join: join, delimiter: delimiter, sep: sep, posix: posix} = require$$1;
|
|
22187
22159
|
const isWindows = process.platform === 'win32';
|
|
22188
22160
|
const rSlash = new RegExp(`[${posix.sep}${sep === posix.sep ? '' : sep}]`.replace(/(\\)/g, '\\$1'));
|
|
22189
22161
|
const rRel = new RegExp(`^\\.${rSlash.source}`);
|
|
@@ -22465,20 +22437,742 @@ class TypeScriptVersionProvider {
|
|
|
22465
22437
|
}
|
|
22466
22438
|
}
|
|
22467
22439
|
|
|
22468
|
-
class
|
|
22469
|
-
constructor(
|
|
22470
|
-
this.
|
|
22471
|
-
|
|
22472
|
-
|
|
22473
|
-
this.
|
|
22474
|
-
|
|
22440
|
+
class CommandManager {
|
|
22441
|
+
constructor() {
|
|
22442
|
+
this.commands = new Map;
|
|
22443
|
+
}
|
|
22444
|
+
dispose() {
|
|
22445
|
+
this.commands.clear();
|
|
22446
|
+
}
|
|
22447
|
+
register(command) {
|
|
22448
|
+
const entry = this.commands.get(command.id);
|
|
22449
|
+
if (!entry) {
|
|
22450
|
+
this.commands.set(command.id, command);
|
|
22451
|
+
}
|
|
22452
|
+
}
|
|
22453
|
+
async handle(commandId, ...args) {
|
|
22454
|
+
const entry = this.commands.get(commandId);
|
|
22455
|
+
if (entry) {
|
|
22456
|
+
await entry.execute(...args);
|
|
22457
|
+
return true;
|
|
22458
|
+
}
|
|
22459
|
+
return false;
|
|
22460
|
+
}
|
|
22461
|
+
}
|
|
22462
|
+
|
|
22463
|
+
const variableDeclaredButNeverUsed = new Set([ 6196, 6133 ]);
|
|
22464
|
+
|
|
22465
|
+
const unreachableCode$1 = new Set([ 7027 ]);
|
|
22466
|
+
|
|
22467
|
+
const incorrectlyImplementsInterface = new Set([ 2420 ]);
|
|
22468
|
+
|
|
22469
|
+
const cannotFindName = new Set([ 2552, 2304 ]);
|
|
22470
|
+
|
|
22471
|
+
const asyncOnlyAllowedInAsyncFunctions = new Set([ 1308 ]);
|
|
22472
|
+
|
|
22473
|
+
const addMissingAwait = 'addMissingAwait';
|
|
22474
|
+
|
|
22475
|
+
const addMissingNewOperator = 'addMissingNewOperator';
|
|
22476
|
+
|
|
22477
|
+
const addMissingOverride = 'fixOverrideModifier';
|
|
22478
|
+
|
|
22479
|
+
const annotateWithTypeFromJSDoc = 'annotateWithTypeFromJSDoc';
|
|
22480
|
+
|
|
22481
|
+
const awaitInSyncFunction = 'fixAwaitInSyncFunction';
|
|
22482
|
+
|
|
22483
|
+
const classDoesntImplementInheritedAbstractMember = 'fixClassDoesntImplementInheritedAbstractMember';
|
|
22484
|
+
|
|
22485
|
+
const classIncorrectlyImplementsInterface = 'fixClassIncorrectlyImplementsInterface';
|
|
22486
|
+
|
|
22487
|
+
const constructorForDerivedNeedSuperCall = 'constructorForDerivedNeedSuperCall';
|
|
22488
|
+
|
|
22489
|
+
const extendsInterfaceBecomesImplements = 'extendsInterfaceBecomesImplements';
|
|
22490
|
+
|
|
22491
|
+
const fixImport = 'import';
|
|
22492
|
+
|
|
22493
|
+
const forgottenThisPropertyAccess = 'forgottenThisPropertyAccess';
|
|
22494
|
+
|
|
22495
|
+
const removeUnnecessaryAwait = 'removeUnnecessaryAwait';
|
|
22496
|
+
|
|
22497
|
+
const spelling = 'spelling';
|
|
22498
|
+
|
|
22499
|
+
const unreachableCode = 'fixUnreachableCode';
|
|
22500
|
+
|
|
22501
|
+
const unusedIdentifier = 'unusedIdentifier';
|
|
22502
|
+
|
|
22503
|
+
class TsCodeAction {
|
|
22504
|
+
constructor(title, kind) {
|
|
22505
|
+
this.title = title;
|
|
22506
|
+
this.kind = kind;
|
|
22507
|
+
}
|
|
22508
|
+
toLspCodeAction() {
|
|
22509
|
+
const codeAction = mainExports$2.CodeAction.create(this.title, this.kind);
|
|
22510
|
+
if (this.command !== undefined) {
|
|
22511
|
+
codeAction.command = this.command;
|
|
22512
|
+
}
|
|
22513
|
+
if (this.diagnostics !== undefined) {
|
|
22514
|
+
codeAction.diagnostics = this.diagnostics;
|
|
22515
|
+
}
|
|
22516
|
+
if (this.disabled !== undefined) {
|
|
22517
|
+
codeAction.disabled = this.disabled;
|
|
22518
|
+
}
|
|
22519
|
+
if (this.edit !== undefined) {
|
|
22520
|
+
codeAction.edit = this.edit;
|
|
22521
|
+
}
|
|
22522
|
+
if (this.isPreferred !== undefined) {
|
|
22523
|
+
codeAction.isPreferred = this.isPreferred;
|
|
22524
|
+
}
|
|
22525
|
+
return codeAction;
|
|
22526
|
+
}
|
|
22527
|
+
}
|
|
22528
|
+
|
|
22529
|
+
async function buildIndividualFixes(fixes, client, file, diagnostics, token) {
|
|
22530
|
+
const documentChanges = [];
|
|
22531
|
+
for (const diagnostic of diagnostics) {
|
|
22532
|
+
for (const {codes: codes, fixName: fixName} of fixes) {
|
|
22533
|
+
if (token.isCancellationRequested) {
|
|
22534
|
+
return;
|
|
22535
|
+
}
|
|
22536
|
+
if (!codes.has(diagnostic.code)) {
|
|
22537
|
+
continue;
|
|
22538
|
+
}
|
|
22539
|
+
const args = {
|
|
22540
|
+
...Range.toFileRangeRequestArgs(file, diagnostic.range),
|
|
22541
|
+
errorCodes: [ +diagnostic.code ]
|
|
22542
|
+
};
|
|
22543
|
+
const response = await client.execute(CommandTypes.GetCodeFixes, args, token);
|
|
22544
|
+
if (response.type !== 'response') {
|
|
22545
|
+
continue;
|
|
22546
|
+
}
|
|
22547
|
+
const fix = response.body?.find(fix => fix.fixName === fixName);
|
|
22548
|
+
if (fix) {
|
|
22549
|
+
documentChanges.push(...fix.changes.map(change => toTextDocumentEdit(change, client)));
|
|
22550
|
+
break;
|
|
22551
|
+
}
|
|
22552
|
+
}
|
|
22553
|
+
}
|
|
22554
|
+
return {
|
|
22555
|
+
documentChanges: documentChanges
|
|
22556
|
+
};
|
|
22557
|
+
}
|
|
22558
|
+
|
|
22559
|
+
async function buildCombinedFix(fixes, client, file, diagnostics, token) {
|
|
22560
|
+
for (const diagnostic of diagnostics) {
|
|
22561
|
+
for (const {codes: codes, fixName: fixName} of fixes) {
|
|
22562
|
+
if (token.isCancellationRequested) {
|
|
22563
|
+
return;
|
|
22564
|
+
}
|
|
22565
|
+
if (!codes.has(diagnostic.code)) {
|
|
22566
|
+
continue;
|
|
22567
|
+
}
|
|
22568
|
+
const args = {
|
|
22569
|
+
...Range.toFileRangeRequestArgs(file, diagnostic.range),
|
|
22570
|
+
errorCodes: [ +diagnostic.code ]
|
|
22571
|
+
};
|
|
22572
|
+
const response = await client.execute(CommandTypes.GetCodeFixes, args, token);
|
|
22573
|
+
if (response.type !== 'response' || !response.body?.length) {
|
|
22574
|
+
continue;
|
|
22575
|
+
}
|
|
22576
|
+
const fix = response.body?.find(fix => fix.fixName === fixName);
|
|
22577
|
+
if (!fix) {
|
|
22578
|
+
continue;
|
|
22579
|
+
}
|
|
22580
|
+
if (!fix.fixId) {
|
|
22581
|
+
return {
|
|
22582
|
+
documentChanges: fix.changes.map(change => toTextDocumentEdit(change, client))
|
|
22583
|
+
};
|
|
22584
|
+
}
|
|
22585
|
+
const combinedArgs = {
|
|
22586
|
+
scope: {
|
|
22587
|
+
type: 'file',
|
|
22588
|
+
args: {
|
|
22589
|
+
file: file
|
|
22590
|
+
}
|
|
22591
|
+
},
|
|
22592
|
+
fixId: fix.fixId
|
|
22593
|
+
};
|
|
22594
|
+
const combinedResponse = await client.execute(CommandTypes.GetCombinedCodeFix, combinedArgs, token);
|
|
22595
|
+
if (combinedResponse.type !== 'response' || !combinedResponse.body) {
|
|
22596
|
+
return;
|
|
22597
|
+
}
|
|
22598
|
+
return {
|
|
22599
|
+
documentChanges: combinedResponse.body.changes.map(change => toTextDocumentEdit(change, client))
|
|
22600
|
+
};
|
|
22601
|
+
}
|
|
22602
|
+
}
|
|
22603
|
+
}
|
|
22604
|
+
|
|
22605
|
+
class SourceAction extends TsCodeAction {}
|
|
22606
|
+
|
|
22607
|
+
class SourceFixAll extends SourceAction {
|
|
22608
|
+
constructor() {
|
|
22609
|
+
super('Fix all fixable JS/TS issues', SourceFixAll.kind.value);
|
|
22610
|
+
}
|
|
22611
|
+
async build(client, file, diagnostics, token) {
|
|
22612
|
+
this.edit = await buildIndividualFixes([ {
|
|
22613
|
+
codes: incorrectlyImplementsInterface,
|
|
22614
|
+
fixName: classIncorrectlyImplementsInterface
|
|
22615
|
+
}, {
|
|
22616
|
+
codes: asyncOnlyAllowedInAsyncFunctions,
|
|
22617
|
+
fixName: awaitInSyncFunction
|
|
22618
|
+
} ], client, file, diagnostics, token);
|
|
22619
|
+
const edits = await buildCombinedFix([ {
|
|
22620
|
+
codes: unreachableCode$1,
|
|
22621
|
+
fixName: unreachableCode
|
|
22622
|
+
} ], client, file, diagnostics, token);
|
|
22623
|
+
if (edits?.documentChanges) {
|
|
22624
|
+
this.edit?.documentChanges?.push(...edits.documentChanges);
|
|
22625
|
+
}
|
|
22626
|
+
}
|
|
22627
|
+
}
|
|
22628
|
+
|
|
22629
|
+
SourceFixAll.kind = CodeActionKind.SourceFixAllTs;
|
|
22630
|
+
|
|
22631
|
+
class SourceRemoveUnused extends SourceAction {
|
|
22632
|
+
constructor() {
|
|
22633
|
+
super('Remove all unused code', SourceRemoveUnused.kind.value);
|
|
22634
|
+
}
|
|
22635
|
+
async build(client, file, diagnostics, token) {
|
|
22636
|
+
this.edit = await buildCombinedFix([ {
|
|
22637
|
+
codes: variableDeclaredButNeverUsed,
|
|
22638
|
+
fixName: unusedIdentifier
|
|
22639
|
+
} ], client, file, diagnostics, token);
|
|
22640
|
+
}
|
|
22641
|
+
}
|
|
22642
|
+
|
|
22643
|
+
SourceRemoveUnused.kind = CodeActionKind.SourceRemoveUnusedTs;
|
|
22644
|
+
|
|
22645
|
+
class SourceAddMissingImports extends SourceAction {
|
|
22646
|
+
constructor() {
|
|
22647
|
+
super('Add all missing imports', SourceAddMissingImports.kind.value);
|
|
22648
|
+
}
|
|
22649
|
+
async build(client, file, diagnostics, token) {
|
|
22650
|
+
this.edit = await buildCombinedFix([ {
|
|
22651
|
+
codes: cannotFindName,
|
|
22652
|
+
fixName: fixImport
|
|
22653
|
+
} ], client, file, diagnostics, token);
|
|
22654
|
+
}
|
|
22655
|
+
}
|
|
22656
|
+
|
|
22657
|
+
SourceAddMissingImports.kind = CodeActionKind.SourceAddMissingImportsTs;
|
|
22658
|
+
|
|
22659
|
+
class TypeScriptAutoFixProvider {
|
|
22660
|
+
constructor(client, fileConfigurationManager, diagnosticsManager) {
|
|
22661
|
+
this.client = client;
|
|
22662
|
+
this.fileConfigurationManager = fileConfigurationManager;
|
|
22663
|
+
this.diagnosticsManager = diagnosticsManager;
|
|
22664
|
+
}
|
|
22665
|
+
getMetadata() {
|
|
22666
|
+
return {
|
|
22667
|
+
providedCodeActionKinds: TypeScriptAutoFixProvider.kindProviders.map(x => x.kind.value)
|
|
22668
|
+
};
|
|
22669
|
+
}
|
|
22670
|
+
async provideCodeActions(document, _range, context, token) {
|
|
22671
|
+
if (!context.only?.length) {
|
|
22672
|
+
return undefined;
|
|
22673
|
+
}
|
|
22674
|
+
const sourceKinds = context.only.map(kind => new CodeActionKind(kind)).filter(codeActionKind => CodeActionKind.Source.intersects(codeActionKind));
|
|
22675
|
+
if (!sourceKinds.length) {
|
|
22676
|
+
return undefined;
|
|
22677
|
+
}
|
|
22678
|
+
if (this.client.hasPendingDiagnostics(document.uri)) {
|
|
22679
|
+
return undefined;
|
|
22680
|
+
}
|
|
22681
|
+
const actions = this.getFixAllActions(sourceKinds);
|
|
22682
|
+
const diagnostics = this.diagnosticsManager.getDiagnosticsForFile(document.filepath);
|
|
22683
|
+
if (!diagnostics.length) {
|
|
22684
|
+
return actions;
|
|
22685
|
+
}
|
|
22686
|
+
await this.fileConfigurationManager.ensureConfigurationForDocument(document, token);
|
|
22687
|
+
if (token.isCancellationRequested) {
|
|
22688
|
+
return undefined;
|
|
22689
|
+
}
|
|
22690
|
+
await Promise.all(actions.map(action => action.build(this.client, document.filepath, diagnostics, token)));
|
|
22691
|
+
return actions;
|
|
22692
|
+
}
|
|
22693
|
+
isCodeActionResolvable(_codeAction) {
|
|
22694
|
+
return false;
|
|
22695
|
+
}
|
|
22696
|
+
getFixAllActions(kinds) {
|
|
22697
|
+
return TypeScriptAutoFixProvider.kindProviders.filter(provider => kinds.some(only => only.intersects(provider.kind))).map(provider => new provider);
|
|
22698
|
+
}
|
|
22699
|
+
}
|
|
22700
|
+
|
|
22701
|
+
TypeScriptAutoFixProvider.kindProviders = [ SourceFixAll, SourceRemoveUnused, SourceAddMissingImports ];
|
|
22702
|
+
|
|
22703
|
+
class Lazy {
|
|
22704
|
+
constructor(executor) {
|
|
22705
|
+
this.executor = executor;
|
|
22706
|
+
this._didRun = false;
|
|
22707
|
+
}
|
|
22708
|
+
get hasValue() {
|
|
22709
|
+
return this._didRun;
|
|
22710
|
+
}
|
|
22711
|
+
get value() {
|
|
22712
|
+
if (!this._didRun) {
|
|
22713
|
+
try {
|
|
22714
|
+
this._value = this.executor();
|
|
22715
|
+
} catch (err) {
|
|
22716
|
+
this._error = err;
|
|
22717
|
+
} finally {
|
|
22718
|
+
this._didRun = true;
|
|
22719
|
+
}
|
|
22720
|
+
}
|
|
22721
|
+
if (this._error) {
|
|
22722
|
+
throw this._error;
|
|
22723
|
+
}
|
|
22724
|
+
return this._value;
|
|
22725
|
+
}
|
|
22726
|
+
get rawValue() {
|
|
22727
|
+
return this._value;
|
|
22728
|
+
}
|
|
22729
|
+
}
|
|
22730
|
+
|
|
22731
|
+
function getEditForCodeAction(client, action) {
|
|
22732
|
+
return action.changes?.length ? {
|
|
22733
|
+
documentChanges: action.changes.map(change => toTextDocumentEdit(change, client))
|
|
22734
|
+
} : undefined;
|
|
22735
|
+
}
|
|
22736
|
+
|
|
22737
|
+
async function applyCodeActionCommands(client, commands, token) {
|
|
22738
|
+
if (commands?.length) {
|
|
22739
|
+
for (const command of commands) {
|
|
22740
|
+
await client.execute(CommandTypes.ApplyCodeActionCommand, {
|
|
22741
|
+
command: command
|
|
22742
|
+
}, token);
|
|
22743
|
+
}
|
|
22744
|
+
}
|
|
22745
|
+
return true;
|
|
22746
|
+
}
|
|
22747
|
+
|
|
22748
|
+
class ApplyCodeActionCommand {
|
|
22749
|
+
constructor(client) {
|
|
22750
|
+
this.client = client;
|
|
22751
|
+
this.id = ApplyCodeActionCommand.ID;
|
|
22752
|
+
}
|
|
22753
|
+
async execute({action: action}) {
|
|
22754
|
+
const codeActionResult = await applyCodeActionCommands(this.client, action.commands);
|
|
22755
|
+
return codeActionResult;
|
|
22756
|
+
}
|
|
22757
|
+
}
|
|
22758
|
+
|
|
22759
|
+
ApplyCodeActionCommand.ID = '_typescript.applyCodeActionCommand';
|
|
22760
|
+
|
|
22761
|
+
class ApplyFixAllCodeAction {
|
|
22762
|
+
constructor(client, tsCodeActionProvider) {
|
|
22763
|
+
this.client = client;
|
|
22764
|
+
this.tsCodeActionProvider = tsCodeActionProvider;
|
|
22765
|
+
this.id = ApplyFixAllCodeAction.ID;
|
|
22766
|
+
}
|
|
22767
|
+
async execute(args) {
|
|
22768
|
+
const tsAction = this.tsCodeActionProvider.getQuickFixAllTsCodeActionByFixName(args.tsActionId);
|
|
22769
|
+
if (tsAction instanceof TsQuickFixAllCodeAction && tsAction.combinedResponse) {
|
|
22770
|
+
await applyCodeActionCommands(this.client, tsAction.combinedResponse.body.commands);
|
|
22771
|
+
}
|
|
22772
|
+
}
|
|
22773
|
+
}
|
|
22774
|
+
|
|
22775
|
+
ApplyFixAllCodeAction.ID = '_typescript.applyFixAllCodeAction';
|
|
22776
|
+
|
|
22777
|
+
class DiagnosticsSet {
|
|
22778
|
+
static from(diagnostics) {
|
|
22779
|
+
const values = new Map;
|
|
22780
|
+
for (const diagnostic of diagnostics) {
|
|
22781
|
+
values.set(DiagnosticsSet.key(diagnostic), diagnostic);
|
|
22782
|
+
}
|
|
22783
|
+
return new DiagnosticsSet(values);
|
|
22784
|
+
}
|
|
22785
|
+
static key(diagnostic) {
|
|
22786
|
+
const {start: start, end: end} = diagnostic.range;
|
|
22787
|
+
return `${diagnostic.code}-${start.line},${start.character}-${end.line},${end.character}`;
|
|
22788
|
+
}
|
|
22789
|
+
constructor(_values) {
|
|
22790
|
+
this._values = _values;
|
|
22791
|
+
}
|
|
22792
|
+
get values() {
|
|
22793
|
+
return this._values.values();
|
|
22794
|
+
}
|
|
22795
|
+
get size() {
|
|
22796
|
+
return this._values.size;
|
|
22797
|
+
}
|
|
22798
|
+
}
|
|
22799
|
+
|
|
22800
|
+
class TsQuickFixCodeAction extends TsCodeAction {
|
|
22801
|
+
constructor(tsAction, title, kind) {
|
|
22802
|
+
super(title, kind);
|
|
22803
|
+
this.tsAction = tsAction;
|
|
22804
|
+
}
|
|
22805
|
+
}
|
|
22806
|
+
|
|
22807
|
+
class TsQuickFixAllCodeAction extends TsQuickFixCodeAction {
|
|
22808
|
+
constructor(tsAction, file, title, kind) {
|
|
22809
|
+
super(tsAction, title, kind);
|
|
22810
|
+
this.file = file;
|
|
22811
|
+
}
|
|
22812
|
+
}
|
|
22813
|
+
|
|
22814
|
+
class CodeActionSet {
|
|
22815
|
+
constructor() {
|
|
22816
|
+
this._actions = new Set;
|
|
22817
|
+
this._fixAllActions = new Map;
|
|
22818
|
+
this._aiActions = new Set;
|
|
22819
|
+
}
|
|
22820
|
+
* values() {
|
|
22821
|
+
yield* this._actions;
|
|
22822
|
+
yield* this._aiActions;
|
|
22823
|
+
}
|
|
22824
|
+
addAction(action) {
|
|
22825
|
+
for (const existing of this._actions) {
|
|
22826
|
+
if (action.tsAction.fixName === existing.tsAction.fixName && equals(action.edit, existing.edit)) {
|
|
22827
|
+
this._actions.delete(existing);
|
|
22828
|
+
}
|
|
22829
|
+
}
|
|
22830
|
+
this._actions.add(action);
|
|
22831
|
+
if (action.tsAction.fixId) {
|
|
22832
|
+
const existingFixAll = this._fixAllActions.get(action.tsAction.fixId);
|
|
22833
|
+
if (existingFixAll) {
|
|
22834
|
+
this._actions.delete(existingFixAll);
|
|
22835
|
+
this._actions.add(existingFixAll);
|
|
22836
|
+
}
|
|
22837
|
+
}
|
|
22838
|
+
}
|
|
22839
|
+
addFixAllAction(fixId, action) {
|
|
22840
|
+
const existing = this._fixAllActions.get(fixId);
|
|
22841
|
+
if (existing) {
|
|
22842
|
+
this._actions.delete(existing);
|
|
22843
|
+
}
|
|
22844
|
+
this.addAction(action);
|
|
22845
|
+
this._fixAllActions.set(fixId, action);
|
|
22846
|
+
}
|
|
22847
|
+
hasFixAllAction(fixId) {
|
|
22848
|
+
return this._fixAllActions.has(fixId);
|
|
22849
|
+
}
|
|
22850
|
+
}
|
|
22851
|
+
|
|
22852
|
+
class SupportedCodeActionProvider {
|
|
22853
|
+
constructor(client) {
|
|
22854
|
+
this.client = client;
|
|
22855
|
+
this.fixableDiagnosticCodes = new Lazy(() => this.client.execute(CommandTypes.GetSupportedCodeFixes, null).then(response => response.type === 'response' ? response.body || [] : []).then(codes => new Set(codes)));
|
|
22856
|
+
}
|
|
22857
|
+
async getFixableDiagnosticsForContext(diagnostics) {
|
|
22858
|
+
const fixableCodes = await this.fixableDiagnosticCodes.value;
|
|
22859
|
+
return DiagnosticsSet.from(diagnostics.filter(diagnostic => typeof diagnostic.code !== 'undefined' && fixableCodes.has(diagnostic.code + '')));
|
|
22860
|
+
}
|
|
22861
|
+
}
|
|
22862
|
+
|
|
22863
|
+
class TypeScriptQuickFixProvider {
|
|
22864
|
+
constructor(client, fileConfigurationManager, commandManager, diagnosticsManager, features) {
|
|
22865
|
+
this.client = client;
|
|
22866
|
+
this.fileConfigurationManager = fileConfigurationManager;
|
|
22867
|
+
this.diagnosticsManager = diagnosticsManager;
|
|
22868
|
+
this.features = features;
|
|
22869
|
+
this._quickFixAllTsCodeActionMap = new Map;
|
|
22870
|
+
commandManager.register(new ApplyCodeActionCommand(client));
|
|
22871
|
+
commandManager.register(new ApplyFixAllCodeAction(client, this));
|
|
22872
|
+
this.supportedCodeActionProvider = new SupportedCodeActionProvider(client);
|
|
22873
|
+
}
|
|
22874
|
+
getMetadata() {
|
|
22875
|
+
return {
|
|
22876
|
+
providedCodeActionKinds: [ CodeActionKind.QuickFix.value ]
|
|
22877
|
+
};
|
|
22878
|
+
}
|
|
22879
|
+
async provideCodeActions(document, range, context, token) {
|
|
22880
|
+
this._quickFixAllTsCodeActionMap.clear();
|
|
22881
|
+
let diagnostics = context.diagnostics;
|
|
22882
|
+
if (this.client.hasPendingDiagnostics(document.uri)) {
|
|
22883
|
+
await new Promise(resolve => {
|
|
22884
|
+
setTimeout(resolve, 500);
|
|
22885
|
+
});
|
|
22886
|
+
if (token.isCancellationRequested) {
|
|
22887
|
+
return;
|
|
22888
|
+
}
|
|
22889
|
+
const allDiagnostics = [];
|
|
22890
|
+
for (const diagnostic of this.diagnosticsManager.getDiagnosticsForFile(document.filepath)) {
|
|
22891
|
+
if (Range.intersection(range, diagnostic.range)) {
|
|
22892
|
+
const newLen = allDiagnostics.push(diagnostic);
|
|
22893
|
+
if (newLen > TypeScriptQuickFixProvider._maxCodeActionsPerFile) {
|
|
22894
|
+
break;
|
|
22895
|
+
}
|
|
22896
|
+
}
|
|
22897
|
+
}
|
|
22898
|
+
diagnostics = allDiagnostics;
|
|
22899
|
+
}
|
|
22900
|
+
const fixableDiagnostics = await this.supportedCodeActionProvider.getFixableDiagnosticsForContext(diagnostics);
|
|
22901
|
+
if (!fixableDiagnostics.size || token.isCancellationRequested) {
|
|
22902
|
+
return;
|
|
22903
|
+
}
|
|
22904
|
+
await this.fileConfigurationManager.ensureConfigurationForDocument(document, token);
|
|
22905
|
+
if (token.isCancellationRequested) {
|
|
22906
|
+
return;
|
|
22907
|
+
}
|
|
22908
|
+
const results = new CodeActionSet;
|
|
22909
|
+
for (const diagnostic of fixableDiagnostics.values) {
|
|
22910
|
+
await this.getFixesForDiagnostic(document, diagnostic, results, token);
|
|
22911
|
+
if (token.isCancellationRequested) {
|
|
22912
|
+
return;
|
|
22913
|
+
}
|
|
22914
|
+
}
|
|
22915
|
+
const allActions = Array.from(results.values());
|
|
22916
|
+
for (const action of allActions) {
|
|
22917
|
+
action.isPreferred = isPreferredFix(action, allActions);
|
|
22918
|
+
}
|
|
22919
|
+
return allActions;
|
|
22920
|
+
}
|
|
22921
|
+
isCodeActionResolvable(codeAction) {
|
|
22922
|
+
return codeAction instanceof TsQuickFixAllCodeAction;
|
|
22923
|
+
}
|
|
22924
|
+
async resolveCodeAction(codeAction, token) {
|
|
22925
|
+
if (!this.isCodeActionResolvable(codeAction) || !codeAction.tsAction.fixId) {
|
|
22926
|
+
return codeAction;
|
|
22927
|
+
}
|
|
22928
|
+
const arg = {
|
|
22929
|
+
scope: {
|
|
22930
|
+
type: 'file',
|
|
22931
|
+
args: {
|
|
22932
|
+
file: codeAction.file
|
|
22933
|
+
}
|
|
22934
|
+
},
|
|
22935
|
+
fixId: codeAction.tsAction.fixId
|
|
22936
|
+
};
|
|
22937
|
+
const response = await this.client.execute(CommandTypes.GetCombinedCodeFix, arg, token);
|
|
22938
|
+
if (response.type === 'response') {
|
|
22939
|
+
codeAction.combinedResponse = response;
|
|
22940
|
+
codeAction.edit = {
|
|
22941
|
+
documentChanges: response.body.changes.map(change => toTextDocumentEdit(change, this.client))
|
|
22942
|
+
};
|
|
22943
|
+
}
|
|
22944
|
+
return codeAction;
|
|
22945
|
+
}
|
|
22946
|
+
getQuickFixAllTsCodeActionByFixName(fixName) {
|
|
22947
|
+
return this._quickFixAllTsCodeActionMap.get(fixName);
|
|
22948
|
+
}
|
|
22949
|
+
async getFixesForDiagnostic(document, diagnostic, results, token) {
|
|
22950
|
+
const args = {
|
|
22951
|
+
...Range.toFileRangeRequestArgs(document.filepath, diagnostic.range),
|
|
22952
|
+
errorCodes: [ +diagnostic.code ]
|
|
22953
|
+
};
|
|
22954
|
+
const response = await this.client.execute(CommandTypes.GetCodeFixes, args, token);
|
|
22955
|
+
if (response.type !== 'response' || !response.body) {
|
|
22956
|
+
return results;
|
|
22957
|
+
}
|
|
22958
|
+
for (const tsCodeFix of response.body) {
|
|
22959
|
+
for (const action of this.getFixesForTsCodeAction(document, diagnostic, tsCodeFix)) {
|
|
22960
|
+
results.addAction(action);
|
|
22961
|
+
}
|
|
22962
|
+
if (this.features.codeActionResolveSupport) {
|
|
22963
|
+
this.addFixAllForTsCodeAction(results, document.uri, document.filepath, diagnostic, tsCodeFix);
|
|
22964
|
+
}
|
|
22965
|
+
}
|
|
22966
|
+
return results;
|
|
22967
|
+
}
|
|
22968
|
+
getFixesForTsCodeAction(document, diagnostic, action) {
|
|
22969
|
+
const actions = [];
|
|
22970
|
+
const codeAction = new TsQuickFixCodeAction(action, action.description, mainExports$2.CodeActionKind.QuickFix);
|
|
22971
|
+
codeAction.edit = getEditForCodeAction(this.client, action);
|
|
22972
|
+
codeAction.diagnostics = [ diagnostic ];
|
|
22973
|
+
codeAction.command = {
|
|
22974
|
+
command: ApplyCodeActionCommand.ID,
|
|
22975
|
+
arguments: [ {
|
|
22976
|
+
action: action,
|
|
22977
|
+
diagnostic: diagnostic,
|
|
22978
|
+
documentUri: document.uri.toString()
|
|
22979
|
+
} ],
|
|
22980
|
+
title: ''
|
|
22981
|
+
};
|
|
22982
|
+
actions.push(codeAction);
|
|
22983
|
+
return actions;
|
|
22984
|
+
}
|
|
22985
|
+
addFixAllForTsCodeAction(results, _resource, file, diagnostic, tsAction) {
|
|
22986
|
+
if (!tsAction.fixId || results.hasFixAllAction(tsAction.fixId)) {
|
|
22987
|
+
return results;
|
|
22988
|
+
}
|
|
22989
|
+
if (!this.diagnosticsManager.getDiagnosticsForFile(file).some(x => {
|
|
22990
|
+
if (x === diagnostic) {
|
|
22991
|
+
return false;
|
|
22992
|
+
}
|
|
22993
|
+
return x.code === diagnostic.code || fixAllErrorCodes.has(x.code) && fixAllErrorCodes.get(x.code) === fixAllErrorCodes.get(diagnostic.code);
|
|
22994
|
+
})) {
|
|
22995
|
+
return results;
|
|
22996
|
+
}
|
|
22997
|
+
const action = new TsQuickFixAllCodeAction(tsAction, file, tsAction.fixAllDescription || `${tsAction.description} (Fix all in file)`, mainExports$2.CodeActionKind.QuickFix);
|
|
22998
|
+
action.diagnostics = [ diagnostic ];
|
|
22999
|
+
action.command = {
|
|
23000
|
+
command: ApplyFixAllCodeAction.ID,
|
|
23001
|
+
arguments: [ {
|
|
23002
|
+
tsActionId: tsAction.fixName
|
|
23003
|
+
} ],
|
|
23004
|
+
title: ''
|
|
23005
|
+
};
|
|
23006
|
+
this._quickFixAllTsCodeActionMap.set(tsAction.fixName, action);
|
|
23007
|
+
results.addFixAllAction(tsAction.fixId, action);
|
|
23008
|
+
return results;
|
|
23009
|
+
}
|
|
23010
|
+
}
|
|
23011
|
+
|
|
23012
|
+
TypeScriptQuickFixProvider._maxCodeActionsPerFile = 1e3;
|
|
23013
|
+
|
|
23014
|
+
const fixAllErrorCodes = new Map([ [ 2339, 2339 ], [ 2345, 2339 ] ]);
|
|
23015
|
+
|
|
23016
|
+
const preferredFixes = new Map([ [ annotateWithTypeFromJSDoc, {
|
|
23017
|
+
priority: 2
|
|
23018
|
+
} ], [ constructorForDerivedNeedSuperCall, {
|
|
23019
|
+
priority: 2
|
|
23020
|
+
} ], [ extendsInterfaceBecomesImplements, {
|
|
23021
|
+
priority: 2
|
|
23022
|
+
} ], [ awaitInSyncFunction, {
|
|
23023
|
+
priority: 2
|
|
23024
|
+
} ], [ removeUnnecessaryAwait, {
|
|
23025
|
+
priority: 2
|
|
23026
|
+
} ], [ classIncorrectlyImplementsInterface, {
|
|
23027
|
+
priority: 3
|
|
23028
|
+
} ], [ classDoesntImplementInheritedAbstractMember, {
|
|
23029
|
+
priority: 3
|
|
23030
|
+
} ], [ unreachableCode, {
|
|
23031
|
+
priority: 2
|
|
23032
|
+
} ], [ unusedIdentifier, {
|
|
23033
|
+
priority: 2
|
|
23034
|
+
} ], [ forgottenThisPropertyAccess, {
|
|
23035
|
+
priority: 2
|
|
23036
|
+
} ], [ spelling, {
|
|
23037
|
+
priority: 0
|
|
23038
|
+
} ], [ addMissingAwait, {
|
|
23039
|
+
priority: 2
|
|
23040
|
+
} ], [ addMissingOverride, {
|
|
23041
|
+
priority: 2
|
|
23042
|
+
} ], [ addMissingNewOperator, {
|
|
23043
|
+
priority: 2
|
|
23044
|
+
} ], [ fixImport, {
|
|
23045
|
+
priority: 1,
|
|
23046
|
+
thereCanOnlyBeOne: true
|
|
23047
|
+
} ] ]);
|
|
23048
|
+
|
|
23049
|
+
function isPreferredFix(action, allActions) {
|
|
23050
|
+
if (action instanceof TsQuickFixAllCodeAction) {
|
|
23051
|
+
return false;
|
|
23052
|
+
}
|
|
23053
|
+
const fixPriority = preferredFixes.get(action.tsAction.fixName);
|
|
23054
|
+
if (!fixPriority) {
|
|
23055
|
+
return false;
|
|
23056
|
+
}
|
|
23057
|
+
return allActions.every(otherAction => {
|
|
23058
|
+
if (otherAction === action) {
|
|
23059
|
+
return true;
|
|
23060
|
+
}
|
|
23061
|
+
if (otherAction instanceof TsQuickFixAllCodeAction) {
|
|
23062
|
+
return true;
|
|
23063
|
+
}
|
|
23064
|
+
const otherFixPriority = preferredFixes.get(otherAction.tsAction.fixName);
|
|
23065
|
+
if (!otherFixPriority || otherFixPriority.priority < fixPriority.priority) {
|
|
23066
|
+
return true;
|
|
23067
|
+
} else if (otherFixPriority.priority > fixPriority.priority) {
|
|
23068
|
+
return false;
|
|
23069
|
+
}
|
|
23070
|
+
if (fixPriority.thereCanOnlyBeOne && action.tsAction.fixName === otherAction.tsAction.fixName) {
|
|
23071
|
+
return false;
|
|
23072
|
+
}
|
|
23073
|
+
return true;
|
|
23074
|
+
});
|
|
23075
|
+
}
|
|
23076
|
+
|
|
23077
|
+
const noopDisposable = mainExports$2.Disposable.create(() => {});
|
|
23078
|
+
|
|
23079
|
+
const nulToken = {
|
|
23080
|
+
isCancellationRequested: false,
|
|
23081
|
+
onCancellationRequested: () => noopDisposable
|
|
23082
|
+
};
|
|
23083
|
+
|
|
23084
|
+
class CodeActionManager {
|
|
23085
|
+
constructor(client, fileConfigurationManager, commandManager, diagnosticsManager, features) {
|
|
23086
|
+
this.features = features;
|
|
23087
|
+
this.providerMap = new Map;
|
|
23088
|
+
this.nextProviderId = 1;
|
|
23089
|
+
this.resolveCodeActionsMap = new Map;
|
|
23090
|
+
this.nextGlobalCodeActionId = 1;
|
|
23091
|
+
this.addProvider(new TypeScriptAutoFixProvider(client, fileConfigurationManager, diagnosticsManager));
|
|
23092
|
+
this.addProvider(new TypeScriptQuickFixProvider(client, fileConfigurationManager, commandManager, diagnosticsManager, features));
|
|
23093
|
+
}
|
|
23094
|
+
get kinds() {
|
|
23095
|
+
const allKinds = [];
|
|
23096
|
+
for (const [_, provider] of this.providerMap) {
|
|
23097
|
+
allKinds.push(...provider.getMetadata().providedCodeActionKinds || []);
|
|
23098
|
+
}
|
|
23099
|
+
return allKinds;
|
|
23100
|
+
}
|
|
23101
|
+
async provideCodeActions(document, range, context, token) {
|
|
23102
|
+
this.resolveCodeActionsMap.clear();
|
|
23103
|
+
const allCodeActions = [];
|
|
23104
|
+
for (const [providerId, provider] of this.providerMap.entries()) {
|
|
23105
|
+
const codeActions = await provider.provideCodeActions(document, range, context, token || nulToken);
|
|
23106
|
+
if (!codeActions) {
|
|
23107
|
+
continue;
|
|
23108
|
+
}
|
|
23109
|
+
for (const action of codeActions) {
|
|
23110
|
+
if (mainExports$2.Command.is(action)) {
|
|
23111
|
+
allCodeActions.push(action);
|
|
23112
|
+
continue;
|
|
23113
|
+
}
|
|
23114
|
+
const lspCodeAction = action.toLspCodeAction();
|
|
23115
|
+
if (provider.isCodeActionResolvable(action)) {
|
|
23116
|
+
const globalId = this.nextGlobalCodeActionId++;
|
|
23117
|
+
this.resolveCodeActionsMap.set(globalId, action);
|
|
23118
|
+
lspCodeAction.data = {
|
|
23119
|
+
globalId: globalId,
|
|
23120
|
+
providerId: providerId
|
|
23121
|
+
};
|
|
23122
|
+
}
|
|
23123
|
+
allCodeActions.push(lspCodeAction);
|
|
23124
|
+
}
|
|
23125
|
+
}
|
|
23126
|
+
return allCodeActions;
|
|
23127
|
+
}
|
|
23128
|
+
async resolveCodeAction(codeAction, token) {
|
|
23129
|
+
if (!this.features.codeActionResolveSupport) {
|
|
23130
|
+
return codeAction;
|
|
23131
|
+
}
|
|
23132
|
+
const {globalId: globalId, providerId: providerId} = codeAction.data || {};
|
|
23133
|
+
if (globalId === undefined || providerId === undefined) {
|
|
23134
|
+
return codeAction;
|
|
23135
|
+
}
|
|
23136
|
+
const provider = this.providerMap.get(providerId);
|
|
23137
|
+
if (!provider || !provider.resolveCodeAction) {
|
|
23138
|
+
return codeAction;
|
|
23139
|
+
}
|
|
23140
|
+
const tsCodeAction = this.resolveCodeActionsMap.get(globalId);
|
|
23141
|
+
if (!tsCodeAction || !providerId) {
|
|
23142
|
+
return codeAction;
|
|
23143
|
+
}
|
|
23144
|
+
const resolvedTsCodeAction = await provider.resolveCodeAction(tsCodeAction, token || nulToken);
|
|
23145
|
+
if (!resolvedTsCodeAction) {
|
|
23146
|
+
return codeAction;
|
|
23147
|
+
}
|
|
23148
|
+
const lspCodeAction = resolvedTsCodeAction.toLspCodeAction();
|
|
23149
|
+
for (const property of this.features.codeActionResolveSupport.properties) {
|
|
23150
|
+
if (property in lspCodeAction) {
|
|
23151
|
+
codeAction[property] = lspCodeAction[property];
|
|
23152
|
+
}
|
|
23153
|
+
}
|
|
23154
|
+
return codeAction;
|
|
23155
|
+
}
|
|
23156
|
+
addProvider(provider) {
|
|
23157
|
+
this.providerMap.set(this.nextProviderId++, provider);
|
|
23158
|
+
}
|
|
23159
|
+
}
|
|
23160
|
+
|
|
23161
|
+
class LspServer {
|
|
23162
|
+
constructor(options) {
|
|
23163
|
+
this.options = options;
|
|
23164
|
+
this.initializeParams = null;
|
|
23165
|
+
this.completionDataCache = new CompletionDataCache;
|
|
23166
|
+
this.features = {};
|
|
22475
23167
|
this.cachedNavTreeResponse = new CachedResponse;
|
|
22476
23168
|
this.implementationsCodeLensProvider = null;
|
|
22477
23169
|
this.referencesCodeLensProvider = null;
|
|
22478
23170
|
this.logger = new PrefixingLogger(options.logger, '[lspserver]');
|
|
22479
23171
|
this.tsClient = new TsClient(onCaseInsensitiveFileSystem(), this.logger, options.lspClient);
|
|
22480
|
-
this.fileConfigurationManager = new FileConfigurationManager(this.tsClient, onCaseInsensitiveFileSystem());
|
|
22481
|
-
this.
|
|
23172
|
+
this.fileConfigurationManager = new FileConfigurationManager(this.tsClient, this.options.lspClient, onCaseInsensitiveFileSystem());
|
|
23173
|
+
this.commandManager = new CommandManager;
|
|
23174
|
+
this.diagnosticsManager = new DiagnosticsManager(diagnostics => this.options.lspClient.publishDiagnostics(diagnostics), this.tsClient, this.features, this.logger);
|
|
23175
|
+
this.codeActionsManager = new CodeActionManager(this.tsClient, this.fileConfigurationManager, this.commandManager, this.diagnosticsManager, this.features);
|
|
22482
23176
|
}
|
|
22483
23177
|
closeAllForTesting() {
|
|
22484
23178
|
for (const document of this.tsClient.documentsForTesting.values()) {
|
|
@@ -22490,7 +23184,7 @@ class LspServer {
|
|
|
22490
23184
|
if (!document) {
|
|
22491
23185
|
throw new Error(`Document not open: ${uri}`);
|
|
22492
23186
|
}
|
|
22493
|
-
await this.
|
|
23187
|
+
await this.diagnosticsManager.waitForDiagnosticsForTesting(document.filepath);
|
|
22494
23188
|
}
|
|
22495
23189
|
shutdown() {
|
|
22496
23190
|
this.tsClient.shutdown();
|
|
@@ -22518,6 +23212,7 @@ class LspServer {
|
|
|
22518
23212
|
const {codeAction: codeAction, completion: completion, definition: definition, publishDiagnostics: publishDiagnostics} = textDocument;
|
|
22519
23213
|
if (codeAction) {
|
|
22520
23214
|
this.features.codeActionDisabledSupport = codeAction.disabledSupport;
|
|
23215
|
+
this.features.codeActionResolveSupport = codeAction.resolveSupport;
|
|
22521
23216
|
}
|
|
22522
23217
|
if (completion) {
|
|
22523
23218
|
const {completionItem: completionItem} = completion;
|
|
@@ -22568,10 +23263,10 @@ class LspServer {
|
|
|
22568
23263
|
process.on('SIGINT', () => {
|
|
22569
23264
|
process.exit();
|
|
22570
23265
|
});
|
|
22571
|
-
this.typeScriptAutoFixProvider = new TypeScriptAutoFixProvider(this.tsClient);
|
|
22572
23266
|
this.fileConfigurationManager.setGlobalConfiguration(this.workspaceRoot, hostInfo);
|
|
22573
23267
|
this.registerHandlers();
|
|
22574
23268
|
const prepareSupport = textDocument?.rename?.prepareSupport && this.tsClient.apiVersion.gte(API.v310);
|
|
23269
|
+
const {codeActionLiteralSupport: codeActionLiteralSupport, resolveSupport: codeActionResolveSupport} = textDocument?.codeAction || {};
|
|
22575
23270
|
const initializeResult = {
|
|
22576
23271
|
capabilities: {
|
|
22577
23272
|
textDocumentSync: mainExports$2.TextDocumentSyncKind.Incremental,
|
|
@@ -22579,8 +23274,13 @@ class LspServer {
|
|
|
22579
23274
|
triggerCharacters: [ '.', '"', '\'', '/', '@', '<' ],
|
|
22580
23275
|
resolveProvider: true
|
|
22581
23276
|
},
|
|
22582
|
-
codeActionProvider:
|
|
22583
|
-
|
|
23277
|
+
codeActionProvider: codeActionLiteralSupport || codeActionResolveSupport ? {
|
|
23278
|
+
...codeActionLiteralSupport ? {
|
|
23279
|
+
codeActionKinds: [ ...this.codeActionsManager.kinds, CodeActionKind.SourceOrganizeImportsTs.value, CodeActionKind.SourceRemoveUnusedImportsTs.value, CodeActionKind.SourceSortImportsTs.value, CodeActionKind.Refactor.value ]
|
|
23280
|
+
} : {},
|
|
23281
|
+
...codeActionResolveSupport ? {
|
|
23282
|
+
resolveProvider: true
|
|
23283
|
+
} : {}
|
|
22584
23284
|
} : true,
|
|
22585
23285
|
codeLensProvider: {
|
|
22586
23286
|
resolveProvider: true
|
|
@@ -22591,7 +23291,7 @@ class LspServer {
|
|
|
22591
23291
|
documentHighlightProvider: true,
|
|
22592
23292
|
documentSymbolProvider: true,
|
|
22593
23293
|
executeCommandProvider: {
|
|
22594
|
-
commands: [ Commands.
|
|
23294
|
+
commands: [ Commands.APPLY_REFACTORING, Commands.CONFIGURE_PLUGIN, Commands.ORGANIZE_IMPORTS, Commands.APPLY_RENAME_FILE, Commands.SOURCE_DEFINITION, Commands.TS_SERVER_REQUEST ]
|
|
22595
23295
|
},
|
|
22596
23296
|
hoverProvider: true,
|
|
22597
23297
|
inlayHintProvider: true,
|
|
@@ -22702,7 +23402,7 @@ class LspServer {
|
|
|
22702
23402
|
didChangeConfiguration(params) {
|
|
22703
23403
|
this.fileConfigurationManager.setWorkspaceConfiguration(params.settings || {});
|
|
22704
23404
|
const ignoredDiagnosticCodes = this.fileConfigurationManager.workspaceConfiguration.diagnostics?.ignoredCodes || [];
|
|
22705
|
-
this.tsClient.interruptGetErr(() => this.
|
|
23405
|
+
this.tsClient.interruptGetErr(() => this.diagnosticsManager.updateIgnoredDiagnosticCodes(ignoredDiagnosticCodes));
|
|
22706
23406
|
}
|
|
22707
23407
|
didOpenTextDocument(params) {
|
|
22708
23408
|
if (this.tsClient.toOpenDocument(params.textDocument.uri, {
|
|
@@ -22724,7 +23424,7 @@ class LspServer {
|
|
|
22724
23424
|
}
|
|
22725
23425
|
this.cachedNavTreeResponse.onDocumentClose(document);
|
|
22726
23426
|
this.tsClient.onDidCloseTextDocument(uri);
|
|
22727
|
-
this.
|
|
23427
|
+
this.diagnosticsManager.onDidCloseFile(document.filepath);
|
|
22728
23428
|
this.fileConfigurationManager.onDidCloseTextDocument(document.uri);
|
|
22729
23429
|
}
|
|
22730
23430
|
didChangeTextDocument(params) {
|
|
@@ -23048,13 +23748,9 @@ class LspServer {
|
|
|
23048
23748
|
if (!document) {
|
|
23049
23749
|
return [];
|
|
23050
23750
|
}
|
|
23051
|
-
await this.
|
|
23751
|
+
const actions = await this.codeActionsManager.provideCodeActions(document, params.range, params.context, token);
|
|
23052
23752
|
const fileRangeArgs = Range.toFileRangeRequestArgs(document.filepath, params.range);
|
|
23053
|
-
const actions = [];
|
|
23054
23753
|
const kinds = params.context.only?.map(kind => new CodeActionKind(kind));
|
|
23055
|
-
if (!kinds || kinds.some(kind => CodeActionKind.QuickFix.contains(kind))) {
|
|
23056
|
-
actions.push(...provideQuickFix(await this.getCodeFixes(fileRangeArgs, params.context, token), this.tsClient));
|
|
23057
|
-
}
|
|
23058
23754
|
if (!kinds || kinds.some(kind => CodeActionKind.Refactor.contains(kind))) {
|
|
23059
23755
|
actions.push(...provideRefactors(await this.getRefactors(fileRangeArgs, params.context, this.features, token), fileRangeArgs, this.features));
|
|
23060
23756
|
}
|
|
@@ -23071,36 +23767,24 @@ class LspServer {
|
|
|
23071
23767
|
skipDestructiveCodeActions = documentHasErrors;
|
|
23072
23768
|
mode = OrganizeImportsMode.SortAndCombine;
|
|
23073
23769
|
}
|
|
23074
|
-
const response = await this.tsClient.interruptGetErr(() =>
|
|
23075
|
-
|
|
23076
|
-
|
|
23077
|
-
|
|
23078
|
-
|
|
23079
|
-
|
|
23080
|
-
|
|
23081
|
-
|
|
23770
|
+
const response = await this.tsClient.interruptGetErr(async () => {
|
|
23771
|
+
await this.fileConfigurationManager.ensureConfigurationForDocument(document, token);
|
|
23772
|
+
return this.tsClient.execute(CommandTypes.OrganizeImports, {
|
|
23773
|
+
scope: {
|
|
23774
|
+
type: 'file',
|
|
23775
|
+
args: fileRangeArgs
|
|
23776
|
+
},
|
|
23777
|
+
skipDestructiveCodeActions: skipDestructiveCodeActions,
|
|
23778
|
+
mode: mode
|
|
23779
|
+
}, token);
|
|
23780
|
+
});
|
|
23082
23781
|
if (response.type === 'response' && response.body) {
|
|
23083
23782
|
actions.push(...provideOrganizeImports(command, response, this.tsClient));
|
|
23084
23783
|
}
|
|
23085
23784
|
}
|
|
23086
23785
|
}
|
|
23087
|
-
if (kinds && !this.tsClient.hasPendingDiagnostics(document.uri)) {
|
|
23088
|
-
const diagnostics = this.diagnosticQueue.getDiagnosticsForFile(document.filepath) || [];
|
|
23089
|
-
if (diagnostics.length) {
|
|
23090
|
-
actions.push(...await this.typeScriptAutoFixProvider.provideCodeActions(kinds, document.filepath, diagnostics));
|
|
23091
|
-
}
|
|
23092
|
-
}
|
|
23093
23786
|
return actions;
|
|
23094
23787
|
}
|
|
23095
|
-
async getCodeFixes(fileRangeArgs, context, token) {
|
|
23096
|
-
const errorCodes = context.diagnostics.map(diagnostic => Number(diagnostic.code));
|
|
23097
|
-
const args = {
|
|
23098
|
-
...fileRangeArgs,
|
|
23099
|
-
errorCodes: errorCodes
|
|
23100
|
-
};
|
|
23101
|
-
const response = await this.tsClient.execute(CommandTypes.GetCodeFixes, args, token);
|
|
23102
|
-
return response.type === 'response' ? response : undefined;
|
|
23103
|
-
}
|
|
23104
23788
|
async getRefactors(fileRangeArgs, context, features, token) {
|
|
23105
23789
|
const kinds = context.only || [ undefined ];
|
|
23106
23790
|
const responses = await Promise.all(kinds.map(async kind => {
|
|
@@ -23115,25 +23799,11 @@ class LspServer {
|
|
|
23115
23799
|
}));
|
|
23116
23800
|
return responses.flat();
|
|
23117
23801
|
}
|
|
23802
|
+
async codeActionResolve(params, _token) {
|
|
23803
|
+
return this.codeActionsManager.resolveCodeAction(params);
|
|
23804
|
+
}
|
|
23118
23805
|
async executeCommand(params, token, workDoneProgress) {
|
|
23119
|
-
if (params.command === Commands.
|
|
23120
|
-
const edit = params.arguments[0];
|
|
23121
|
-
await this.options.lspClient.applyWorkspaceEdit({
|
|
23122
|
-
edit: edit
|
|
23123
|
-
});
|
|
23124
|
-
} else if (params.command === Commands.APPLY_CODE_ACTION && params.arguments) {
|
|
23125
|
-
const codeAction = params.arguments[0];
|
|
23126
|
-
if (!await this.applyFileCodeEdits(codeAction.changes)) {
|
|
23127
|
-
return;
|
|
23128
|
-
}
|
|
23129
|
-
if (codeAction.commands?.length) {
|
|
23130
|
-
for (const command of codeAction.commands) {
|
|
23131
|
-
await this.tsClient.execute(CommandTypes.ApplyCodeActionCommand, {
|
|
23132
|
-
command: command
|
|
23133
|
-
}, token);
|
|
23134
|
-
}
|
|
23135
|
-
}
|
|
23136
|
-
} else if (params.command === Commands.APPLY_REFACTORING && params.arguments) {
|
|
23806
|
+
if (await this.commandManager.handle(params.command, ...params.arguments || [])) ; else if (params.command === Commands.APPLY_REFACTORING && params.arguments) {
|
|
23137
23807
|
const args = params.arguments[0];
|
|
23138
23808
|
const response = await this.tsClient.execute(CommandTypes.GetEditsForRefactor, args, token);
|
|
23139
23809
|
if (response.type !== 'response' || !response.body) {
|
|
@@ -23174,6 +23844,7 @@ class LspServer {
|
|
|
23174
23844
|
const additionalArguments = params.arguments[1] || {};
|
|
23175
23845
|
const body = await this.tsClient.interruptGetErr(async () => {
|
|
23176
23846
|
await this.fileConfigurationManager.ensureConfigurationForDocument(document);
|
|
23847
|
+
const mode = additionalArguments.mode ?? (additionalArguments.skipDestructiveCodeActions ? OrganizeImportsMode.SortAndCombine : OrganizeImportsMode.All);
|
|
23177
23848
|
const response = await this.tsClient.execute(CommandTypes.OrganizeImports, {
|
|
23178
23849
|
scope: {
|
|
23179
23850
|
type: 'file',
|
|
@@ -23182,7 +23853,7 @@ class LspServer {
|
|
|
23182
23853
|
}
|
|
23183
23854
|
},
|
|
23184
23855
|
skipDestructiveCodeActions: additionalArguments.skipDestructiveCodeActions,
|
|
23185
|
-
mode:
|
|
23856
|
+
mode: mode
|
|
23186
23857
|
}, token);
|
|
23187
23858
|
if (response.type !== 'response') {
|
|
23188
23859
|
return;
|
|
@@ -23388,7 +24059,7 @@ class LspServer {
|
|
|
23388
24059
|
const diagnosticEvent = event;
|
|
23389
24060
|
if (diagnosticEvent.body?.diagnostics) {
|
|
23390
24061
|
const {file: file, diagnostics: diagnostics} = diagnosticEvent.body;
|
|
23391
|
-
this.
|
|
24062
|
+
this.diagnosticsManager.updateDiagnostics(getDignosticsKind(event), file, diagnostics);
|
|
23392
24063
|
}
|
|
23393
24064
|
}
|
|
23394
24065
|
}
|
|
@@ -23532,6 +24203,12 @@ class LspClientImpl {
|
|
|
23532
24203
|
logMessage(args) {
|
|
23533
24204
|
this.connection.sendNotification(mainExports$2.LogMessageNotification.type, args);
|
|
23534
24205
|
}
|
|
24206
|
+
async getWorkspaceConfiguration(scopeUri, section) {
|
|
24207
|
+
return await this.connection.workspace.getConfiguration({
|
|
24208
|
+
scopeUri: scopeUri,
|
|
24209
|
+
section: section
|
|
24210
|
+
});
|
|
24211
|
+
}
|
|
23535
24212
|
async applyWorkspaceEdit(params) {
|
|
23536
24213
|
return this.connection.workspace.applyEdit(params);
|
|
23537
24214
|
}
|
|
@@ -23559,6 +24236,7 @@ function createLspConnection(options) {
|
|
|
23559
24236
|
connection.onDidCloseTextDocument(server.didCloseTextDocument.bind(server));
|
|
23560
24237
|
connection.onDidChangeTextDocument(server.didChangeTextDocument.bind(server));
|
|
23561
24238
|
connection.onCodeAction(server.codeAction.bind(server));
|
|
24239
|
+
connection.onCodeActionResolve(server.codeActionResolve.bind(server));
|
|
23562
24240
|
connection.onCodeLens(server.codeLens.bind(server));
|
|
23563
24241
|
connection.onCodeLensResolve(server.codeLensResolve.bind(server));
|
|
23564
24242
|
connection.onCompletion(server.completion.bind(server));
|