@teambit/ts-server 0.0.61 → 0.0.63

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { server } from 'typescript';
2
- type Diagnostic = server.protocol.Diagnostic;
2
+ export type Diagnostic = server.protocol.Diagnostic;
3
3
  /**
4
4
  * mostly taken from ts repo, src/compiler/program.ts "formatDiagnosticsWithColorAndContext" method.
5
5
  * sadly, it's impossible to use that method for the diagnostic format coming from ts-server. it only
@@ -7,4 +7,3 @@ type Diagnostic = server.protocol.Diagnostic;
7
7
  */
8
8
  export declare function formatDiagnostics(diagnostics: readonly Diagnostic[], filePath: string): string;
9
9
  export declare function formatDiagnostic(diagnostic: Diagnostic, filePath: string): string;
10
- export {};
@@ -1 +1 @@
1
- {"version":3,"names":["formatDiagnostics","diagnostics","filePath","output","diagnostic","formatDiagnostic","diagnosticCategoryName","category","errorMessage","code","flattenDiagnosticMessageText","text","line","offset","start","diag","newLine","indent","undefined","result","i","messageText","next","kid"],"sources":["format-diagnostics.ts"],"sourcesContent":["import { DiagnosticMessageChain, server } from 'typescript';\n\ntype Diagnostic = server.protocol.Diagnostic;\n\n/**\n * mostly taken from ts repo, src/compiler/program.ts \"formatDiagnosticsWithColorAndContext\" method.\n * sadly, it's impossible to use that method for the diagnostic format coming from ts-server. it only\n * works with the diagnostic format of \"ts\" APIs.\n */\nexport function formatDiagnostics(diagnostics: readonly Diagnostic[], filePath: string): string {\n let output = '';\n\n for (const diagnostic of diagnostics) {\n output += formatDiagnostic(diagnostic, filePath);\n }\n return output;\n}\n\nconst diagnosticCategoryName = (diagnostic: Diagnostic) => diagnostic.category;\n\nexport function formatDiagnostic(diagnostic: Diagnostic, filePath: string): string {\n const errorMessage = `${diagnosticCategoryName(diagnostic)} TS${diagnostic.code}: ${flattenDiagnosticMessageText(\n diagnostic.text,\n '\\n'\n )}${'\\n'}`;\n\n const { line, offset } = diagnostic.start;\n return `${filePath}(${line},${offset}): ${errorMessage}`;\n}\n\nfunction flattenDiagnosticMessageText(\n diag: string | DiagnosticMessageChain | undefined,\n newLine: string,\n indent = 0\n): string {\n if (typeof diag === 'string') {\n return diag;\n }\n if (diag === undefined) {\n return '';\n }\n let result = '';\n if (indent) {\n result += newLine;\n\n for (let i = 0; i < indent; i += 1) {\n result += ' ';\n }\n }\n result += diag.messageText;\n indent += 1;\n if (diag.next) {\n for (const kid of diag.next) {\n result += flattenDiagnosticMessageText(kid, newLine, indent);\n }\n }\n return result;\n}\n"],"mappings":";;;;;;;AAIA;AACA;AACA;AACA;AACA;AACO,SAASA,iBAAiBA,CAACC,WAAkC,EAAEC,QAAgB,EAAU;EAC9F,IAAIC,MAAM,GAAG,EAAE;EAEf,KAAK,MAAMC,UAAU,IAAIH,WAAW,EAAE;IACpCE,MAAM,IAAIE,gBAAgB,CAACD,UAAU,EAAEF,QAAQ,CAAC;EAClD;EACA,OAAOC,MAAM;AACf;AAEA,MAAMG,sBAAsB,GAAIF,UAAsB,IAAKA,UAAU,CAACG,QAAQ;AAEvE,SAASF,gBAAgBA,CAACD,UAAsB,EAAEF,QAAgB,EAAU;EACjF,MAAMM,YAAY,GAAG,GAAGF,sBAAsB,CAACF,UAAU,CAAC,MAAMA,UAAU,CAACK,IAAI,KAAKC,4BAA4B,CAC9GN,UAAU,CAACO,IAAI,EACf,IACF,CAAC,GAAG,IAAI,EAAE;EAEV,MAAM;IAAEC,IAAI;IAAEC;EAAO,CAAC,GAAGT,UAAU,CAACU,KAAK;EACzC,OAAO,GAAGZ,QAAQ,IAAIU,IAAI,IAAIC,MAAM,MAAML,YAAY,EAAE;AAC1D;AAEA,SAASE,4BAA4BA,CACnCK,IAAiD,EACjDC,OAAe,EACfC,MAAM,GAAG,CAAC,EACF;EACR,IAAI,OAAOF,IAAI,KAAK,QAAQ,EAAE;IAC5B,OAAOA,IAAI;EACb;EACA,IAAIA,IAAI,KAAKG,SAAS,EAAE;IACtB,OAAO,EAAE;EACX;EACA,IAAIC,MAAM,GAAG,EAAE;EACf,IAAIF,MAAM,EAAE;IACVE,MAAM,IAAIH,OAAO;IAEjB,KAAK,IAAII,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGH,MAAM,EAAEG,CAAC,IAAI,CAAC,EAAE;MAClCD,MAAM,IAAI,IAAI;IAChB;EACF;EACAA,MAAM,IAAIJ,IAAI,CAACM,WAAW;EAC1BJ,MAAM,IAAI,CAAC;EACX,IAAIF,IAAI,CAACO,IAAI,EAAE;IACb,KAAK,MAAMC,GAAG,IAAIR,IAAI,CAACO,IAAI,EAAE;MAC3BH,MAAM,IAAIT,4BAA4B,CAACa,GAAG,EAAEP,OAAO,EAAEC,MAAM,CAAC;IAC9D;EACF;EACA,OAAOE,MAAM;AACf","ignoreList":[]}
1
+ {"version":3,"names":["formatDiagnostics","diagnostics","filePath","output","diagnostic","formatDiagnostic","diagnosticCategoryName","category","errorMessage","code","flattenDiagnosticMessageText","text","line","offset","start","diag","newLine","indent","undefined","result","i","messageText","next","kid"],"sources":["format-diagnostics.ts"],"sourcesContent":["import { DiagnosticMessageChain, server } from 'typescript';\n\nexport type Diagnostic = server.protocol.Diagnostic;\n\n/**\n * mostly taken from ts repo, src/compiler/program.ts \"formatDiagnosticsWithColorAndContext\" method.\n * sadly, it's impossible to use that method for the diagnostic format coming from ts-server. it only\n * works with the diagnostic format of \"ts\" APIs.\n */\nexport function formatDiagnostics(diagnostics: readonly Diagnostic[], filePath: string): string {\n let output = '';\n\n for (const diagnostic of diagnostics) {\n output += formatDiagnostic(diagnostic, filePath);\n }\n return output;\n}\n\nconst diagnosticCategoryName = (diagnostic: Diagnostic) => diagnostic.category;\n\nexport function formatDiagnostic(diagnostic: Diagnostic, filePath: string): string {\n const errorMessage = `${diagnosticCategoryName(diagnostic)} TS${diagnostic.code}: ${flattenDiagnosticMessageText(\n diagnostic.text,\n '\\n'\n )}${'\\n'}`;\n\n const { line, offset } = diagnostic.start;\n return `${filePath}(${line},${offset}): ${errorMessage}`;\n}\n\nfunction flattenDiagnosticMessageText(\n diag: string | DiagnosticMessageChain | undefined,\n newLine: string,\n indent = 0\n): string {\n if (typeof diag === 'string') {\n return diag;\n }\n if (diag === undefined) {\n return '';\n }\n let result = '';\n if (indent) {\n result += newLine;\n\n for (let i = 0; i < indent; i += 1) {\n result += ' ';\n }\n }\n result += diag.messageText;\n indent += 1;\n if (diag.next) {\n for (const kid of diag.next) {\n result += flattenDiagnosticMessageText(kid, newLine, indent);\n }\n }\n return result;\n}\n"],"mappings":";;;;;;;AAIA;AACA;AACA;AACA;AACA;AACO,SAASA,iBAAiBA,CAACC,WAAkC,EAAEC,QAAgB,EAAU;EAC9F,IAAIC,MAAM,GAAG,EAAE;EAEf,KAAK,MAAMC,UAAU,IAAIH,WAAW,EAAE;IACpCE,MAAM,IAAIE,gBAAgB,CAACD,UAAU,EAAEF,QAAQ,CAAC;EAClD;EACA,OAAOC,MAAM;AACf;AAEA,MAAMG,sBAAsB,GAAIF,UAAsB,IAAKA,UAAU,CAACG,QAAQ;AAEvE,SAASF,gBAAgBA,CAACD,UAAsB,EAAEF,QAAgB,EAAU;EACjF,MAAMM,YAAY,GAAG,GAAGF,sBAAsB,CAACF,UAAU,CAAC,MAAMA,UAAU,CAACK,IAAI,KAAKC,4BAA4B,CAC9GN,UAAU,CAACO,IAAI,EACf,IACF,CAAC,GAAG,IAAI,EAAE;EAEV,MAAM;IAAEC,IAAI;IAAEC;EAAO,CAAC,GAAGT,UAAU,CAACU,KAAK;EACzC,OAAO,GAAGZ,QAAQ,IAAIU,IAAI,IAAIC,MAAM,MAAML,YAAY,EAAE;AAC1D;AAEA,SAASE,4BAA4BA,CACnCK,IAAiD,EACjDC,OAAe,EACfC,MAAM,GAAG,CAAC,EACF;EACR,IAAI,OAAOF,IAAI,KAAK,QAAQ,EAAE;IAC5B,OAAOA,IAAI;EACb;EACA,IAAIA,IAAI,KAAKG,SAAS,EAAE;IACtB,OAAO,EAAE;EACX;EACA,IAAIC,MAAM,GAAG,EAAE;EACf,IAAIF,MAAM,EAAE;IACVE,MAAM,IAAIH,OAAO;IAEjB,KAAK,IAAII,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGH,MAAM,EAAEG,CAAC,IAAI,CAAC,EAAE;MAClCD,MAAM,IAAI,IAAI;IAChB;EACF;EACAA,MAAM,IAAIJ,IAAI,CAACM,WAAW;EAC1BJ,MAAM,IAAI,CAAC;EACX,IAAIF,IAAI,CAACO,IAAI,EAAE;IACb,KAAK,MAAMC,GAAG,IAAIR,IAAI,CAACO,IAAI,EAAE;MAC3BH,MAAM,IAAIT,4BAA4B,CAACa,GAAG,EAAEP,OAAO,EAAEC,MAAM,CAAC;IAC9D;EACF;EACA,OAAOE,MAAM;AACf","ignoreList":[]}
@@ -2,11 +2,18 @@ import { Logger } from '@teambit/logger';
2
2
  import type ts from 'typescript/lib/tsserverlibrary';
3
3
  import { CheckTypes } from '@teambit/watcher';
4
4
  import type { Position } from 'vscode-languageserver-types';
5
+ import { Diagnostic } from './format-diagnostics';
5
6
  export type TsserverClientOpts = {
6
7
  verbose?: boolean;
7
8
  tsServerPath?: string;
8
9
  checkTypes?: CheckTypes;
9
10
  printTypeErrors?: boolean;
11
+ aggregateDiagnosticData?: boolean;
12
+ };
13
+ export type DiagnosticData = {
14
+ file: string;
15
+ diagnostic: Diagnostic;
16
+ formatted: string;
10
17
  };
11
18
  export declare class TsserverClient {
12
19
  /**
@@ -23,6 +30,7 @@ export declare class TsserverClient {
23
30
  private tsServer;
24
31
  lastDiagnostics: ts.server.protocol.DiagnosticEventBody[];
25
32
  private serverRunning;
33
+ diagnosticData: DiagnosticData[];
26
34
  constructor(
27
35
  /**
28
36
  * absolute root path of the project.
@@ -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
+ diagnosticData = [];
74
75
  constructor(
75
76
  /**
76
77
  * absolute root path of the project.
@@ -332,12 +333,24 @@ class TsserverClient {
332
333
  return _path().default.join(this.projectPath, filepath);
333
334
  }
334
335
  publishDiagnostic(message) {
335
- if (!message.body?.diagnostics.length || !this.options.printTypeErrors) {
336
+ if (!message.body?.diagnostics.length || !this.options.printTypeErrors && !this.options.aggregateDiagnosticData) {
336
337
  return;
337
338
  }
338
339
  this.lastDiagnostics.push(message.body);
339
340
  const file = _path().default.relative(this.projectPath, message.body.file);
340
- message.body.diagnostics.forEach(diag => this.logger.console((0, _formatDiagnostics().formatDiagnostic)(diag, file)));
341
+ message.body.diagnostics.forEach(diag => {
342
+ const formatted = (0, _formatDiagnostics().formatDiagnostic)(diag, file);
343
+ if (this.options.printTypeErrors) {
344
+ this.logger.console(formatted);
345
+ }
346
+ if (this.options.aggregateDiagnosticData) {
347
+ this.diagnosticData.push({
348
+ file,
349
+ diagnostic: diag,
350
+ formatted
351
+ });
352
+ }
353
+ });
341
354
  }
342
355
 
343
356
  /**
@@ -1 +1 @@
1
- {"version":3,"names":["_fsExtra","data","_interopRequireDefault","require","_path","_watcher","_commandExists","_modulesResolver","_processBasedTsserver","_tspCommandTypes","_utils","_formatDiagnostics","e","__esModule","default","TsserverClient","lastDiagnostics","serverRunning","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","request","CommandTypes","Geterr","delay","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","relative","forEach","diag","formatDiagnostic","tsServerPath","bundled","findPathToModule","__dirname","commandExists","sync","getTsserverExecutable","exports"],"sources":["ts-server-client.ts"],"sourcesContent":["import fs from 'fs-extra';\nimport { 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 { 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};\n\nexport class TsserverClient {\n private tsServer: ProcessBasedTsServer | null;\n public lastDiagnostics: ts.server.protocol.DiagnosticEventBody[] = [];\n private serverRunning = false;\n\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 async getDiagnostic(files = this.files): Promise<any> {\n this.lastDiagnostics = [];\n return this.tsServer?.request(CommandTypes.Geterr, { delay: 0, files });\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) {\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) => this.logger.console(formatDiagnostic(diag, file)));\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,S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C;IAEA,MAAM,IAAI1F,KAAK,CAAC,kBAAkB,IAAA0F,8BAAqB,EAAC,CAAC,sCAAsC,CAAC;EAClG;AACF;AAACC,OAAA,CAAA5H,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","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","request","CommandTypes","Geterr","delay","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 { 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 { formatDiagnostic, Diagnostic } 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 async getDiagnostic(files = this.files): Promise<any> {\n this.lastDiagnostics = [];\n return this.tsServer?.request(CommandTypes.Geterr, { delay: 0, files });\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;AAAA;AACA,SAAAO,sB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AgB,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,IAAI7F,KAAK,CAAC,kBAAkB,IAAA6F,8BAAqB,EAAC,CAAC,sCAAsC,CAAC;EAClG;AACF;AAACC,OAAA,CAAAhI,cAAA,GAAAA,cAAA","ignoreList":[]}
@@ -1,6 +1,6 @@
1
1
  import { DiagnosticMessageChain, server } from 'typescript';
2
2
 
3
- type Diagnostic = server.protocol.Diagnostic;
3
+ export type Diagnostic = server.protocol.Diagnostic;
4
4
 
5
5
  /**
6
6
  * mostly taken from ts repo, src/compiler/program.ts "formatDiagnosticsWithColorAndContext" method.
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/ts-server",
3
- "version": "0.0.61",
3
+ "version": "0.0.63",
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.61"
9
+ "version": "0.0.63"
10
10
  },
11
11
  "dependencies": {
12
12
  "typescript": "5.5.3",
@@ -20,7 +20,7 @@
20
20
  "@types/fs-extra": "9.0.7",
21
21
  "@types/mocha": "10.0.1",
22
22
  "chai": "4.3.0",
23
- "@teambit/node.envs.node-babel-mocha": "0.1.4"
23
+ "@teambit/node.envs.node-babel-mocha": "0.1.5"
24
24
  },
25
25
  "peerDependencies": {},
26
26
  "license": "Apache-2.0",
@@ -9,20 +9,27 @@ import { findPathToModule } from './modules-resolver';
9
9
  import { ProcessBasedTsServer } from './process-based-tsserver';
10
10
  import { CommandTypes, EventName } from './tsp-command-types';
11
11
  import { getTsserverExecutable } from './utils';
12
- import { formatDiagnostic } from './format-diagnostics';
12
+ import { formatDiagnostic, Diagnostic } from './format-diagnostics';
13
13
 
14
14
  export type TsserverClientOpts = {
15
15
  verbose?: boolean; // print tsserver events to the console.
16
16
  tsServerPath?: string; // if not provided, it'll use findTsserverPath() strategies.
17
17
  checkTypes?: CheckTypes; // whether errors/warnings are monitored and printed to the console.
18
18
  printTypeErrors?: boolean; // whether print typescript errors to the console.
19
+ aggregateDiagnosticData?: boolean; // whether to aggregate diagnostic data instead of printing them to the console.
19
20
  };
20
21
 
22
+ export type DiagnosticData = {
23
+ file: string;
24
+ diagnostic: Diagnostic;
25
+ formatted: string;
26
+ }
27
+
21
28
  export class TsserverClient {
22
29
  private tsServer: ProcessBasedTsServer | null;
23
30
  public lastDiagnostics: ts.server.protocol.DiagnosticEventBody[] = [];
24
31
  private serverRunning = false;
25
-
32
+ public diagnosticData: DiagnosticData[] = [];
26
33
  constructor(
27
34
  /**
28
35
  * absolute root path of the project.
@@ -306,12 +313,24 @@ export class TsserverClient {
306
313
  }
307
314
 
308
315
  private publishDiagnostic(message: ts.server.protocol.DiagnosticEvent) {
309
- if (!message.body?.diagnostics.length || !this.options.printTypeErrors) {
316
+ if (!message.body?.diagnostics.length || (!this.options.printTypeErrors && !this.options.aggregateDiagnosticData)) {
310
317
  return;
311
318
  }
312
319
  this.lastDiagnostics.push(message.body);
313
320
  const file = path.relative(this.projectPath, message.body.file);
314
- message.body.diagnostics.forEach((diag) => this.logger.console(formatDiagnostic(diag, file)));
321
+ message.body.diagnostics.forEach((diag) => {
322
+ const formatted = formatDiagnostic(diag, file);
323
+ if (this.options.printTypeErrors) {
324
+ this.logger.console(formatted);
325
+ }
326
+ if (this.options.aggregateDiagnosticData) {
327
+ this.diagnosticData.push({
328
+ file,
329
+ diagnostic: diag,
330
+ formatted,
331
+ });
332
+ }
333
+ });
315
334
  }
316
335
 
317
336
  /**