@teambit/ts-server 0.0.78 → 0.0.79
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/ts-server-client.d.ts +18 -1
- package/dist/ts-server-client.js +55 -16
- package/dist/ts-server-client.js.map +1 -1
- package/package.json +2 -2
- package/ts-server-client.ts +57 -12
|
@@ -9,6 +9,12 @@ export type TsserverClientOpts = {
|
|
|
9
9
|
checkTypes?: CheckTypes;
|
|
10
10
|
printTypeErrors?: boolean;
|
|
11
11
|
aggregateDiagnosticData?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* if false, files passed to the constructor are NOT opened during init().
|
|
14
|
+
* useful when the caller wants to control opening (e.g. batched open/close in `getDiagnostic`).
|
|
15
|
+
* default: true (backward compatible).
|
|
16
|
+
*/
|
|
17
|
+
openFilesOnInit?: boolean;
|
|
12
18
|
};
|
|
13
19
|
export type DiagnosticData = {
|
|
14
20
|
file: string;
|
|
@@ -30,6 +36,7 @@ export declare class TsserverClient {
|
|
|
30
36
|
private tsServer;
|
|
31
37
|
lastDiagnostics: ts.server.protocol.DiagnosticEventBody[];
|
|
32
38
|
private serverRunning;
|
|
39
|
+
private filesPreOpenedOnInit;
|
|
33
40
|
diagnosticData: DiagnosticData[];
|
|
34
41
|
constructor(
|
|
35
42
|
/**
|
|
@@ -66,9 +73,19 @@ export declare class TsserverClient {
|
|
|
66
73
|
* were found or not.
|
|
67
74
|
*
|
|
68
75
|
* @param files files to check
|
|
69
|
-
* @param batchSize if provided, files will be processed in batches
|
|
76
|
+
* @param batchSize if provided, files will be processed in batches. when files were not pre-opened
|
|
77
|
+
* via init(), each batch is opened, checked, then closed — keeping tsserver memory
|
|
78
|
+
* bounded by the batch size to avoid OOM in large workspaces.
|
|
70
79
|
*/
|
|
71
80
|
getDiagnostic(files?: string[], batchSize?: number): Promise<any>;
|
|
81
|
+
/**
|
|
82
|
+
* open multiple files in a single round-trip. useful when batching to bound tsserver memory.
|
|
83
|
+
*/
|
|
84
|
+
openFiles(files: string[]): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* close multiple files in a single round-trip.
|
|
87
|
+
*/
|
|
88
|
+
closeFiles(files: string[]): Promise<void>;
|
|
72
89
|
/**
|
|
73
90
|
* avoid using this method, it takes longer than `getDiagnostic()` and shows errors from paths outside the project
|
|
74
91
|
*/
|
package/dist/ts-server-client.js
CHANGED
|
@@ -71,6 +71,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
71
71
|
class TsserverClient {
|
|
72
72
|
lastDiagnostics = [];
|
|
73
73
|
serverRunning = false;
|
|
74
|
+
filesPreOpenedOnInit = false;
|
|
74
75
|
diagnosticData = [];
|
|
75
76
|
constructor(
|
|
76
77
|
/**
|
|
@@ -106,16 +107,14 @@ class TsserverClient {
|
|
|
106
107
|
}).catch(err => {
|
|
107
108
|
this.logger.error('TsserverClient.init failed', err);
|
|
108
109
|
});
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
await Promise.all(
|
|
112
|
-
const failedFiles =
|
|
113
|
-
if (failedFiles.length > 0) {
|
|
114
|
-
this.logger.error('TsserverClient.init failed to open files:', failedFiles);
|
|
115
|
-
}
|
|
110
|
+
const shouldOpenFiles = this.options.openFilesOnInit !== false;
|
|
111
|
+
if (this.files.length && shouldOpenFiles) {
|
|
112
|
+
const openResults = await Promise.all(this.files.map(file => this.open(file).catch(error => error)));
|
|
113
|
+
const failedFiles = openResults.filter(result => result instanceof Error);
|
|
116
114
|
if (failedFiles.length > 0) {
|
|
117
115
|
this.logger.error('TsserverClient.init failed to open files:', failedFiles);
|
|
118
116
|
}
|
|
117
|
+
this.filesPreOpenedOnInit = true;
|
|
119
118
|
this.checkTypesIfNeeded();
|
|
120
119
|
}
|
|
121
120
|
this.logger.debug('TsserverClient.init completed');
|
|
@@ -177,7 +176,9 @@ class TsserverClient {
|
|
|
177
176
|
* were found or not.
|
|
178
177
|
*
|
|
179
178
|
* @param files files to check
|
|
180
|
-
* @param batchSize if provided, files will be processed in batches
|
|
179
|
+
* @param batchSize if provided, files will be processed in batches. when files were not pre-opened
|
|
180
|
+
* via init(), each batch is opened, checked, then closed — keeping tsserver memory
|
|
181
|
+
* bounded by the batch size to avoid OOM in large workspaces.
|
|
181
182
|
*/
|
|
182
183
|
async getDiagnostic(files = this.files, batchSize) {
|
|
183
184
|
this.lastDiagnostics = [];
|
|
@@ -187,17 +188,55 @@ class TsserverClient {
|
|
|
187
188
|
files
|
|
188
189
|
});
|
|
189
190
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
files
|
|
197
|
-
|
|
191
|
+
const filesArePreOpened = this.filesPreOpenedOnInit && files.every(f => this.files.includes(f));
|
|
192
|
+
const total = files.length;
|
|
193
|
+
try {
|
|
194
|
+
for (let i = 0; i < files.length; i += batchSize) {
|
|
195
|
+
const batch = files.slice(i, i + batchSize);
|
|
196
|
+
const upTo = Math.min(i + batchSize, total);
|
|
197
|
+
this.logger.setStatusLine(`type-checking files ${i + 1}-${upTo} of ${total}`);
|
|
198
|
+
if (!filesArePreOpened) {
|
|
199
|
+
await this.openFiles(batch);
|
|
200
|
+
}
|
|
201
|
+
try {
|
|
202
|
+
await this.tsServer?.request(_tspCommandTypes().CommandTypes.Geterr, {
|
|
203
|
+
delay: 0,
|
|
204
|
+
files: batch
|
|
205
|
+
});
|
|
206
|
+
} finally {
|
|
207
|
+
if (!filesArePreOpened) {
|
|
208
|
+
await this.closeFiles(batch).catch(err => this.logger.error('failed to close batch', err));
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
} finally {
|
|
213
|
+
this.logger.clearStatusLine();
|
|
198
214
|
}
|
|
199
215
|
}
|
|
200
216
|
|
|
217
|
+
/**
|
|
218
|
+
* open multiple files in a single round-trip. useful when batching to bound tsserver memory.
|
|
219
|
+
*/
|
|
220
|
+
async openFiles(files) {
|
|
221
|
+
if (!files.length) return;
|
|
222
|
+
await this.tsServer?.request(_tspCommandTypes().CommandTypes.UpdateOpen, {
|
|
223
|
+
openFiles: files.map(file => ({
|
|
224
|
+
file,
|
|
225
|
+
projectRootPath: this.projectPath
|
|
226
|
+
}))
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* close multiple files in a single round-trip.
|
|
232
|
+
*/
|
|
233
|
+
async closeFiles(files) {
|
|
234
|
+
if (!files.length) return;
|
|
235
|
+
await this.tsServer?.request(_tspCommandTypes().CommandTypes.UpdateOpen, {
|
|
236
|
+
closedFiles: files
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
|
|
201
240
|
/**
|
|
202
241
|
* avoid using this method, it takes longer than `getDiagnostic()` and shows errors from paths outside the project
|
|
203
242
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_fsExtra","data","_interopRequireDefault","require","_path","_watcher","_commandExists","_modulesResolver","_processBasedTsserver","_tspCommandTypes","_utils","_formatDiagnostics","e","__esModule","default","TsserverClient","lastDiagnostics","serverRunning","diagnosticData","constructor","projectPath","logger","options","files","init","tsServer","ProcessBasedTsServer","tsserverPath","findTsserverPath","logToConsole","verbose","onEvent","onTsserverEvent","bind","start","then","catch","err","error","length","openPromises","map","file","open","Promise","all","promise","failedFiles","filter","Error","checkTypesIfNeeded","debug","shouldCheckTypes","Date","now","getDiagnostic","end","msg","consoleFailure","consoleSuccess","console","Boolean","checkTypes","onFileChange","changed","CheckTypes","ChangedFile","undefined","killTsServer","kill","isServerRunning","batchSize","request","CommandTypes","Geterr","delay","i","batch","slice","getDiagnosticAllProject","requestedByFile","GeterrForProject","getQuickInfo","position","absFile","convertFileToAbsoluteIfNeeded","openIfNeeded","Quickinfo","line","offset","character","getTypeDefinition","TypeDefinition","getDefinition","response","Definition","success","warn","getReferences","References","getSignatureHelp","SignatureHelp","configure","configureArgs","Configure","includes","push","notify","Open","projectRootPath","close","Close","openFile","Change","endLine","endOffset","insertString","content","fs","readFile","event","EventName","semanticDiag","syntaxDiag","publishDiagnostic","filepath","path","isAbsolute","join","message","body","diagnostics","printTypeErrors","aggregateDiagnosticData","relative","forEach","diag","formatted","formatDiagnostic","diagnostic","tsServerPath","bundled","findPathToModule","__dirname","commandExists","sync","getTsserverExecutable","exports"],"sources":["ts-server-client.ts"],"sourcesContent":["import fs from 'fs-extra';\nimport type { Logger } from '@teambit/logger';\nimport path from 'path';\nimport type ts from 'typescript/lib/tsserverlibrary';\nimport { CheckTypes } from '@teambit/watcher';\nimport type { Position } from 'vscode-languageserver-types';\nimport commandExists from 'command-exists';\nimport { findPathToModule } from './modules-resolver';\nimport { ProcessBasedTsServer } from './process-based-tsserver';\nimport { CommandTypes, EventName } from './tsp-command-types';\nimport { getTsserverExecutable } from './utils';\nimport type { Diagnostic } from './format-diagnostics';\nimport { formatDiagnostic } from './format-diagnostics';\n\nexport type TsserverClientOpts = {\n verbose?: boolean; // print tsserver events to the console.\n tsServerPath?: string; // if not provided, it'll use findTsserverPath() strategies.\n checkTypes?: CheckTypes; // whether errors/warnings are monitored and printed to the console.\n printTypeErrors?: boolean; // whether print typescript errors to the console.\n aggregateDiagnosticData?: boolean; // whether to aggregate diagnostic data instead of printing them to the console.\n};\n\nexport type DiagnosticData = {\n file: string;\n diagnostic: Diagnostic;\n formatted: string;\n};\n\nexport class TsserverClient {\n private tsServer: ProcessBasedTsServer | null;\n public lastDiagnostics: ts.server.protocol.DiagnosticEventBody[] = [];\n private serverRunning = false;\n public diagnosticData: DiagnosticData[] = [];\n constructor(\n /**\n * absolute root path of the project.\n */\n private projectPath: string,\n private logger: Logger,\n private options: TsserverClientOpts = {},\n /**\n * provide files if you want to check types on init. (options.checkTypes should be enabled).\n * paths should be absolute.\n */\n private files: string[] = []\n ) {}\n\n /**\n * start the ts-server and keep its process alive.\n * this methods returns pretty fast. if checkTypes is enabled, it runs the process in the background and\n * doesn't wait for it.\n */\n async init(): Promise<void> {\n try {\n this.tsServer = new ProcessBasedTsServer({\n logger: this.logger,\n tsserverPath: this.findTsserverPath(),\n logToConsole: this.options.verbose,\n onEvent: this.onTsserverEvent.bind(this),\n });\n\n this.tsServer\n .start()\n .then(() => {\n this.serverRunning = true;\n })\n .catch((err) => {\n this.logger.error('TsserverClient.init failed', err);\n });\n\n if (this.files.length) {\n const openPromises = this.files.map((file) => this.open(file));\n await Promise.all(openPromises.map((promise) => promise.catch((error) => error)));\n const failedFiles = openPromises.filter((promise) => promise instanceof Error);\n if (failedFiles.length > 0) {\n this.logger.error('TsserverClient.init failed to open files:', failedFiles);\n }\n if (failedFiles.length > 0) {\n this.logger.error('TsserverClient.init failed to open files:', failedFiles);\n }\n this.checkTypesIfNeeded();\n }\n this.logger.debug('TsserverClient.init completed');\n } catch (err) {\n this.logger.error('TsserverClient.init failed', err);\n }\n }\n\n private checkTypesIfNeeded(files = this.files) {\n if (!this.shouldCheckTypes()) {\n return;\n }\n const start = Date.now();\n this.getDiagnostic(files)\n .then(() => {\n const end = Date.now() - start;\n const msg = `completed type checking (${end / 1000} sec)`;\n if (this.lastDiagnostics.length) {\n this.logger.consoleFailure(`${msg}. found errors in ${this.lastDiagnostics.length} files.`);\n } else {\n this.logger.consoleSuccess(`${msg}. no errors were found.`);\n }\n })\n .catch((err) => {\n const msg = `failed getting the type errors from ts-server`;\n this.logger.console(msg);\n this.logger.error(msg, err);\n });\n }\n\n private shouldCheckTypes() {\n // this also covers this.options.checkTypes !== CheckTypes.None.\n return Boolean(this.options.checkTypes);\n }\n\n /**\n * if `bit watch` or `bit start` are running in the background, this method is triggered.\n */\n async onFileChange(file: string) {\n await this.changed(file);\n const files = this.options.checkTypes === CheckTypes.ChangedFile ? [file] : undefined;\n this.checkTypesIfNeeded(files);\n }\n\n killTsServer() {\n if (this.tsServer && this.serverRunning) {\n this.tsServer.kill();\n this.tsServer = null;\n this.serverRunning = false;\n }\n }\n\n isServerRunning() {\n return this.serverRunning;\n }\n\n /**\n * get diagnostic of all files opened in the project.\n * there is little to no value of getting diagnostic for a specific file, as\n * changing a type in one file may cause errors in different files.\n *\n * the errors/diagnostic info are sent as events, see this.onTsserverEvent() for more info.\n *\n * the return value here just shows whether the request was succeeded, it doesn't have any info about whether errors\n * were found or not.\n *\n * @param files files to check\n * @param batchSize if provided, files will be processed in batches to avoid overwhelming tsserver\n */\n async getDiagnostic(files = this.files, batchSize?: number): Promise<any> {\n this.lastDiagnostics = [];\n\n if (!batchSize || files.length <= batchSize) {\n return this.tsServer?.request(CommandTypes.Geterr, { delay: 0, files });\n }\n\n // Process files in batches\n for (let i = 0; i < files.length; i += batchSize) {\n const batch = files.slice(i, i + batchSize);\n await this.tsServer?.request(CommandTypes.Geterr, { delay: 0, files: batch });\n }\n }\n\n /**\n * avoid using this method, it takes longer than `getDiagnostic()` and shows errors from paths outside the project\n */\n async getDiagnosticAllProject(requestedByFile: string): Promise<any> {\n return this.tsServer?.request(CommandTypes.GeterrForProject, { file: requestedByFile, delay: 0 });\n }\n\n /**\n * @param file can be absolute or relative to this.projectRoot.\n */\n async getQuickInfo(file: string, position: Position): Promise<ts.server.protocol.QuickInfoResponse | undefined> {\n const absFile = this.convertFileToAbsoluteIfNeeded(file);\n await this.openIfNeeded(absFile);\n return this.tsServer?.request(CommandTypes.Quickinfo, {\n file: absFile,\n line: position.line,\n offset: position.character,\n });\n }\n\n /**\n * @param file can be absolute or relative to this.projectRoot.\n */\n async getTypeDefinition(\n file: string,\n position: Position\n ): Promise<ts.server.protocol.TypeDefinitionResponse | undefined> {\n const absFile = this.convertFileToAbsoluteIfNeeded(file);\n await this.openIfNeeded(absFile);\n return this.tsServer?.request(CommandTypes.TypeDefinition, {\n file: absFile,\n line: position.line,\n offset: position.character,\n });\n }\n\n async getDefinition(file: string, position: Position) {\n const absFile = this.convertFileToAbsoluteIfNeeded(file);\n await this.openIfNeeded(absFile);\n const response = await this.tsServer?.request(CommandTypes.Definition, {\n file: absFile,\n line: position.line,\n offset: position.character,\n });\n\n if (!response?.success) {\n // TODO: we need a function to handle responses properly here for all.\n this.logger.warn(`For file ${absFile} tsserver failed to request definition info`);\n return response;\n }\n\n return response;\n }\n\n /**\n * @param file can be absolute or relative to this.projectRoot.\n */\n async getReferences(file: string, position: Position): Promise<ts.server.protocol.ReferencesResponse | undefined> {\n const absFile = this.convertFileToAbsoluteIfNeeded(file);\n await this.openIfNeeded(absFile);\n return this.tsServer?.request(CommandTypes.References, {\n file: absFile,\n line: position.line,\n offset: position.character,\n });\n }\n\n /**\n * @param file can be absolute or relative to this.projectRoot.\n */\n async getSignatureHelp(\n file: string,\n position: Position\n ): Promise<ts.server.protocol.SignatureHelpResponse | undefined> {\n const absFile = this.convertFileToAbsoluteIfNeeded(file);\n await this.openIfNeeded(absFile);\n\n return this.tsServer?.request(CommandTypes.SignatureHelp, {\n file: absFile,\n line: position.line,\n offset: position.character,\n });\n }\n\n private async configure(\n configureArgs: ts.server.protocol.ConfigureRequestArguments = {}\n ): Promise<ts.server.protocol.ConfigureResponse | undefined> {\n return this.tsServer?.request(CommandTypes.Configure, configureArgs);\n }\n\n /**\n * ask tsserver to open a file if it was not opened before.\n * @param file absolute path of the file\n */\n async openIfNeeded(file: string) {\n if (this.files.includes(file)) {\n return;\n }\n await this.open(file);\n this.files.push(file);\n }\n\n private async open(file: string) {\n return this.tsServer?.notify(CommandTypes.Open, {\n file,\n projectRootPath: this.projectPath,\n });\n }\n\n async close(file: string) {\n await this.tsServer?.notify(CommandTypes.Close, {\n file,\n });\n this.files = this.files.filter((openFile) => openFile !== file);\n }\n\n /**\n * since Bit is not an IDE, it doesn't have the information such as the exact line/offset of the changes.\n * as a workaround, to tell tsserver what was changed, we pretend that the entire file was cleared and new text was\n * added. this is the only way I could find to tell tsserver about the change. otherwise, tsserver keep assuming that\n * the file content remained the same. (closing/re-opening the file doesn't help).\n */\n async changed(file: string) {\n // tell tsserver that all content was removed\n await this.tsServer?.notify(CommandTypes.Change, {\n file,\n line: 1,\n offset: 1,\n endLine: 99999,\n endOffset: 1,\n insertString: '',\n });\n\n const content = await fs.readFile(file, 'utf-8');\n\n // tell tsserver that all file content was added\n await this.tsServer?.notify(CommandTypes.Change, {\n file,\n line: 1,\n offset: 1,\n endLine: 1,\n endOffset: 1,\n insertString: content,\n });\n }\n\n protected onTsserverEvent(event: ts.server.protocol.Event): void {\n switch (event.event) {\n case EventName.semanticDiag:\n case EventName.syntaxDiag:\n this.publishDiagnostic(event as ts.server.protocol.DiagnosticEvent);\n break;\n default:\n this.logger.debug(`ignored TsServer event: ${event.event}`);\n }\n }\n\n private convertFileToAbsoluteIfNeeded(filepath: string): string {\n if (path.isAbsolute(filepath)) {\n return filepath;\n }\n return path.join(this.projectPath, filepath);\n }\n\n private publishDiagnostic(message: ts.server.protocol.DiagnosticEvent) {\n if (!message.body?.diagnostics.length || (!this.options.printTypeErrors && !this.options.aggregateDiagnosticData)) {\n return;\n }\n this.lastDiagnostics.push(message.body);\n const file = path.relative(this.projectPath, message.body.file);\n message.body.diagnostics.forEach((diag) => {\n const formatted = formatDiagnostic(diag, file);\n if (this.options.printTypeErrors) {\n this.logger.console(formatted);\n }\n if (this.options.aggregateDiagnosticData) {\n this.diagnosticData.push({\n file,\n diagnostic: diag,\n formatted,\n });\n }\n });\n }\n\n /**\n * copied over from https://github.com/typescript-language-server/typescript-language-server/blob/master/src/lsp-server.ts\n */\n private findTsserverPath(): string {\n if (this.options.tsServerPath) {\n return this.options.tsServerPath;\n }\n\n const tsServerPath = path.join('typescript', 'lib', 'tsserver.js');\n\n /**\n * (1) find it in the bit directory\n */\n const bundled = findPathToModule(__dirname, tsServerPath);\n\n if (bundled) {\n return bundled;\n }\n\n // (2) use globally installed tsserver\n if (commandExists.sync(getTsserverExecutable())) {\n return getTsserverExecutable();\n }\n\n throw new Error(`Couldn't find '${getTsserverExecutable()}' executable or 'tsserver.js' module`);\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CA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;IACA,IAAIG,wBAAa,CAACC,IAAI,CAAC,IAAAC,8BAAqB,EAAC,CAAC,CAAC,EAAE;MAC/C,OAAO,IAAAA,8BAAqB,EAAC,CAAC;IAChC;IAEA,MAAM,IAAIjG,KAAK,CAAC,kBAAkB,IAAAiG,8BAAqB,EAAC,CAAC,sCAAsC,CAAC;EAClG;AACF;AAACC,OAAA,CAAApI,cAAA,GAAAA,cAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_fsExtra","data","_interopRequireDefault","require","_path","_watcher","_commandExists","_modulesResolver","_processBasedTsserver","_tspCommandTypes","_utils","_formatDiagnostics","e","__esModule","default","TsserverClient","lastDiagnostics","serverRunning","filesPreOpenedOnInit","diagnosticData","constructor","projectPath","logger","options","files","init","tsServer","ProcessBasedTsServer","tsserverPath","findTsserverPath","logToConsole","verbose","onEvent","onTsserverEvent","bind","start","then","catch","err","error","shouldOpenFiles","openFilesOnInit","length","openResults","Promise","all","map","file","open","failedFiles","filter","result","Error","checkTypesIfNeeded","debug","shouldCheckTypes","Date","now","getDiagnostic","end","msg","consoleFailure","consoleSuccess","console","Boolean","checkTypes","onFileChange","changed","CheckTypes","ChangedFile","undefined","killTsServer","kill","isServerRunning","batchSize","request","CommandTypes","Geterr","delay","filesArePreOpened","every","f","includes","total","i","batch","slice","upTo","Math","min","setStatusLine","openFiles","closeFiles","clearStatusLine","UpdateOpen","projectRootPath","closedFiles","getDiagnosticAllProject","requestedByFile","GeterrForProject","getQuickInfo","position","absFile","convertFileToAbsoluteIfNeeded","openIfNeeded","Quickinfo","line","offset","character","getTypeDefinition","TypeDefinition","getDefinition","response","Definition","success","warn","getReferences","References","getSignatureHelp","SignatureHelp","configure","configureArgs","Configure","push","notify","Open","close","Close","openFile","Change","endLine","endOffset","insertString","content","fs","readFile","event","EventName","semanticDiag","syntaxDiag","publishDiagnostic","filepath","path","isAbsolute","join","message","body","diagnostics","printTypeErrors","aggregateDiagnosticData","relative","forEach","diag","formatted","formatDiagnostic","diagnostic","tsServerPath","bundled","findPathToModule","__dirname","commandExists","sync","getTsserverExecutable","exports"],"sources":["ts-server-client.ts"],"sourcesContent":["import fs from 'fs-extra';\nimport type { Logger } from '@teambit/logger';\nimport path from 'path';\nimport type ts from 'typescript/lib/tsserverlibrary';\nimport { CheckTypes } from '@teambit/watcher';\nimport type { Position } from 'vscode-languageserver-types';\nimport commandExists from 'command-exists';\nimport { findPathToModule } from './modules-resolver';\nimport { ProcessBasedTsServer } from './process-based-tsserver';\nimport { CommandTypes, EventName } from './tsp-command-types';\nimport { getTsserverExecutable } from './utils';\nimport type { Diagnostic } from './format-diagnostics';\nimport { formatDiagnostic } from './format-diagnostics';\n\nexport type TsserverClientOpts = {\n verbose?: boolean; // print tsserver events to the console.\n tsServerPath?: string; // if not provided, it'll use findTsserverPath() strategies.\n checkTypes?: CheckTypes; // whether errors/warnings are monitored and printed to the console.\n printTypeErrors?: boolean; // whether print typescript errors to the console.\n aggregateDiagnosticData?: boolean; // whether to aggregate diagnostic data instead of printing them to the console.\n /**\n * if false, files passed to the constructor are NOT opened during init().\n * useful when the caller wants to control opening (e.g. batched open/close in `getDiagnostic`).\n * default: true (backward compatible).\n */\n openFilesOnInit?: boolean;\n};\n\nexport type DiagnosticData = {\n file: string;\n diagnostic: Diagnostic;\n formatted: string;\n};\n\nexport class TsserverClient {\n private tsServer: ProcessBasedTsServer | null;\n public lastDiagnostics: ts.server.protocol.DiagnosticEventBody[] = [];\n private serverRunning = false;\n private filesPreOpenedOnInit = false;\n public diagnosticData: DiagnosticData[] = [];\n constructor(\n /**\n * absolute root path of the project.\n */\n private projectPath: string,\n private logger: Logger,\n private options: TsserverClientOpts = {},\n /**\n * provide files if you want to check types on init. (options.checkTypes should be enabled).\n * paths should be absolute.\n */\n private files: string[] = []\n ) {}\n\n /**\n * start the ts-server and keep its process alive.\n * this methods returns pretty fast. if checkTypes is enabled, it runs the process in the background and\n * doesn't wait for it.\n */\n async init(): Promise<void> {\n try {\n this.tsServer = new ProcessBasedTsServer({\n logger: this.logger,\n tsserverPath: this.findTsserverPath(),\n logToConsole: this.options.verbose,\n onEvent: this.onTsserverEvent.bind(this),\n });\n\n this.tsServer\n .start()\n .then(() => {\n this.serverRunning = true;\n })\n .catch((err) => {\n this.logger.error('TsserverClient.init failed', err);\n });\n\n const shouldOpenFiles = this.options.openFilesOnInit !== false;\n if (this.files.length && shouldOpenFiles) {\n const openResults = await Promise.all(\n this.files.map((file) => this.open(file).catch((error: unknown) => error))\n );\n const failedFiles = openResults.filter((result) => result instanceof Error);\n if (failedFiles.length > 0) {\n this.logger.error('TsserverClient.init failed to open files:', failedFiles);\n }\n this.filesPreOpenedOnInit = true;\n this.checkTypesIfNeeded();\n }\n this.logger.debug('TsserverClient.init completed');\n } catch (err) {\n this.logger.error('TsserverClient.init failed', err);\n }\n }\n\n private checkTypesIfNeeded(files = this.files) {\n if (!this.shouldCheckTypes()) {\n return;\n }\n const start = Date.now();\n this.getDiagnostic(files)\n .then(() => {\n const end = Date.now() - start;\n const msg = `completed type checking (${end / 1000} sec)`;\n if (this.lastDiagnostics.length) {\n this.logger.consoleFailure(`${msg}. found errors in ${this.lastDiagnostics.length} files.`);\n } else {\n this.logger.consoleSuccess(`${msg}. no errors were found.`);\n }\n })\n .catch((err) => {\n const msg = `failed getting the type errors from ts-server`;\n this.logger.console(msg);\n this.logger.error(msg, err);\n });\n }\n\n private shouldCheckTypes() {\n // this also covers this.options.checkTypes !== CheckTypes.None.\n return Boolean(this.options.checkTypes);\n }\n\n /**\n * if `bit watch` or `bit start` are running in the background, this method is triggered.\n */\n async onFileChange(file: string) {\n await this.changed(file);\n const files = this.options.checkTypes === CheckTypes.ChangedFile ? [file] : undefined;\n this.checkTypesIfNeeded(files);\n }\n\n killTsServer() {\n if (this.tsServer && this.serverRunning) {\n this.tsServer.kill();\n this.tsServer = null;\n this.serverRunning = false;\n }\n }\n\n isServerRunning() {\n return this.serverRunning;\n }\n\n /**\n * get diagnostic of all files opened in the project.\n * there is little to no value of getting diagnostic for a specific file, as\n * changing a type in one file may cause errors in different files.\n *\n * the errors/diagnostic info are sent as events, see this.onTsserverEvent() for more info.\n *\n * the return value here just shows whether the request was succeeded, it doesn't have any info about whether errors\n * were found or not.\n *\n * @param files files to check\n * @param batchSize if provided, files will be processed in batches. when files were not pre-opened\n * via init(), each batch is opened, checked, then closed — keeping tsserver memory\n * bounded by the batch size to avoid OOM in large workspaces.\n */\n async getDiagnostic(files = this.files, batchSize?: number): Promise<any> {\n this.lastDiagnostics = [];\n\n if (!batchSize || files.length <= batchSize) {\n return this.tsServer?.request(CommandTypes.Geterr, { delay: 0, files });\n }\n\n const filesArePreOpened = this.filesPreOpenedOnInit && files.every((f) => this.files.includes(f));\n const total = files.length;\n try {\n for (let i = 0; i < files.length; i += batchSize) {\n const batch = files.slice(i, i + batchSize);\n const upTo = Math.min(i + batchSize, total);\n this.logger.setStatusLine(`type-checking files ${i + 1}-${upTo} of ${total}`);\n if (!filesArePreOpened) {\n await this.openFiles(batch);\n }\n try {\n await this.tsServer?.request(CommandTypes.Geterr, { delay: 0, files: batch });\n } finally {\n if (!filesArePreOpened) {\n await this.closeFiles(batch).catch((err) => this.logger.error('failed to close batch', err));\n }\n }\n }\n } finally {\n this.logger.clearStatusLine();\n }\n }\n\n /**\n * open multiple files in a single round-trip. useful when batching to bound tsserver memory.\n */\n async openFiles(files: string[]): Promise<void> {\n if (!files.length) return;\n await this.tsServer?.request(CommandTypes.UpdateOpen, {\n openFiles: files.map((file) => ({ file, projectRootPath: this.projectPath })),\n });\n }\n\n /**\n * close multiple files in a single round-trip.\n */\n async closeFiles(files: string[]): Promise<void> {\n if (!files.length) return;\n await this.tsServer?.request(CommandTypes.UpdateOpen, {\n closedFiles: files,\n });\n }\n\n /**\n * avoid using this method, it takes longer than `getDiagnostic()` and shows errors from paths outside the project\n */\n async getDiagnosticAllProject(requestedByFile: string): Promise<any> {\n return this.tsServer?.request(CommandTypes.GeterrForProject, { file: requestedByFile, delay: 0 });\n }\n\n /**\n * @param file can be absolute or relative to this.projectRoot.\n */\n async getQuickInfo(file: string, position: Position): Promise<ts.server.protocol.QuickInfoResponse | undefined> {\n const absFile = this.convertFileToAbsoluteIfNeeded(file);\n await this.openIfNeeded(absFile);\n return this.tsServer?.request(CommandTypes.Quickinfo, {\n file: absFile,\n line: position.line,\n offset: position.character,\n });\n }\n\n /**\n * @param file can be absolute or relative to this.projectRoot.\n */\n async getTypeDefinition(\n file: string,\n position: Position\n ): Promise<ts.server.protocol.TypeDefinitionResponse | undefined> {\n const absFile = this.convertFileToAbsoluteIfNeeded(file);\n await this.openIfNeeded(absFile);\n return this.tsServer?.request(CommandTypes.TypeDefinition, {\n file: absFile,\n line: position.line,\n offset: position.character,\n });\n }\n\n async getDefinition(file: string, position: Position) {\n const absFile = this.convertFileToAbsoluteIfNeeded(file);\n await this.openIfNeeded(absFile);\n const response = await this.tsServer?.request(CommandTypes.Definition, {\n file: absFile,\n line: position.line,\n offset: position.character,\n });\n\n if (!response?.success) {\n // TODO: we need a function to handle responses properly here for all.\n this.logger.warn(`For file ${absFile} tsserver failed to request definition info`);\n return response;\n }\n\n return response;\n }\n\n /**\n * @param file can be absolute or relative to this.projectRoot.\n */\n async getReferences(file: string, position: Position): Promise<ts.server.protocol.ReferencesResponse | undefined> {\n const absFile = this.convertFileToAbsoluteIfNeeded(file);\n await this.openIfNeeded(absFile);\n return this.tsServer?.request(CommandTypes.References, {\n file: absFile,\n line: position.line,\n offset: position.character,\n });\n }\n\n /**\n * @param file can be absolute or relative to this.projectRoot.\n */\n async getSignatureHelp(\n file: string,\n position: Position\n ): Promise<ts.server.protocol.SignatureHelpResponse | undefined> {\n const absFile = this.convertFileToAbsoluteIfNeeded(file);\n await this.openIfNeeded(absFile);\n\n return this.tsServer?.request(CommandTypes.SignatureHelp, {\n file: absFile,\n line: position.line,\n offset: position.character,\n });\n }\n\n private async configure(\n configureArgs: ts.server.protocol.ConfigureRequestArguments = {}\n ): Promise<ts.server.protocol.ConfigureResponse | undefined> {\n return this.tsServer?.request(CommandTypes.Configure, configureArgs);\n }\n\n /**\n * ask tsserver to open a file if it was not opened before.\n * @param file absolute path of the file\n */\n async openIfNeeded(file: string) {\n if (this.files.includes(file)) {\n return;\n }\n await this.open(file);\n this.files.push(file);\n }\n\n private async open(file: string) {\n return this.tsServer?.notify(CommandTypes.Open, {\n file,\n projectRootPath: this.projectPath,\n });\n }\n\n async close(file: string) {\n await this.tsServer?.notify(CommandTypes.Close, {\n file,\n });\n this.files = this.files.filter((openFile) => openFile !== file);\n }\n\n /**\n * since Bit is not an IDE, it doesn't have the information such as the exact line/offset of the changes.\n * as a workaround, to tell tsserver what was changed, we pretend that the entire file was cleared and new text was\n * added. this is the only way I could find to tell tsserver about the change. otherwise, tsserver keep assuming that\n * the file content remained the same. (closing/re-opening the file doesn't help).\n */\n async changed(file: string) {\n // tell tsserver that all content was removed\n await this.tsServer?.notify(CommandTypes.Change, {\n file,\n line: 1,\n offset: 1,\n endLine: 99999,\n endOffset: 1,\n insertString: '',\n });\n\n const content = await fs.readFile(file, 'utf-8');\n\n // tell tsserver that all file content was added\n await this.tsServer?.notify(CommandTypes.Change, {\n file,\n line: 1,\n offset: 1,\n endLine: 1,\n endOffset: 1,\n insertString: content,\n });\n }\n\n protected onTsserverEvent(event: ts.server.protocol.Event): void {\n switch (event.event) {\n case EventName.semanticDiag:\n case EventName.syntaxDiag:\n this.publishDiagnostic(event as ts.server.protocol.DiagnosticEvent);\n break;\n default:\n this.logger.debug(`ignored TsServer event: ${event.event}`);\n }\n }\n\n private convertFileToAbsoluteIfNeeded(filepath: string): string {\n if (path.isAbsolute(filepath)) {\n return filepath;\n }\n return path.join(this.projectPath, filepath);\n }\n\n private publishDiagnostic(message: ts.server.protocol.DiagnosticEvent) {\n if (!message.body?.diagnostics.length || (!this.options.printTypeErrors && !this.options.aggregateDiagnosticData)) {\n return;\n }\n this.lastDiagnostics.push(message.body);\n const file = path.relative(this.projectPath, message.body.file);\n message.body.diagnostics.forEach((diag) => {\n const formatted = formatDiagnostic(diag, file);\n if (this.options.printTypeErrors) {\n this.logger.console(formatted);\n }\n if (this.options.aggregateDiagnosticData) {\n this.diagnosticData.push({\n file,\n diagnostic: diag,\n formatted,\n });\n }\n });\n }\n\n /**\n * copied over from https://github.com/typescript-language-server/typescript-language-server/blob/master/src/lsp-server.ts\n */\n private findTsserverPath(): string {\n if (this.options.tsServerPath) {\n return this.options.tsServerPath;\n }\n\n const tsServerPath = path.join('typescript', 'lib', 'tsserver.js');\n\n /**\n * (1) find it in the bit directory\n */\n const bundled = findPathToModule(__dirname, tsServerPath);\n\n if (bundled) {\n return bundled;\n }\n\n // (2) use globally installed tsserver\n if (commandExists.sync(getTsserverExecutable())) {\n return getTsserverExecutable();\n }\n\n throw new Error(`Couldn't find '${getTsserverExecutable()}' executable or 'tsserver.js' module`);\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,QAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAG,MAAA;EAAA,MAAAH,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAC,KAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAI,SAAA;EAAA,MAAAJ,IAAA,GAAAE,OAAA;EAAAE,QAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAK,eAAA;EAAA,MAAAL,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAG,cAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAM,iBAAA;EAAA,MAAAN,IAAA,GAAAE,OAAA;EAAAI,gBAAA,YAAAA,CAAA;IAAA,OAAAN,IAAA;EAAA;EAAA,OAAAA,IAAA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AEzG,IAAI,CAAC;MAC9C,IAAI,IAAI,CAACxB,OAAO,CAAC6H,eAAe,EAAE;QAChC,IAAI,CAAC9H,MAAM,CAACyC,OAAO,CAAC0F,SAAS,CAAC;MAChC;MACA,IAAI,IAAI,CAAClI,OAAO,CAAC8H,uBAAuB,EAAE;QACxC,IAAI,CAAClI,cAAc,CAACwG,IAAI,CAAC;UACvB5E,IAAI;UACJ4G,UAAU,EAAEH,IAAI;UAChBC;QACF,CAAC,CAAC;MACJ;IACF,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;EACU5H,gBAAgBA,CAAA,EAAW;IACjC,IAAI,IAAI,CAACN,OAAO,CAACqI,YAAY,EAAE;MAC7B,OAAO,IAAI,CAACrI,OAAO,CAACqI,YAAY;IAClC;IAEA,MAAMA,YAAY,GAAGd,eAAI,CAACE,IAAI,CAAC,YAAY,EAAE,KAAK,EAAE,aAAa,CAAC;;IAElE;AACJ;AACA;IACI,MAAMa,OAAO,GAAG,IAAAC,mCAAgB,EAACC,SAAS,EAAEH,YAAY,CAAC;IAEzD,IAAIC,OAAO,EAAE;MACX,OAAOA,OAAO;IAChB;;IAEA;IACA,IAAIG,wBAAa,CAACC,IAAI,CAAC,IAAAC,8BAAqB,EAAC,CAAC,CAAC,EAAE;MAC/C,OAAO,IAAAA,8BAAqB,EAAC,CAAC;IAChC;IAEA,MAAM,IAAI9G,KAAK,CAAC,kBAAkB,IAAA8G,8BAAqB,EAAC,CAAC,sCAAsC,CAAC;EAClG;AACF;AAACC,OAAA,CAAApJ,cAAA,GAAAA,cAAA","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/ts-server",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.79",
|
|
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.79"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"typescript": "5.9.2",
|
package/ts-server-client.ts
CHANGED
|
@@ -18,6 +18,12 @@ export type TsserverClientOpts = {
|
|
|
18
18
|
checkTypes?: CheckTypes; // whether errors/warnings are monitored and printed to the console.
|
|
19
19
|
printTypeErrors?: boolean; // whether print typescript errors to the console.
|
|
20
20
|
aggregateDiagnosticData?: boolean; // whether to aggregate diagnostic data instead of printing them to the console.
|
|
21
|
+
/**
|
|
22
|
+
* if false, files passed to the constructor are NOT opened during init().
|
|
23
|
+
* useful when the caller wants to control opening (e.g. batched open/close in `getDiagnostic`).
|
|
24
|
+
* default: true (backward compatible).
|
|
25
|
+
*/
|
|
26
|
+
openFilesOnInit?: boolean;
|
|
21
27
|
};
|
|
22
28
|
|
|
23
29
|
export type DiagnosticData = {
|
|
@@ -30,6 +36,7 @@ export class TsserverClient {
|
|
|
30
36
|
private tsServer: ProcessBasedTsServer | null;
|
|
31
37
|
public lastDiagnostics: ts.server.protocol.DiagnosticEventBody[] = [];
|
|
32
38
|
private serverRunning = false;
|
|
39
|
+
private filesPreOpenedOnInit = false;
|
|
33
40
|
public diagnosticData: DiagnosticData[] = [];
|
|
34
41
|
constructor(
|
|
35
42
|
/**
|
|
@@ -68,16 +75,16 @@ export class TsserverClient {
|
|
|
68
75
|
this.logger.error('TsserverClient.init failed', err);
|
|
69
76
|
});
|
|
70
77
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
await Promise.all(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
+
const shouldOpenFiles = this.options.openFilesOnInit !== false;
|
|
79
|
+
if (this.files.length && shouldOpenFiles) {
|
|
80
|
+
const openResults = await Promise.all(
|
|
81
|
+
this.files.map((file) => this.open(file).catch((error: unknown) => error))
|
|
82
|
+
);
|
|
83
|
+
const failedFiles = openResults.filter((result) => result instanceof Error);
|
|
78
84
|
if (failedFiles.length > 0) {
|
|
79
85
|
this.logger.error('TsserverClient.init failed to open files:', failedFiles);
|
|
80
86
|
}
|
|
87
|
+
this.filesPreOpenedOnInit = true;
|
|
81
88
|
this.checkTypesIfNeeded();
|
|
82
89
|
}
|
|
83
90
|
this.logger.debug('TsserverClient.init completed');
|
|
@@ -145,7 +152,9 @@ export class TsserverClient {
|
|
|
145
152
|
* were found or not.
|
|
146
153
|
*
|
|
147
154
|
* @param files files to check
|
|
148
|
-
* @param batchSize if provided, files will be processed in batches
|
|
155
|
+
* @param batchSize if provided, files will be processed in batches. when files were not pre-opened
|
|
156
|
+
* via init(), each batch is opened, checked, then closed — keeping tsserver memory
|
|
157
|
+
* bounded by the batch size to avoid OOM in large workspaces.
|
|
149
158
|
*/
|
|
150
159
|
async getDiagnostic(files = this.files, batchSize?: number): Promise<any> {
|
|
151
160
|
this.lastDiagnostics = [];
|
|
@@ -154,13 +163,49 @@ export class TsserverClient {
|
|
|
154
163
|
return this.tsServer?.request(CommandTypes.Geterr, { delay: 0, files });
|
|
155
164
|
}
|
|
156
165
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
166
|
+
const filesArePreOpened = this.filesPreOpenedOnInit && files.every((f) => this.files.includes(f));
|
|
167
|
+
const total = files.length;
|
|
168
|
+
try {
|
|
169
|
+
for (let i = 0; i < files.length; i += batchSize) {
|
|
170
|
+
const batch = files.slice(i, i + batchSize);
|
|
171
|
+
const upTo = Math.min(i + batchSize, total);
|
|
172
|
+
this.logger.setStatusLine(`type-checking files ${i + 1}-${upTo} of ${total}`);
|
|
173
|
+
if (!filesArePreOpened) {
|
|
174
|
+
await this.openFiles(batch);
|
|
175
|
+
}
|
|
176
|
+
try {
|
|
177
|
+
await this.tsServer?.request(CommandTypes.Geterr, { delay: 0, files: batch });
|
|
178
|
+
} finally {
|
|
179
|
+
if (!filesArePreOpened) {
|
|
180
|
+
await this.closeFiles(batch).catch((err) => this.logger.error('failed to close batch', err));
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
} finally {
|
|
185
|
+
this.logger.clearStatusLine();
|
|
161
186
|
}
|
|
162
187
|
}
|
|
163
188
|
|
|
189
|
+
/**
|
|
190
|
+
* open multiple files in a single round-trip. useful when batching to bound tsserver memory.
|
|
191
|
+
*/
|
|
192
|
+
async openFiles(files: string[]): Promise<void> {
|
|
193
|
+
if (!files.length) return;
|
|
194
|
+
await this.tsServer?.request(CommandTypes.UpdateOpen, {
|
|
195
|
+
openFiles: files.map((file) => ({ file, projectRootPath: this.projectPath })),
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* close multiple files in a single round-trip.
|
|
201
|
+
*/
|
|
202
|
+
async closeFiles(files: string[]): Promise<void> {
|
|
203
|
+
if (!files.length) return;
|
|
204
|
+
await this.tsServer?.request(CommandTypes.UpdateOpen, {
|
|
205
|
+
closedFiles: files,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
|
|
164
209
|
/**
|
|
165
210
|
* avoid using this method, it takes longer than `getDiagnostic()` and shows errors from paths outside the project
|
|
166
211
|
*/
|