@teambit/ts-server 0.0.45 → 0.0.46
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/dist/process-based-tsserver.d.ts +9 -6
- package/dist/process-based-tsserver.js +129 -67
- package/dist/process-based-tsserver.js.map +1 -1
- package/dist/ts-server-client.d.ts +5 -3
- package/dist/ts-server-client.js +89 -42
- package/dist/ts-server-client.js.map +1 -1
- package/package-tar/teambit-ts-server-0.0.46.tgz +0 -0
- package/package.json +2 -2
- package/process-based-tsserver.ts +112 -57
- package/ts-server-client.ts +67 -36
- package/package-tar/teambit-ts-server-0.0.45.tgz +0 -0
- /package/dist/{preview-1680406095586.js → preview-1685613946070.js} +0 -0
|
@@ -62,22 +62,25 @@ export declare class ProcessBasedTsServer {
|
|
|
62
62
|
private readlineInterface;
|
|
63
63
|
private tsServerProcess;
|
|
64
64
|
private seq;
|
|
65
|
+
private TSSERVER_START_TIMEOUT;
|
|
65
66
|
private readonly deferreds;
|
|
66
67
|
private logger;
|
|
67
68
|
private cancellationPipeName;
|
|
68
69
|
constructor(options: TspClientOptions, tsServerArgs?: TsServerArgs);
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
notify(command: CommandTypes.
|
|
72
|
-
notify(command: CommandTypes.
|
|
73
|
-
notify(command: CommandTypes.
|
|
70
|
+
restart(): Promise<void>;
|
|
71
|
+
start(): Promise<void>;
|
|
72
|
+
notify(command: CommandTypes.Open, args: protocol.OpenRequestArgs): Promise<void>;
|
|
73
|
+
notify(command: CommandTypes.Close, args: protocol.FileRequestArgs): Promise<void>;
|
|
74
|
+
notify(command: CommandTypes.Saveto, args: protocol.SavetoRequestArgs): Promise<void>;
|
|
75
|
+
notify(command: CommandTypes.Change, args: protocol.ChangeRequestArgs): Promise<void>;
|
|
74
76
|
request<K extends keyof TypeScriptRequestTypes>(command: K, args: TypeScriptRequestTypes[K][0], token?: CancellationToken): Promise<TypeScriptRequestTypes[K][1]>;
|
|
75
77
|
kill(): void;
|
|
76
78
|
private log;
|
|
77
79
|
protected sendMessage(command: string, notification: boolean, args?: any): void;
|
|
78
|
-
protected processMessage(untrimmedMessageString: string): void;
|
|
80
|
+
protected processMessage(untrimmedMessageString: string, resolve?: () => void, reject?: (err: any) => void): void;
|
|
79
81
|
private resolveResponse;
|
|
80
82
|
private isEvent;
|
|
81
83
|
private isResponse;
|
|
82
84
|
private isRequestCompletedEvent;
|
|
85
|
+
private ensureServerIsRunning;
|
|
83
86
|
}
|
|
@@ -25,6 +25,15 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
__setModuleDefault(result, mod);
|
|
26
26
|
return result;
|
|
27
27
|
};
|
|
28
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
29
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
30
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
31
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
32
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
33
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
34
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
35
|
+
});
|
|
36
|
+
};
|
|
28
37
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
29
38
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
39
|
};
|
|
@@ -48,81 +57,116 @@ class ProcessBasedTsServer {
|
|
|
48
57
|
this.options = options;
|
|
49
58
|
this.tsServerArgs = tsServerArgs;
|
|
50
59
|
this.seq = 0;
|
|
60
|
+
this.TSSERVER_START_TIMEOUT = 5000; // 5s
|
|
51
61
|
this.deferreds = {};
|
|
52
62
|
this.logger = options.logger;
|
|
53
63
|
}
|
|
64
|
+
restart() {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
this.kill();
|
|
67
|
+
yield this.start();
|
|
68
|
+
});
|
|
69
|
+
}
|
|
54
70
|
start() {
|
|
55
|
-
|
|
56
|
-
if (this.readlineInterface) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
const { tsserverPath } = this.options;
|
|
60
|
-
const { logFile, logVerbosity, maxTsServerMemory, globalPlugins, pluginProbeLocations } = this.tsServerArgs;
|
|
61
|
-
const args = [];
|
|
62
|
-
if (logFile) {
|
|
63
|
-
args.push('--logFile', logFile);
|
|
64
|
-
}
|
|
65
|
-
if (logVerbosity) {
|
|
66
|
-
args.push('--logVerbosity', logVerbosity);
|
|
67
|
-
}
|
|
68
|
-
if (globalPlugins && globalPlugins.length) {
|
|
69
|
-
args.push('--globalPlugins', globalPlugins.join(','));
|
|
70
|
-
}
|
|
71
|
-
if (pluginProbeLocations && pluginProbeLocations.length) {
|
|
72
|
-
args.push('--pluginProbeLocations', pluginProbeLocations.join(','));
|
|
73
|
-
}
|
|
74
|
-
this.cancellationPipeName = tempy_1.default.file({ name: 'tscancellation' });
|
|
75
|
-
args.push('--cancellationPipeName', `${this.cancellationPipeName}*`);
|
|
76
|
-
this.logger.info(`Starting tsserver : '${tsserverPath} ${args.join(' ')}'`);
|
|
77
|
-
const tsserverPathIsModule = path.extname(tsserverPath) === '.js';
|
|
78
|
-
const options = {
|
|
79
|
-
silent: true,
|
|
80
|
-
execArgv: [...(maxTsServerMemory ? [`--max-old-space-size=${maxTsServerMemory}`] : [])],
|
|
81
|
-
};
|
|
82
|
-
this.tsServerProcess = tsserverPathIsModule ? cp.fork(tsserverPath, args, options) : cp.spawn(tsserverPath, args);
|
|
83
|
-
this.readlineInterface = readline.createInterface(this.tsServerProcess.stdout, this.tsServerProcess.stdin, undefined);
|
|
84
|
-
process.on('exit', () => {
|
|
71
|
+
return new Promise((resolve, reject) => {
|
|
85
72
|
var _a;
|
|
86
|
-
this.
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
73
|
+
if (this.tsServerProcess) {
|
|
74
|
+
reject(new Error('server already started'));
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const { tsserverPath } = this.options;
|
|
78
|
+
const { logFile, logVerbosity, maxTsServerMemory, globalPlugins, pluginProbeLocations } = this.tsServerArgs;
|
|
79
|
+
const args = [];
|
|
80
|
+
if (logFile) {
|
|
81
|
+
args.push('--logFile', logFile);
|
|
82
|
+
}
|
|
83
|
+
if (logVerbosity) {
|
|
84
|
+
args.push('--logVerbosity', logVerbosity);
|
|
85
|
+
}
|
|
86
|
+
if (globalPlugins && globalPlugins.length) {
|
|
87
|
+
args.push('--globalPlugins', globalPlugins.join(','));
|
|
88
|
+
}
|
|
89
|
+
if (pluginProbeLocations && pluginProbeLocations.length) {
|
|
90
|
+
args.push('--pluginProbeLocations', pluginProbeLocations.join(','));
|
|
91
|
+
}
|
|
92
|
+
this.cancellationPipeName = tempy_1.default.file({ name: 'tscancellation' });
|
|
93
|
+
args.push('--cancellationPipeName', `${this.cancellationPipeName}*`);
|
|
94
|
+
this.logger.info(`Starting tsserver : '${tsserverPath} ${args.join(' ')}'`);
|
|
95
|
+
const tsserverPathIsModule = path.extname(tsserverPath) === '.js';
|
|
96
|
+
const options = {
|
|
97
|
+
silent: true,
|
|
98
|
+
execArgv: [...(maxTsServerMemory ? [`--max-old-space-size=${maxTsServerMemory}`] : [])],
|
|
99
|
+
};
|
|
100
|
+
this.tsServerProcess = tsserverPathIsModule ? cp.fork(tsserverPath, args, options) : cp.spawn(tsserverPath, args);
|
|
101
|
+
const timeout = setTimeout(() => {
|
|
102
|
+
reject(new Error(`TIMEOUT: TSServer did not start within the specified time ${this.TSSERVER_START_TIMEOUT}s`));
|
|
103
|
+
}, this.TSSERVER_START_TIMEOUT);
|
|
104
|
+
this.readlineInterface = readline.createInterface(this.tsServerProcess.stdout, this.tsServerProcess.stdin, undefined);
|
|
105
|
+
process.on('exit', () => {
|
|
106
|
+
this.kill();
|
|
107
|
+
reject(new Error('TSServer was killed'));
|
|
108
|
+
});
|
|
109
|
+
this.readlineInterface.on('line', (line) => {
|
|
110
|
+
clearTimeout(timeout);
|
|
111
|
+
this.processMessage(line, resolve, reject);
|
|
112
|
+
});
|
|
113
|
+
const dec = new decoder.StringDecoder('utf-8');
|
|
114
|
+
(_a = this.tsServerProcess.stderr) === null || _a === void 0 ? void 0 : _a.addListener('data', (data) => {
|
|
115
|
+
const stringMsg = typeof data === 'string' ? data : dec.write(data);
|
|
116
|
+
this.logger.error(stringMsg);
|
|
117
|
+
reject(new Error(stringMsg));
|
|
118
|
+
});
|
|
95
119
|
});
|
|
96
120
|
}
|
|
97
121
|
notify(command, args) {
|
|
98
|
-
this
|
|
122
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
+
yield this.ensureServerIsRunning();
|
|
124
|
+
this.sendMessage(command, true, args);
|
|
125
|
+
});
|
|
99
126
|
}
|
|
100
127
|
request(command, args, token) {
|
|
101
|
-
this
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
128
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
yield this.ensureServerIsRunning();
|
|
130
|
+
this.sendMessage(command, false, args);
|
|
131
|
+
const seq = this.seq;
|
|
132
|
+
const deferred = new utils_1.Deferred();
|
|
133
|
+
this.deferreds[seq] = deferred;
|
|
134
|
+
const request = deferred.promise;
|
|
135
|
+
let onCancelled;
|
|
136
|
+
if (token) {
|
|
137
|
+
onCancelled = token.onCancellationRequested(() => {
|
|
138
|
+
onCancelled.dispose();
|
|
139
|
+
if (this.cancellationPipeName) {
|
|
140
|
+
const requestCancellationPipeName = `${this.cancellationPipeName}${seq}`;
|
|
141
|
+
fs.writeFile(requestCancellationPipeName, '', (err) => {
|
|
142
|
+
if (!err) {
|
|
143
|
+
// eslint-disable-next-line
|
|
144
|
+
request.then(() => fs.unlink(requestCancellationPipeName, () => {
|
|
145
|
+
/* no-op */
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
const result = yield request;
|
|
154
|
+
onCancelled === null || onCancelled === void 0 ? void 0 : onCancelled.dispose();
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
this.logger.error(`Error in request: ${error}`);
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
161
|
+
});
|
|
123
162
|
}
|
|
124
163
|
kill() {
|
|
125
|
-
|
|
164
|
+
var _a, _b, _c, _d;
|
|
165
|
+
(_a = this.tsServerProcess) === null || _a === void 0 ? void 0 : _a.kill();
|
|
166
|
+
(_c = (_b = this.tsServerProcess) === null || _b === void 0 ? void 0 : _b.stdin) === null || _c === void 0 ? void 0 : _c.destroy();
|
|
167
|
+
(_d = this.readlineInterface) === null || _d === void 0 ? void 0 : _d.close();
|
|
168
|
+
this.tsServerProcess = null;
|
|
169
|
+
this.readlineInterface = null;
|
|
126
170
|
}
|
|
127
171
|
log(msg, obj = {}) {
|
|
128
172
|
msg = `[tsserver] ${msg}`;
|
|
@@ -134,7 +178,7 @@ class ProcessBasedTsServer {
|
|
|
134
178
|
}
|
|
135
179
|
}
|
|
136
180
|
sendMessage(command, notification, args) {
|
|
137
|
-
var _a;
|
|
181
|
+
var _a, _b;
|
|
138
182
|
this.seq += 1;
|
|
139
183
|
const request = {
|
|
140
184
|
command,
|
|
@@ -145,16 +189,27 @@ class ProcessBasedTsServer {
|
|
|
145
189
|
request.arguments = args;
|
|
146
190
|
}
|
|
147
191
|
const serializedRequest = `${JSON.stringify(request)}\n`;
|
|
148
|
-
(_a = this.tsServerProcess
|
|
192
|
+
(_b = (_a = this.tsServerProcess) === null || _a === void 0 ? void 0 : _a.stdin) === null || _b === void 0 ? void 0 : _b.write(serializedRequest);
|
|
149
193
|
this.log(notification ? 'notify' : 'request', request);
|
|
150
194
|
}
|
|
151
|
-
processMessage(untrimmedMessageString) {
|
|
195
|
+
processMessage(untrimmedMessageString, resolve, reject) {
|
|
152
196
|
const messageString = untrimmedMessageString.trim();
|
|
153
197
|
if (!messageString || messageString.startsWith('Content-Length:')) {
|
|
154
198
|
return;
|
|
155
199
|
}
|
|
156
|
-
|
|
200
|
+
let message;
|
|
201
|
+
try {
|
|
202
|
+
message = JSON.parse(messageString);
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
// If the message isn't valid JSON, it's not a valid tsserver message. Reject the promise.
|
|
206
|
+
reject === null || reject === void 0 ? void 0 : reject(new Error(`Received invalid message from TSServer: ${untrimmedMessageString}`));
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
157
209
|
this.log('processMessage', message);
|
|
210
|
+
if (this.isEvent(message)) {
|
|
211
|
+
resolve === null || resolve === void 0 ? void 0 : resolve();
|
|
212
|
+
}
|
|
158
213
|
if (this.isResponse(message)) {
|
|
159
214
|
this.resolveResponse(message, message.request_seq, message.success);
|
|
160
215
|
}
|
|
@@ -189,6 +244,13 @@ class ProcessBasedTsServer {
|
|
|
189
244
|
isRequestCompletedEvent(message) {
|
|
190
245
|
return this.isEvent(message) && message.event === 'requestCompleted';
|
|
191
246
|
}
|
|
247
|
+
ensureServerIsRunning() {
|
|
248
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
249
|
+
if (!this.tsServerProcess) {
|
|
250
|
+
yield this.restart();
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
}
|
|
192
254
|
}
|
|
193
255
|
exports.ProcessBasedTsServer = ProcessBasedTsServer;
|
|
194
256
|
//# sourceMappingURL=process-based-tsserver.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-based-tsserver.js","sourceRoot":"","sources":["../process-based-tsserver.ts"],"names":[],"mappings":";AAAA;;GAEG
|
|
1
|
+
{"version":3,"file":"process-based-tsserver.js","sourceRoot":"","sources":["../process-based-tsserver.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH;;;;;GAKG;AAEH,uCAAyB;AACzB,2CAA6B;AAC7B,kDAAoC;AACpC,mDAAqC;AAGrC,wDAA0C;AAG1C,kDAA0B;AAG1B,mCAAmC;AAwDnC,MAAa,oBAAoB;IAa/B,YAAoB,OAAyB,EAAU,eAA6B,EAAE;QAAlE,YAAO,GAAP,OAAO,CAAkB;QAAU,iBAAY,GAAZ,YAAY,CAAmB;QAV9E,QAAG,GAAG,CAAC,CAAC;QACR,2BAAsB,GAAG,IAAI,CAAC,CAAC,KAAK;QAE3B,cAAS,GAEtB,EAAE,CAAC;QAML,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC/B,CAAC;IAEK,OAAO;;YACX,IAAI,CAAC,IAAI,EAAE,CAAC;YACZ,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;QACrB,CAAC;KAAA;IAED,KAAK;QACH,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;;YAC3C,IAAI,IAAI,CAAC,eAAe,EAAE;gBACxB,MAAM,CAAC,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC,CAAC;gBAC5C,OAAO;aACR;YAED,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;YACtC,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,aAAa,EAAE,oBAAoB,EAAE,GAAG,IAAI,CAAC,YAAY,CAAC;YAC5G,MAAM,IAAI,GAAa,EAAE,CAAC;YA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C/D;iBAAM,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;gBAC/B,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;aAC/B;SACF;IACH,CAAC;IAEO,eAAe,CAAC,OAAyB,EAAE,WAAmB,EAAE,OAAgB;QACtF,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;QAC7C,IAAI,CAAC,GAAG,CAAC,mBAAmB,EAAE,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC,CAAC;QACxD,IAAI,QAAQ,EAAE;YACZ,IAAI,OAAO,EAAE;gBACX,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;aAC9C;iBAAM;gBACL,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;aAC7C;YACD,OAAO,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;SACpC;IACH,CAAC;IAEO,OAAO,CAAC,OAAyB;QACvC,OAAO,OAAO,CAAC,IAAI,KAAK,OAAO,CAAC;IAClC,CAAC;IAEO,UAAU,CAAC,OAAyB;QAC1C,OAAO,OAAO,CAAC,IAAI,KAAK,UAAU,CAAC;IACrC,CAAC;IAEO,uBAAuB,CAAC,OAAyB;QACvD,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,KAAK,KAAK,kBAAkB,CAAC;IACvE,CAAC;IAEa,qBAAqB;;YACjC,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;gBACzB,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;aACtB;QACH,CAAC;KAAA;CACF;AAnOD,oDAmOC"}
|
|
@@ -22,6 +22,7 @@ export declare class TsserverClient {
|
|
|
22
22
|
private files;
|
|
23
23
|
private tsServer;
|
|
24
24
|
lastDiagnostics: protocol.DiagnosticEventBody[];
|
|
25
|
+
private serverRunning;
|
|
25
26
|
constructor(
|
|
26
27
|
/**
|
|
27
28
|
* absolute root path of the project.
|
|
@@ -37,7 +38,7 @@ export declare class TsserverClient {
|
|
|
37
38
|
* this methods returns pretty fast. if checkTypes is enabled, it runs the process in the background and
|
|
38
39
|
* doesn't wait for it.
|
|
39
40
|
*/
|
|
40
|
-
init(): void
|
|
41
|
+
init(): Promise<void>;
|
|
41
42
|
private checkTypesIfNeeded;
|
|
42
43
|
private shouldCheckTypes;
|
|
43
44
|
/**
|
|
@@ -45,6 +46,7 @@ export declare class TsserverClient {
|
|
|
45
46
|
*/
|
|
46
47
|
onFileChange(file: string): Promise<void>;
|
|
47
48
|
killTsServer(): void;
|
|
49
|
+
isServerRunning(): boolean;
|
|
48
50
|
/**
|
|
49
51
|
* get diagnostic of all files opened in the project.
|
|
50
52
|
* there is little to no value of getting diagnostic for a specific file, as
|
|
@@ -82,9 +84,9 @@ export declare class TsserverClient {
|
|
|
82
84
|
* ask tsserver to open a file if it was not opened before.
|
|
83
85
|
* @param file absolute path of the file
|
|
84
86
|
*/
|
|
85
|
-
openIfNeeded(file: string): void
|
|
87
|
+
openIfNeeded(file: string): Promise<void>;
|
|
86
88
|
private open;
|
|
87
|
-
close(file: string): void
|
|
89
|
+
close(file: string): Promise<void>;
|
|
88
90
|
/**
|
|
89
91
|
* since Bit is not an IDE, it doesn't have the information such as the exact line/offset of the changes.
|
|
90
92
|
* as a workaround, to tell tsserver what was changed, we pretend that the entire file was cleared and new text was
|
package/dist/ts-server-client.js
CHANGED
|
@@ -38,6 +38,7 @@ class TsserverClient {
|
|
|
38
38
|
this.options = options;
|
|
39
39
|
this.files = files;
|
|
40
40
|
this.lastDiagnostics = [];
|
|
41
|
+
this.serverRunning = false;
|
|
41
42
|
}
|
|
42
43
|
/**
|
|
43
44
|
* start the ts-server and keep its process alive.
|
|
@@ -45,18 +46,40 @@ class TsserverClient {
|
|
|
45
46
|
* doesn't wait for it.
|
|
46
47
|
*/
|
|
47
48
|
init() {
|
|
48
|
-
this
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
try {
|
|
51
|
+
this.tsServer = new process_based_tsserver_1.ProcessBasedTsServer({
|
|
52
|
+
logger: this.logger,
|
|
53
|
+
tsserverPath: this.findTsserverPath(),
|
|
54
|
+
logToConsole: this.options.verbose,
|
|
55
|
+
onEvent: this.onTsserverEvent.bind(this),
|
|
56
|
+
});
|
|
57
|
+
this.tsServer
|
|
58
|
+
.start()
|
|
59
|
+
.then(() => {
|
|
60
|
+
this.serverRunning = true;
|
|
61
|
+
})
|
|
62
|
+
.catch((err) => {
|
|
63
|
+
this.logger.error('TsserverClient.init failed', err);
|
|
64
|
+
});
|
|
65
|
+
if (this.files.length) {
|
|
66
|
+
const openPromises = this.files.map((file) => this.open(file));
|
|
67
|
+
yield Promise.all(openPromises.map((promise) => promise.catch((error) => error)));
|
|
68
|
+
const failedFiles = openPromises.filter((promise) => promise instanceof Error);
|
|
69
|
+
if (failedFiles.length > 0) {
|
|
70
|
+
this.logger.error('TsserverClient.init failed to open files:', failedFiles);
|
|
71
|
+
}
|
|
72
|
+
if (failedFiles.length > 0) {
|
|
73
|
+
this.logger.error('TsserverClient.init failed to open files:', failedFiles);
|
|
74
|
+
}
|
|
75
|
+
this.checkTypesIfNeeded();
|
|
76
|
+
}
|
|
77
|
+
this.logger.debug('TsserverClient.init completed');
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
this.logger.error('TsserverClient.init failed', err);
|
|
81
|
+
}
|
|
53
82
|
});
|
|
54
|
-
this.tsServer.start();
|
|
55
|
-
if (this.files.length) {
|
|
56
|
-
this.files.forEach((file) => this.open(file));
|
|
57
|
-
}
|
|
58
|
-
this.checkTypesIfNeeded();
|
|
59
|
-
this.logger.debug('TsserverClient.init completed');
|
|
60
83
|
}
|
|
61
84
|
checkTypesIfNeeded(files = this.files) {
|
|
62
85
|
if (!this.shouldCheckTypes()) {
|
|
@@ -95,7 +118,14 @@ class TsserverClient {
|
|
|
95
118
|
});
|
|
96
119
|
}
|
|
97
120
|
killTsServer() {
|
|
98
|
-
this.tsServer.
|
|
121
|
+
if (this.tsServer && this.serverRunning) {
|
|
122
|
+
this.tsServer.kill();
|
|
123
|
+
this.tsServer = null;
|
|
124
|
+
this.serverRunning = false;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
isServerRunning() {
|
|
128
|
+
return this.serverRunning;
|
|
99
129
|
}
|
|
100
130
|
/**
|
|
101
131
|
* get diagnostic of all files opened in the project.
|
|
@@ -108,27 +138,30 @@ class TsserverClient {
|
|
|
108
138
|
* were found or not.
|
|
109
139
|
*/
|
|
110
140
|
getDiagnostic(files = this.files) {
|
|
141
|
+
var _a;
|
|
111
142
|
return __awaiter(this, void 0, void 0, function* () {
|
|
112
143
|
this.lastDiagnostics = [];
|
|
113
|
-
return this.tsServer.request(tsp_command_types_1.CommandTypes.Geterr, { delay: 0, files });
|
|
144
|
+
return (_a = this.tsServer) === null || _a === void 0 ? void 0 : _a.request(tsp_command_types_1.CommandTypes.Geterr, { delay: 0, files });
|
|
114
145
|
});
|
|
115
146
|
}
|
|
116
147
|
/**
|
|
117
148
|
* avoid using this method, it takes longer than `getDiagnostic()` and shows errors from paths outside the project
|
|
118
149
|
*/
|
|
119
150
|
getDiagnosticAllProject(requestedByFile) {
|
|
151
|
+
var _a;
|
|
120
152
|
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
-
return this.tsServer.request(tsp_command_types_1.CommandTypes.GeterrForProject, { file: requestedByFile, delay: 0 });
|
|
153
|
+
return (_a = this.tsServer) === null || _a === void 0 ? void 0 : _a.request(tsp_command_types_1.CommandTypes.GeterrForProject, { file: requestedByFile, delay: 0 });
|
|
122
154
|
});
|
|
123
155
|
}
|
|
124
156
|
/**
|
|
125
157
|
* @param file can be absolute or relative to this.projectRoot.
|
|
126
158
|
*/
|
|
127
159
|
getQuickInfo(file, position) {
|
|
160
|
+
var _a;
|
|
128
161
|
return __awaiter(this, void 0, void 0, function* () {
|
|
129
162
|
const absFile = this.convertFileToAbsoluteIfNeeded(file);
|
|
130
|
-
this.openIfNeeded(absFile);
|
|
131
|
-
return this.tsServer.request(tsp_command_types_1.CommandTypes.Quickinfo, {
|
|
163
|
+
yield this.openIfNeeded(absFile);
|
|
164
|
+
return (_a = this.tsServer) === null || _a === void 0 ? void 0 : _a.request(tsp_command_types_1.CommandTypes.Quickinfo, {
|
|
132
165
|
file: absFile,
|
|
133
166
|
line: position.line,
|
|
134
167
|
offset: position.character,
|
|
@@ -139,10 +172,11 @@ class TsserverClient {
|
|
|
139
172
|
* @param file can be absolute or relative to this.projectRoot.
|
|
140
173
|
*/
|
|
141
174
|
getTypeDefinition(file, position) {
|
|
175
|
+
var _a;
|
|
142
176
|
return __awaiter(this, void 0, void 0, function* () {
|
|
143
177
|
const absFile = this.convertFileToAbsoluteIfNeeded(file);
|
|
144
|
-
this.openIfNeeded(absFile);
|
|
145
|
-
return this.tsServer.request(tsp_command_types_1.CommandTypes.TypeDefinition, {
|
|
178
|
+
yield this.openIfNeeded(absFile);
|
|
179
|
+
return (_a = this.tsServer) === null || _a === void 0 ? void 0 : _a.request(tsp_command_types_1.CommandTypes.TypeDefinition, {
|
|
146
180
|
file: absFile,
|
|
147
181
|
line: position.line,
|
|
148
182
|
offset: position.character,
|
|
@@ -150,15 +184,16 @@ class TsserverClient {
|
|
|
150
184
|
});
|
|
151
185
|
}
|
|
152
186
|
getDefinition(file, position) {
|
|
187
|
+
var _a;
|
|
153
188
|
return __awaiter(this, void 0, void 0, function* () {
|
|
154
189
|
const absFile = this.convertFileToAbsoluteIfNeeded(file);
|
|
155
|
-
this.openIfNeeded(absFile);
|
|
156
|
-
const response = yield this.tsServer.request(tsp_command_types_1.CommandTypes.Definition, {
|
|
190
|
+
yield this.openIfNeeded(absFile);
|
|
191
|
+
const response = yield ((_a = this.tsServer) === null || _a === void 0 ? void 0 : _a.request(tsp_command_types_1.CommandTypes.Definition, {
|
|
157
192
|
file: absFile,
|
|
158
193
|
line: position.line,
|
|
159
194
|
offset: position.character,
|
|
160
|
-
});
|
|
161
|
-
if (!response.success) {
|
|
195
|
+
}));
|
|
196
|
+
if (!(response === null || response === void 0 ? void 0 : response.success)) {
|
|
162
197
|
// TODO: we need a function to handle responses properly here for all.
|
|
163
198
|
return response;
|
|
164
199
|
}
|
|
@@ -169,10 +204,11 @@ class TsserverClient {
|
|
|
169
204
|
* @param file can be absolute or relative to this.projectRoot.
|
|
170
205
|
*/
|
|
171
206
|
getReferences(file, position) {
|
|
207
|
+
var _a;
|
|
172
208
|
return __awaiter(this, void 0, void 0, function* () {
|
|
173
209
|
const absFile = this.convertFileToAbsoluteIfNeeded(file);
|
|
174
|
-
this.openIfNeeded(absFile);
|
|
175
|
-
return this.tsServer.request(tsp_command_types_1.CommandTypes.References, {
|
|
210
|
+
yield this.openIfNeeded(absFile);
|
|
211
|
+
return (_a = this.tsServer) === null || _a === void 0 ? void 0 : _a.request(tsp_command_types_1.CommandTypes.References, {
|
|
176
212
|
file: absFile,
|
|
177
213
|
line: position.line,
|
|
178
214
|
offset: position.character,
|
|
@@ -183,10 +219,11 @@ class TsserverClient {
|
|
|
183
219
|
* @param file can be absolute or relative to this.projectRoot.
|
|
184
220
|
*/
|
|
185
221
|
getSignatureHelp(file, position) {
|
|
222
|
+
var _a;
|
|
186
223
|
return __awaiter(this, void 0, void 0, function* () {
|
|
187
224
|
const absFile = this.convertFileToAbsoluteIfNeeded(file);
|
|
188
|
-
this.openIfNeeded(absFile);
|
|
189
|
-
return this.tsServer.request(tsp_command_types_1.CommandTypes.SignatureHelp, {
|
|
225
|
+
yield this.openIfNeeded(absFile);
|
|
226
|
+
return (_a = this.tsServer) === null || _a === void 0 ? void 0 : _a.request(tsp_command_types_1.CommandTypes.SignatureHelp, {
|
|
190
227
|
file: absFile,
|
|
191
228
|
line: position.line,
|
|
192
229
|
offset: position.character,
|
|
@@ -194,8 +231,9 @@ class TsserverClient {
|
|
|
194
231
|
});
|
|
195
232
|
}
|
|
196
233
|
configure(configureArgs = {}) {
|
|
234
|
+
var _a;
|
|
197
235
|
return __awaiter(this, void 0, void 0, function* () {
|
|
198
|
-
return this.tsServer.request(tsp_command_types_1.CommandTypes.Configure, configureArgs);
|
|
236
|
+
return (_a = this.tsServer) === null || _a === void 0 ? void 0 : _a.request(tsp_command_types_1.CommandTypes.Configure, configureArgs);
|
|
199
237
|
});
|
|
200
238
|
}
|
|
201
239
|
/**
|
|
@@ -203,23 +241,31 @@ class TsserverClient {
|
|
|
203
241
|
* @param file absolute path of the file
|
|
204
242
|
*/
|
|
205
243
|
openIfNeeded(file) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
244
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
245
|
+
if (this.files.includes(file)) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
yield this.open(file);
|
|
249
|
+
this.files.push(file);
|
|
250
|
+
});
|
|
211
251
|
}
|
|
212
252
|
open(file) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
253
|
+
var _a;
|
|
254
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
255
|
+
return (_a = this.tsServer) === null || _a === void 0 ? void 0 : _a.notify(tsp_command_types_1.CommandTypes.Open, {
|
|
256
|
+
file,
|
|
257
|
+
projectRootPath: this.projectPath,
|
|
258
|
+
});
|
|
216
259
|
});
|
|
217
260
|
}
|
|
218
261
|
close(file) {
|
|
219
|
-
|
|
220
|
-
|
|
262
|
+
var _a;
|
|
263
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
264
|
+
yield ((_a = this.tsServer) === null || _a === void 0 ? void 0 : _a.notify(tsp_command_types_1.CommandTypes.Close, {
|
|
265
|
+
file,
|
|
266
|
+
}));
|
|
267
|
+
this.files = this.files.filter((openFile) => openFile !== file);
|
|
221
268
|
});
|
|
222
|
-
this.files = this.files.filter((openFile) => openFile !== file);
|
|
223
269
|
}
|
|
224
270
|
/**
|
|
225
271
|
* since Bit is not an IDE, it doesn't have the information such as the exact line/offset of the changes.
|
|
@@ -228,26 +274,27 @@ class TsserverClient {
|
|
|
228
274
|
* the file content remained the same. (closing/re-opening the file doesn't help).
|
|
229
275
|
*/
|
|
230
276
|
changed(file) {
|
|
277
|
+
var _a, _b;
|
|
231
278
|
return __awaiter(this, void 0, void 0, function* () {
|
|
232
279
|
// tell tsserver that all content was removed
|
|
233
|
-
this.tsServer.notify(tsp_command_types_1.CommandTypes.Change, {
|
|
280
|
+
yield ((_a = this.tsServer) === null || _a === void 0 ? void 0 : _a.notify(tsp_command_types_1.CommandTypes.Change, {
|
|
234
281
|
file,
|
|
235
282
|
line: 1,
|
|
236
283
|
offset: 1,
|
|
237
284
|
endLine: 99999,
|
|
238
285
|
endOffset: 1,
|
|
239
286
|
insertString: '',
|
|
240
|
-
});
|
|
287
|
+
}));
|
|
241
288
|
const content = yield fs_extra_1.default.readFile(file, 'utf-8');
|
|
242
289
|
// tell tsserver that all file content was added
|
|
243
|
-
this.tsServer.notify(tsp_command_types_1.CommandTypes.Change, {
|
|
290
|
+
yield ((_b = this.tsServer) === null || _b === void 0 ? void 0 : _b.notify(tsp_command_types_1.CommandTypes.Change, {
|
|
244
291
|
file,
|
|
245
292
|
line: 1,
|
|
246
293
|
offset: 1,
|
|
247
294
|
endLine: 1,
|
|
248
295
|
endOffset: 1,
|
|
249
296
|
insertString: content,
|
|
250
|
-
});
|
|
297
|
+
}));
|
|
251
298
|
});
|
|
252
299
|
}
|
|
253
300
|
onTsserverEvent(event) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ts-server-client.js","sourceRoot":"","sources":["../ts-server-client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,wDAA0B;AAE1B,gDAAwB;AAGxB,8CAA8C;AAE9C,oEAA2C;AAC3C,yDAAsD;AACtD,qEAAgE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QACxC,MAAM,IAAI,GAAG,cAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAChE,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAA,qCAAgB,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IAChG,CAAC;IAED;;OAEG;IACK,gBAAgB;QACtB,IAAI,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE;YAC7B,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC;SAClC;QAED,MAAM,YAAY,GAAG,cAAI,CAAC,IAAI,CAAC,YAAY,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC;QAEnE;;WAEG;QACH,MAAM,OAAO,GAAG,IAAA,mCAAgB,EAAC,SAAS,EAAE,YAAY,CAAC,CAAC;QAE1D,IAAI,OAAO,EAAE;YACX,OAAO,OAAO,CAAC;SAChB;QAED,sCAAsC;QACtC,IAAI,wBAAa,CAAC,IAAI,CAAC,IAAA,6BAAqB,GAAE,CAAC,EAAE;YAC/C,OAAO,IAAA,6BAAqB,GAAE,CAAC;SAChC;QAED,MAAM,IAAI,KAAK,CAAC,kBAAkB,IAAA,6BAAqB,GAAE,sCAAsC,CAAC,CAAC;IACnG,CAAC;CACF;AA3TD,wCA2TC"}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/ts-server",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.46",
|
|
4
4
|
"homepage": "https://bit.cloud/teambit/typescript/ts-server",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.typescript",
|
|
8
8
|
"name": "ts-server",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.46"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"typescript": "4.7.4",
|
|
@@ -78,9 +78,10 @@ export interface TypeScriptRequestTypes {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
export class ProcessBasedTsServer {
|
|
81
|
-
private readlineInterface: readline.ReadLine;
|
|
82
|
-
private tsServerProcess: cp.ChildProcess;
|
|
81
|
+
private readlineInterface: readline.ReadLine | null;
|
|
82
|
+
private tsServerProcess: cp.ChildProcess | null;
|
|
83
83
|
private seq = 0;
|
|
84
|
+
private TSSERVER_START_TIMEOUT = 5000; // 5s
|
|
84
85
|
|
|
85
86
|
private readonly deferreds: {
|
|
86
87
|
[seq: number]: Deferred<any>;
|
|
@@ -93,73 +94,95 @@ export class ProcessBasedTsServer {
|
|
|
93
94
|
this.logger = options.logger;
|
|
94
95
|
}
|
|
95
96
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const { tsserverPath } = this.options;
|
|
101
|
-
const { logFile, logVerbosity, maxTsServerMemory, globalPlugins, pluginProbeLocations } = this.tsServerArgs;
|
|
102
|
-
const args: string[] = [];
|
|
103
|
-
if (logFile) {
|
|
104
|
-
args.push('--logFile', logFile);
|
|
105
|
-
}
|
|
106
|
-
if (logVerbosity) {
|
|
107
|
-
args.push('--logVerbosity', logVerbosity);
|
|
108
|
-
}
|
|
109
|
-
if (globalPlugins && globalPlugins.length) {
|
|
110
|
-
args.push('--globalPlugins', globalPlugins.join(','));
|
|
111
|
-
}
|
|
112
|
-
if (pluginProbeLocations && pluginProbeLocations.length) {
|
|
113
|
-
args.push('--pluginProbeLocations', pluginProbeLocations.join(','));
|
|
114
|
-
}
|
|
115
|
-
this.cancellationPipeName = tempy.file({ name: 'tscancellation' });
|
|
116
|
-
args.push('--cancellationPipeName', `${this.cancellationPipeName}*`);
|
|
117
|
-
this.logger.info(`Starting tsserver : '${tsserverPath} ${args.join(' ')}'`);
|
|
118
|
-
const tsserverPathIsModule = path.extname(tsserverPath) === '.js';
|
|
119
|
-
const options = {
|
|
120
|
-
silent: true,
|
|
121
|
-
execArgv: [...(maxTsServerMemory ? [`--max-old-space-size=${maxTsServerMemory}`] : [])],
|
|
122
|
-
};
|
|
123
|
-
this.tsServerProcess = tsserverPathIsModule ? cp.fork(tsserverPath, args, options) : cp.spawn(tsserverPath, args);
|
|
124
|
-
this.readlineInterface = readline.createInterface(
|
|
125
|
-
this.tsServerProcess.stdout as Readable,
|
|
126
|
-
this.tsServerProcess.stdin as Writable,
|
|
127
|
-
undefined
|
|
128
|
-
);
|
|
129
|
-
process.on('exit', () => {
|
|
130
|
-
this.readlineInterface.close();
|
|
131
|
-
this.tsServerProcess.stdin?.destroy();
|
|
132
|
-
this.tsServerProcess.kill();
|
|
133
|
-
});
|
|
134
|
-
this.readlineInterface.on('line', (line) => this.processMessage(line));
|
|
97
|
+
async restart() {
|
|
98
|
+
this.kill();
|
|
99
|
+
await this.start();
|
|
100
|
+
}
|
|
135
101
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
102
|
+
start() {
|
|
103
|
+
return new Promise<void>((resolve, reject) => {
|
|
104
|
+
if (this.tsServerProcess) {
|
|
105
|
+
reject(new Error('server already started'));
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const { tsserverPath } = this.options;
|
|
110
|
+
const { logFile, logVerbosity, maxTsServerMemory, globalPlugins, pluginProbeLocations } = this.tsServerArgs;
|
|
111
|
+
const args: string[] = [];
|
|
112
|
+
if (logFile) {
|
|
113
|
+
args.push('--logFile', logFile);
|
|
114
|
+
}
|
|
115
|
+
if (logVerbosity) {
|
|
116
|
+
args.push('--logVerbosity', logVerbosity);
|
|
117
|
+
}
|
|
118
|
+
if (globalPlugins && globalPlugins.length) {
|
|
119
|
+
args.push('--globalPlugins', globalPlugins.join(','));
|
|
120
|
+
}
|
|
121
|
+
if (pluginProbeLocations && pluginProbeLocations.length) {
|
|
122
|
+
args.push('--pluginProbeLocations', pluginProbeLocations.join(','));
|
|
123
|
+
}
|
|
124
|
+
this.cancellationPipeName = tempy.file({ name: 'tscancellation' });
|
|
125
|
+
args.push('--cancellationPipeName', `${this.cancellationPipeName}*`);
|
|
126
|
+
this.logger.info(`Starting tsserver : '${tsserverPath} ${args.join(' ')}'`);
|
|
127
|
+
const tsserverPathIsModule = path.extname(tsserverPath) === '.js';
|
|
128
|
+
const options = {
|
|
129
|
+
silent: true,
|
|
130
|
+
execArgv: [...(maxTsServerMemory ? [`--max-old-space-size=${maxTsServerMemory}`] : [])],
|
|
131
|
+
};
|
|
132
|
+
this.tsServerProcess = tsserverPathIsModule ? cp.fork(tsserverPath, args, options) : cp.spawn(tsserverPath, args);
|
|
133
|
+
|
|
134
|
+
const timeout = setTimeout(() => {
|
|
135
|
+
reject(new Error(`TIMEOUT: TSServer did not start within the specified time ${this.TSSERVER_START_TIMEOUT}s`));
|
|
136
|
+
}, this.TSSERVER_START_TIMEOUT);
|
|
137
|
+
|
|
138
|
+
this.readlineInterface = readline.createInterface(
|
|
139
|
+
this.tsServerProcess.stdout as Readable,
|
|
140
|
+
this.tsServerProcess.stdin as Writable,
|
|
141
|
+
undefined
|
|
142
|
+
);
|
|
143
|
+
process.on('exit', () => {
|
|
144
|
+
this.kill();
|
|
145
|
+
reject(new Error('TSServer was killed'));
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
this.readlineInterface.on('line', (line) => {
|
|
149
|
+
clearTimeout(timeout);
|
|
150
|
+
this.processMessage(line, resolve, reject);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
const dec = new decoder.StringDecoder('utf-8');
|
|
154
|
+
this.tsServerProcess.stderr?.addListener('data', (data) => {
|
|
155
|
+
const stringMsg = typeof data === 'string' ? data : dec.write(data);
|
|
156
|
+
this.logger.error(stringMsg);
|
|
157
|
+
reject(new Error(stringMsg));
|
|
158
|
+
});
|
|
140
159
|
});
|
|
141
160
|
}
|
|
142
161
|
|
|
143
|
-
notify(command: CommandTypes.Open, args: protocol.OpenRequestArgs): void
|
|
144
|
-
notify(command: CommandTypes.Close, args: protocol.FileRequestArgs): void
|
|
145
|
-
notify(command: CommandTypes.Saveto, args: protocol.SavetoRequestArgs): void
|
|
146
|
-
notify(command: CommandTypes.Change, args: protocol.ChangeRequestArgs): void
|
|
147
|
-
notify(command: string, args: any): void {
|
|
162
|
+
async notify(command: CommandTypes.Open, args: protocol.OpenRequestArgs): Promise<void>;
|
|
163
|
+
async notify(command: CommandTypes.Close, args: protocol.FileRequestArgs): Promise<void>;
|
|
164
|
+
async notify(command: CommandTypes.Saveto, args: protocol.SavetoRequestArgs): Promise<void>;
|
|
165
|
+
async notify(command: CommandTypes.Change, args: protocol.ChangeRequestArgs): Promise<void>;
|
|
166
|
+
async notify(command: string, args: any): Promise<void> {
|
|
167
|
+
await this.ensureServerIsRunning();
|
|
148
168
|
this.sendMessage(command, true, args);
|
|
149
169
|
}
|
|
150
170
|
|
|
151
|
-
request<K extends keyof TypeScriptRequestTypes>(
|
|
171
|
+
async request<K extends keyof TypeScriptRequestTypes>(
|
|
152
172
|
command: K,
|
|
153
173
|
args: TypeScriptRequestTypes[K][0],
|
|
154
174
|
token?: CancellationToken
|
|
155
175
|
): Promise<TypeScriptRequestTypes[K][1]> {
|
|
176
|
+
await this.ensureServerIsRunning();
|
|
156
177
|
this.sendMessage(command, false, args);
|
|
157
178
|
const seq = this.seq;
|
|
158
179
|
const deferred = new Deferred<TypeScriptRequestTypes[K][1]>();
|
|
159
180
|
this.deferreds[seq] = deferred;
|
|
160
181
|
const request = deferred.promise;
|
|
182
|
+
|
|
183
|
+
let onCancelled;
|
|
161
184
|
if (token) {
|
|
162
|
-
|
|
185
|
+
onCancelled = token.onCancellationRequested(() => {
|
|
163
186
|
onCancelled.dispose();
|
|
164
187
|
if (this.cancellationPipeName) {
|
|
165
188
|
const requestCancellationPipeName = `${this.cancellationPipeName}${seq}`;
|
|
@@ -176,11 +199,23 @@ export class ProcessBasedTsServer {
|
|
|
176
199
|
}
|
|
177
200
|
});
|
|
178
201
|
}
|
|
179
|
-
|
|
202
|
+
|
|
203
|
+
try {
|
|
204
|
+
const result = await request;
|
|
205
|
+
onCancelled?.dispose();
|
|
206
|
+
return result;
|
|
207
|
+
} catch (error) {
|
|
208
|
+
this.logger.error(`Error in request: ${error}`);
|
|
209
|
+
throw error;
|
|
210
|
+
}
|
|
180
211
|
}
|
|
181
212
|
|
|
182
213
|
kill() {
|
|
183
|
-
this.tsServerProcess
|
|
214
|
+
this.tsServerProcess?.kill();
|
|
215
|
+
this.tsServerProcess?.stdin?.destroy();
|
|
216
|
+
this.readlineInterface?.close();
|
|
217
|
+
this.tsServerProcess = null;
|
|
218
|
+
this.readlineInterface = null;
|
|
184
219
|
}
|
|
185
220
|
|
|
186
221
|
private log(msg: string, obj: Record<string, any> = {}) {
|
|
@@ -203,17 +238,31 @@ export class ProcessBasedTsServer {
|
|
|
203
238
|
request.arguments = args;
|
|
204
239
|
}
|
|
205
240
|
const serializedRequest = `${JSON.stringify(request)}\n`;
|
|
206
|
-
this.tsServerProcess
|
|
241
|
+
this.tsServerProcess?.stdin?.write(serializedRequest);
|
|
207
242
|
this.log(notification ? 'notify' : 'request', request);
|
|
208
243
|
}
|
|
209
244
|
|
|
210
|
-
protected processMessage(untrimmedMessageString: string): void {
|
|
245
|
+
protected processMessage(untrimmedMessageString: string, resolve?: () => void, reject?: (err) => void): void {
|
|
211
246
|
const messageString = untrimmedMessageString.trim();
|
|
212
247
|
if (!messageString || messageString.startsWith('Content-Length:')) {
|
|
213
248
|
return;
|
|
214
249
|
}
|
|
215
|
-
|
|
250
|
+
let message: protocol.Message;
|
|
251
|
+
|
|
252
|
+
try {
|
|
253
|
+
message = JSON.parse(messageString);
|
|
254
|
+
} catch (error) {
|
|
255
|
+
// If the message isn't valid JSON, it's not a valid tsserver message. Reject the promise.
|
|
256
|
+
reject?.(new Error(`Received invalid message from TSServer: ${untrimmedMessageString}`));
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
|
|
216
260
|
this.log('processMessage', message);
|
|
261
|
+
|
|
262
|
+
if (this.isEvent(message)) {
|
|
263
|
+
resolve?.();
|
|
264
|
+
}
|
|
265
|
+
|
|
217
266
|
if (this.isResponse(message)) {
|
|
218
267
|
this.resolveResponse(message, message.request_seq, message.success);
|
|
219
268
|
} else if (this.isEvent(message)) {
|
|
@@ -249,4 +298,10 @@ export class ProcessBasedTsServer {
|
|
|
249
298
|
private isRequestCompletedEvent(message: protocol.Message): message is protocol.RequestCompletedEvent {
|
|
250
299
|
return this.isEvent(message) && message.event === 'requestCompleted';
|
|
251
300
|
}
|
|
301
|
+
|
|
302
|
+
private async ensureServerIsRunning() {
|
|
303
|
+
if (!this.tsServerProcess) {
|
|
304
|
+
await this.restart();
|
|
305
|
+
}
|
|
306
|
+
}
|
|
252
307
|
}
|
package/ts-server-client.ts
CHANGED
|
@@ -20,8 +20,10 @@ export type TsserverClientOpts = {
|
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
export class TsserverClient {
|
|
23
|
-
private tsServer: ProcessBasedTsServer;
|
|
23
|
+
private tsServer: ProcessBasedTsServer | null;
|
|
24
24
|
public lastDiagnostics: protocol.DiagnosticEventBody[] = [];
|
|
25
|
+
private serverRunning = false;
|
|
26
|
+
|
|
25
27
|
constructor(
|
|
26
28
|
/**
|
|
27
29
|
* absolute root path of the project.
|
|
@@ -41,19 +43,40 @@ export class TsserverClient {
|
|
|
41
43
|
* this methods returns pretty fast. if checkTypes is enabled, it runs the process in the background and
|
|
42
44
|
* doesn't wait for it.
|
|
43
45
|
*/
|
|
44
|
-
init() {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
this.
|
|
46
|
+
async init(): Promise<void> {
|
|
47
|
+
try {
|
|
48
|
+
this.tsServer = new ProcessBasedTsServer({
|
|
49
|
+
logger: this.logger,
|
|
50
|
+
tsserverPath: this.findTsserverPath(),
|
|
51
|
+
logToConsole: this.options.verbose,
|
|
52
|
+
onEvent: this.onTsserverEvent.bind(this),
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
this.tsServer
|
|
56
|
+
.start()
|
|
57
|
+
.then(() => {
|
|
58
|
+
this.serverRunning = true;
|
|
59
|
+
})
|
|
60
|
+
.catch((err) => {
|
|
61
|
+
this.logger.error('TsserverClient.init failed', err);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
if (this.files.length) {
|
|
65
|
+
const openPromises = this.files.map((file) => this.open(file));
|
|
66
|
+
await Promise.all(openPromises.map((promise) => promise.catch((error) => error)));
|
|
67
|
+
const failedFiles = openPromises.filter((promise) => promise instanceof Error);
|
|
68
|
+
if (failedFiles.length > 0) {
|
|
69
|
+
this.logger.error('TsserverClient.init failed to open files:', failedFiles);
|
|
70
|
+
}
|
|
71
|
+
if (failedFiles.length > 0) {
|
|
72
|
+
this.logger.error('TsserverClient.init failed to open files:', failedFiles);
|
|
73
|
+
}
|
|
74
|
+
this.checkTypesIfNeeded();
|
|
75
|
+
}
|
|
76
|
+
this.logger.debug('TsserverClient.init completed');
|
|
77
|
+
} catch (err) {
|
|
78
|
+
this.logger.error('TsserverClient.init failed', err);
|
|
54
79
|
}
|
|
55
|
-
this.checkTypesIfNeeded();
|
|
56
|
-
this.logger.debug('TsserverClient.init completed');
|
|
57
80
|
}
|
|
58
81
|
|
|
59
82
|
private checkTypesIfNeeded(files = this.files) {
|
|
@@ -93,7 +116,15 @@ export class TsserverClient {
|
|
|
93
116
|
}
|
|
94
117
|
|
|
95
118
|
killTsServer() {
|
|
96
|
-
this.tsServer.
|
|
119
|
+
if (this.tsServer && this.serverRunning) {
|
|
120
|
+
this.tsServer.kill();
|
|
121
|
+
this.tsServer = null;
|
|
122
|
+
this.serverRunning = false;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
isServerRunning() {
|
|
127
|
+
return this.serverRunning;
|
|
97
128
|
}
|
|
98
129
|
|
|
99
130
|
/**
|
|
@@ -108,14 +139,14 @@ export class TsserverClient {
|
|
|
108
139
|
*/
|
|
109
140
|
async getDiagnostic(files = this.files): Promise<any> {
|
|
110
141
|
this.lastDiagnostics = [];
|
|
111
|
-
return this.tsServer
|
|
142
|
+
return this.tsServer?.request(CommandTypes.Geterr, { delay: 0, files });
|
|
112
143
|
}
|
|
113
144
|
|
|
114
145
|
/**
|
|
115
146
|
* avoid using this method, it takes longer than `getDiagnostic()` and shows errors from paths outside the project
|
|
116
147
|
*/
|
|
117
148
|
async getDiagnosticAllProject(requestedByFile: string): Promise<any> {
|
|
118
|
-
return this.tsServer
|
|
149
|
+
return this.tsServer?.request(CommandTypes.GeterrForProject, { file: requestedByFile, delay: 0 });
|
|
119
150
|
}
|
|
120
151
|
|
|
121
152
|
/**
|
|
@@ -123,8 +154,8 @@ export class TsserverClient {
|
|
|
123
154
|
*/
|
|
124
155
|
async getQuickInfo(file: string, position: Position): Promise<protocol.QuickInfoResponse | undefined> {
|
|
125
156
|
const absFile = this.convertFileToAbsoluteIfNeeded(file);
|
|
126
|
-
this.openIfNeeded(absFile);
|
|
127
|
-
return this.tsServer
|
|
157
|
+
await this.openIfNeeded(absFile);
|
|
158
|
+
return this.tsServer?.request(CommandTypes.Quickinfo, {
|
|
128
159
|
file: absFile,
|
|
129
160
|
line: position.line,
|
|
130
161
|
offset: position.character,
|
|
@@ -136,8 +167,8 @@ export class TsserverClient {
|
|
|
136
167
|
*/
|
|
137
168
|
async getTypeDefinition(file: string, position: Position): Promise<protocol.TypeDefinitionResponse | undefined> {
|
|
138
169
|
const absFile = this.convertFileToAbsoluteIfNeeded(file);
|
|
139
|
-
this.openIfNeeded(absFile);
|
|
140
|
-
return this.tsServer
|
|
170
|
+
await this.openIfNeeded(absFile);
|
|
171
|
+
return this.tsServer?.request(CommandTypes.TypeDefinition, {
|
|
141
172
|
file: absFile,
|
|
142
173
|
line: position.line,
|
|
143
174
|
offset: position.character,
|
|
@@ -146,14 +177,14 @@ export class TsserverClient {
|
|
|
146
177
|
|
|
147
178
|
async getDefinition(file: string, position: Position) {
|
|
148
179
|
const absFile = this.convertFileToAbsoluteIfNeeded(file);
|
|
149
|
-
this.openIfNeeded(absFile);
|
|
150
|
-
const response = await this.tsServer
|
|
180
|
+
await this.openIfNeeded(absFile);
|
|
181
|
+
const response = await this.tsServer?.request(CommandTypes.Definition, {
|
|
151
182
|
file: absFile,
|
|
152
183
|
line: position.line,
|
|
153
184
|
offset: position.character,
|
|
154
185
|
});
|
|
155
186
|
|
|
156
|
-
if (!response
|
|
187
|
+
if (!response?.success) {
|
|
157
188
|
// TODO: we need a function to handle responses properly here for all.
|
|
158
189
|
return response;
|
|
159
190
|
}
|
|
@@ -166,8 +197,8 @@ export class TsserverClient {
|
|
|
166
197
|
*/
|
|
167
198
|
async getReferences(file: string, position: Position): Promise<protocol.ReferencesResponse | undefined> {
|
|
168
199
|
const absFile = this.convertFileToAbsoluteIfNeeded(file);
|
|
169
|
-
this.openIfNeeded(absFile);
|
|
170
|
-
return this.tsServer
|
|
200
|
+
await this.openIfNeeded(absFile);
|
|
201
|
+
return this.tsServer?.request(CommandTypes.References, {
|
|
171
202
|
file: absFile,
|
|
172
203
|
line: position.line,
|
|
173
204
|
offset: position.character,
|
|
@@ -179,9 +210,9 @@ export class TsserverClient {
|
|
|
179
210
|
*/
|
|
180
211
|
async getSignatureHelp(file: string, position: Position): Promise<protocol.SignatureHelpResponse | undefined> {
|
|
181
212
|
const absFile = this.convertFileToAbsoluteIfNeeded(file);
|
|
182
|
-
this.openIfNeeded(absFile);
|
|
213
|
+
await this.openIfNeeded(absFile);
|
|
183
214
|
|
|
184
|
-
return this.tsServer
|
|
215
|
+
return this.tsServer?.request(CommandTypes.SignatureHelp, {
|
|
185
216
|
file: absFile,
|
|
186
217
|
line: position.line,
|
|
187
218
|
offset: position.character,
|
|
@@ -191,30 +222,30 @@ export class TsserverClient {
|
|
|
191
222
|
private async configure(
|
|
192
223
|
configureArgs: protocol.ConfigureRequestArguments = {}
|
|
193
224
|
): Promise<protocol.ConfigureResponse | undefined> {
|
|
194
|
-
return this.tsServer
|
|
225
|
+
return this.tsServer?.request(CommandTypes.Configure, configureArgs);
|
|
195
226
|
}
|
|
196
227
|
|
|
197
228
|
/**
|
|
198
229
|
* ask tsserver to open a file if it was not opened before.
|
|
199
230
|
* @param file absolute path of the file
|
|
200
231
|
*/
|
|
201
|
-
openIfNeeded(file: string) {
|
|
232
|
+
async openIfNeeded(file: string) {
|
|
202
233
|
if (this.files.includes(file)) {
|
|
203
234
|
return;
|
|
204
235
|
}
|
|
205
|
-
this.open(file);
|
|
236
|
+
await this.open(file);
|
|
206
237
|
this.files.push(file);
|
|
207
238
|
}
|
|
208
239
|
|
|
209
|
-
private open(file: string) {
|
|
210
|
-
this.tsServer
|
|
240
|
+
private async open(file: string) {
|
|
241
|
+
return this.tsServer?.notify(CommandTypes.Open, {
|
|
211
242
|
file,
|
|
212
243
|
projectRootPath: this.projectPath,
|
|
213
244
|
});
|
|
214
245
|
}
|
|
215
246
|
|
|
216
|
-
close(file: string) {
|
|
217
|
-
this.tsServer
|
|
247
|
+
async close(file: string) {
|
|
248
|
+
await this.tsServer?.notify(CommandTypes.Close, {
|
|
218
249
|
file,
|
|
219
250
|
});
|
|
220
251
|
this.files = this.files.filter((openFile) => openFile !== file);
|
|
@@ -228,7 +259,7 @@ export class TsserverClient {
|
|
|
228
259
|
*/
|
|
229
260
|
async changed(file: string) {
|
|
230
261
|
// tell tsserver that all content was removed
|
|
231
|
-
this.tsServer
|
|
262
|
+
await this.tsServer?.notify(CommandTypes.Change, {
|
|
232
263
|
file,
|
|
233
264
|
line: 1,
|
|
234
265
|
offset: 1,
|
|
@@ -240,7 +271,7 @@ export class TsserverClient {
|
|
|
240
271
|
const content = await fs.readFile(file, 'utf-8');
|
|
241
272
|
|
|
242
273
|
// tell tsserver that all file content was added
|
|
243
|
-
this.tsServer
|
|
274
|
+
await this.tsServer?.notify(CommandTypes.Change, {
|
|
244
275
|
file,
|
|
245
276
|
line: 1,
|
|
246
277
|
offset: 1,
|
|
Binary file
|
|
File without changes
|