@teambit/ts-server 0.0.64 → 0.0.66
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/format-diagnostics.d.ts +1 -1
- package/dist/format-diagnostics.js.map +1 -1
- package/dist/process-based-tsserver.d.ts +3 -3
- package/dist/process-based-tsserver.js.map +1 -1
- package/dist/ts-server-client.d.ts +2 -2
- package/dist/ts-server-client.js.map +1 -1
- package/format-diagnostics.ts +1 -1
- package/package.json +3 -3
- package/process-based-tsserver.ts +4 -4
- package/ts-server-client.ts +3 -2
|
@@ -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\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":[]}
|
|
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 type { 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":[]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* part of this file was copied over from https://github.com/typescript-language-server/typescript-language-server/blob/master/src/tsp-client.ts
|
|
3
3
|
*/
|
|
4
|
-
import { Logger } from '@teambit/logger';
|
|
4
|
+
import type { Logger } from '@teambit/logger';
|
|
5
5
|
import type ts from 'typescript/lib/tsserverlibrary';
|
|
6
|
-
import { CancellationToken } from 'vscode-jsonrpc';
|
|
7
|
-
import { CommandTypes } from './tsp-command-types';
|
|
6
|
+
import type { CancellationToken } from 'vscode-jsonrpc';
|
|
7
|
+
import type { CommandTypes } from './tsp-command-types';
|
|
8
8
|
export interface TspClientOptions {
|
|
9
9
|
logger: Logger;
|
|
10
10
|
tsserverPath: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["fs","data","_interopRequireWildcard","require","path","cp","readline","decoder","_tempy","_interopRequireDefault","_utils","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","ProcessBasedTsServer","seq","deferreds","constructor","options","tsServerArgs","logger","restart","kill","start","Promise","resolve","reject","tsServerProcess","Error","tsserverPath","logFile","logVerbosity","maxTsServerMemory","globalPlugins","pluginProbeLocations","args","push","length","join","cancellationPipeName","tempy","file","name","info","tsserverPathIsModule","extname","silent","execArgv","fork","spawn","readlineInterface","createInterface","stdout","stdin","undefined","process","on","line","processMessage","dec","StringDecoder","stderr","addListener","stringMsg","write","error","notify","command","ensureServerIsRunning","sendMessage","request","token","deferred","Deferred","promise","onCancelled","onCancellationRequested","dispose","requestCancellationPipeName","writeFile","err","then","unlink","result","destroy","close","log","msg","obj","logToConsole","console","JSON","stringify","trace","notification","type","arguments","serializedRequest","untrimmedMessageString","messageString","trim","startsWith","message","parse","isEvent","isResponse","resolveResponse","request_seq","success","isRequestCompletedEvent","body","onEvent","event","exports"],"sources":["process-based-tsserver.ts"],"sourcesContent":["/**\n * part of this file was copied over from https://github.com/typescript-language-server/typescript-language-server/blob/master/src/tsp-client.ts\n */\n\n/*\n * Copyright (C) 2017, 2018 TypeFox and others.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0\n */\n\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as cp from 'child_process';\nimport * as readline from 'readline';\nimport { Logger } from '@teambit/logger';\nimport { Readable, Writable } from 'stream';\nimport * as decoder from 'string_decoder';\nimport type ts from 'typescript/lib/tsserverlibrary';\nimport tempy from 'tempy';\nimport { CancellationToken } from 'vscode-jsonrpc';\nimport { CommandTypes } from './tsp-command-types';\nimport { Deferred } from './utils';\n\nexport interface TspClientOptions {\n logger: Logger;\n tsserverPath: string;\n logToConsole?: boolean;\n onEvent?: (event: ts.server.protocol.Event) => void;\n}\n\nexport interface TsServerArgs {\n logFile?: string;\n logVerbosity?: string;\n maxTsServerMemory?: number;\n globalPlugins?: string[];\n pluginProbeLocations?: string[];\n}\n\nexport interface StandardTsServerRequests {\n [CommandTypes.ApplyCodeActionCommand]: [\n ts.server.protocol.ApplyCodeActionCommandRequestArgs,\n ts.server.protocol.ApplyCodeActionCommandResponse,\n ];\n [CommandTypes.CompletionDetails]: [\n ts.server.protocol.CompletionDetailsRequestArgs,\n ts.server.protocol.CompletionDetailsResponse,\n ];\n [CommandTypes.CompletionInfo]: [ts.server.protocol.CompletionsRequestArgs, ts.server.protocol.CompletionInfoResponse];\n [CommandTypes.Configure]: [ts.server.protocol.ConfigureRequestArguments, ts.server.protocol.ConfigureResponse];\n [CommandTypes.Definition]: [ts.server.protocol.FileLocationRequestArgs, ts.server.protocol.DefinitionResponse];\n [CommandTypes.DefinitionAndBoundSpan]: [\n ts.server.protocol.FileLocationRequestArgs,\n ts.server.protocol.DefinitionInfoAndBoundSpanResponse,\n ];\n [CommandTypes.DocCommentTemplate]: [\n ts.server.protocol.FileLocationRequestArgs,\n ts.server.protocol.DocCommandTemplateResponse,\n ];\n [CommandTypes.DocumentHighlights]: [\n ts.server.protocol.DocumentHighlightsRequestArgs,\n ts.server.protocol.DocumentHighlightsResponse,\n ];\n [CommandTypes.Format]: [ts.server.protocol.FormatRequestArgs, ts.server.protocol.FormatResponse];\n [CommandTypes.Formatonkey]: [ts.server.protocol.FormatOnKeyRequestArgs, ts.server.protocol.FormatResponse];\n [CommandTypes.GetApplicableRefactors]: [\n ts.server.protocol.GetApplicableRefactorsRequestArgs,\n ts.server.protocol.GetApplicableRefactorsResponse,\n ];\n [CommandTypes.GetCodeFixes]: [ts.server.protocol.CodeFixRequestArgs, ts.server.protocol.CodeFixResponse];\n [CommandTypes.GetCombinedCodeFix]: [\n ts.server.protocol.GetCombinedCodeFixRequestArgs,\n ts.server.protocol.GetCombinedCodeFixResponse,\n ];\n [CommandTypes.GetEditsForFileRename]: [\n ts.server.protocol.GetEditsForFileRenameRequestArgs,\n ts.server.protocol.GetEditsForFileRenameResponse,\n ];\n [CommandTypes.GetEditsForRefactor]: [\n ts.server.protocol.GetEditsForRefactorRequestArgs,\n ts.server.protocol.GetEditsForRefactorResponse,\n ];\n [CommandTypes.GetOutliningSpans]: [ts.server.protocol.FileRequestArgs, ts.server.protocol.OutliningSpansResponse];\n [CommandTypes.GetSupportedCodeFixes]: [null, ts.server.protocol.GetSupportedCodeFixesResponse];\n [CommandTypes.Implementation]: [\n ts.server.protocol.FileLocationRequestArgs,\n ts.server.protocol.ImplementationResponse,\n ];\n [CommandTypes.JsxClosingTag]: [ts.server.protocol.JsxClosingTagRequestArgs, ts.server.protocol.JsxClosingTagResponse];\n [CommandTypes.Navto]: [ts.server.protocol.NavtoRequestArgs, ts.server.protocol.NavtoResponse];\n [CommandTypes.NavTree]: [ts.server.protocol.FileRequestArgs, ts.server.protocol.NavTreeResponse];\n [CommandTypes.OrganizeImports]: [\n ts.server.protocol.OrganizeImportsRequestArgs,\n ts.server.protocol.OrganizeImportsResponse,\n ];\n [CommandTypes.PrepareCallHierarchy]: [\n ts.server.protocol.FileLocationRequestArgs,\n ts.server.protocol.PrepareCallHierarchyResponse,\n ];\n [CommandTypes.ProvideCallHierarchyIncomingCalls]: [\n ts.server.protocol.FileLocationRequestArgs,\n ts.server.protocol.ProvideCallHierarchyIncomingCallsResponse,\n ];\n [CommandTypes.ProvideCallHierarchyOutgoingCalls]: [\n ts.server.protocol.FileLocationRequestArgs,\n ts.server.protocol.ProvideCallHierarchyOutgoingCallsResponse,\n ];\n [CommandTypes.ProjectInfo]: [ts.server.protocol.ProjectInfoRequestArgs, ts.server.protocol.ProjectInfoResponse];\n [CommandTypes.ProvideInlayHints]: [ts.server.protocol.InlayHintsRequestArgs, ts.server.protocol.InlayHintsResponse];\n [CommandTypes.Quickinfo]: [ts.server.protocol.FileLocationRequestArgs, ts.server.protocol.QuickInfoResponse];\n [CommandTypes.References]: [ts.server.protocol.FileLocationRequestArgs, ts.server.protocol.ReferencesResponse];\n [CommandTypes.Rename]: [ts.server.protocol.RenameRequestArgs, ts.server.protocol.RenameResponse];\n [CommandTypes.SelectionRange]: [\n ts.server.protocol.SelectionRangeRequestArgs,\n ts.server.protocol.SelectionRangeResponse,\n ];\n [CommandTypes.SignatureHelp]: [ts.server.protocol.SignatureHelpRequestArgs, ts.server.protocol.SignatureHelpResponse];\n [CommandTypes.TypeDefinition]: [\n ts.server.protocol.FileLocationRequestArgs,\n ts.server.protocol.TypeDefinitionResponse,\n ];\n [CommandTypes.UpdateOpen]: [ts.server.protocol.UpdateOpenRequestArgs, ts.server.protocol.Response];\n}\n\nexport interface NoResponseTsServerRequests {\n [CommandTypes.Change]: [ts.server.protocol.ChangeRequestArgs, null];\n [CommandTypes.Close]: [ts.server.protocol.FileRequestArgs, null];\n [CommandTypes.CompilerOptionsForInferredProjects]: [\n ts.server.protocol.SetCompilerOptionsForInferredProjectsArgs,\n ts.server.protocol.SetCompilerOptionsForInferredProjectsResponse,\n ];\n [CommandTypes.Configure]: [ts.server.protocol.ConfigureRequestArguments, ts.server.protocol.ConfigureResponse];\n [CommandTypes.ConfigurePlugin]: [\n ts.server.protocol.ConfigurePluginRequestArguments,\n ts.server.protocol.ConfigurePluginResponse,\n ];\n [CommandTypes.Open]: [ts.server.protocol.OpenRequestArgs, null];\n}\n\nexport interface AsyncTsServerRequests {\n [CommandTypes.Geterr]: [ts.server.protocol.GeterrRequestArgs, ts.server.protocol.Response];\n [CommandTypes.GeterrForProject]: [ts.server.protocol.GeterrForProjectRequestArgs, ts.server.protocol.Response];\n}\n\nexport type TypeScriptRequestTypes = StandardTsServerRequests & NoResponseTsServerRequests & AsyncTsServerRequests;\n\nexport class ProcessBasedTsServer {\n private readlineInterface: readline.ReadLine | null;\n private tsServerProcess: cp.ChildProcess | null;\n private seq = 0;\n\n private readonly deferreds: {\n [seq: number]: Deferred<any>;\n } = {};\n\n private logger: Logger;\n private cancellationPipeName: string | undefined;\n\n constructor(\n private options: TspClientOptions,\n private tsServerArgs: TsServerArgs = {}\n ) {\n this.logger = options.logger;\n }\n\n async restart() {\n this.kill();\n await this.start();\n }\n\n start() {\n return new Promise<void>((resolve, reject) => {\n if (this.tsServerProcess) {\n reject(new Error('server already started'));\n return;\n }\n\n const { tsserverPath } = this.options;\n const { logFile, logVerbosity, maxTsServerMemory, globalPlugins, pluginProbeLocations } = this.tsServerArgs;\n const args: string[] = [];\n if (logFile) {\n args.push('--logFile', logFile);\n }\n if (logVerbosity) {\n args.push('--logVerbosity', logVerbosity);\n }\n if (globalPlugins && globalPlugins.length) {\n args.push('--globalPlugins', globalPlugins.join(','));\n }\n if (pluginProbeLocations && pluginProbeLocations.length) {\n args.push('--pluginProbeLocations', pluginProbeLocations.join(','));\n }\n this.cancellationPipeName = tempy.file({ name: 'tscancellation' });\n args.push('--cancellationPipeName', `${this.cancellationPipeName}*`);\n this.logger.info(`Starting tsserver : '${tsserverPath} ${args.join(' ')}'`);\n const tsserverPathIsModule = path.extname(tsserverPath) === '.js';\n const options = {\n silent: true,\n execArgv: maxTsServerMemory ? [`--max-old-space-size=${maxTsServerMemory}`] : [],\n };\n this.tsServerProcess = tsserverPathIsModule ? cp.fork(tsserverPath, args, options) : cp.spawn(tsserverPath, args);\n\n this.readlineInterface = readline.createInterface(\n this.tsServerProcess.stdout as Readable,\n this.tsServerProcess.stdin as Writable,\n undefined\n );\n process.on('exit', () => {\n this.kill();\n reject(new Error('TSServer was killed'));\n });\n\n this.readlineInterface.on('line', (line) => {\n this.processMessage(line, resolve, reject);\n });\n\n const dec = new decoder.StringDecoder('utf-8');\n this.tsServerProcess.stderr?.addListener('data', (data) => {\n const stringMsg = typeof data === 'string' ? data : dec.write(data);\n this.logger.error(stringMsg);\n reject(new Error(stringMsg));\n });\n });\n }\n\n async notify(command: CommandTypes.Open, args: ts.server.protocol.OpenRequestArgs): Promise<void>;\n async notify(command: CommandTypes.Close, args: ts.server.protocol.FileRequestArgs): Promise<void>;\n async notify(command: CommandTypes.Saveto, args: ts.server.protocol.SavetoRequestArgs): Promise<void>;\n async notify(command: CommandTypes.Change, args: ts.server.protocol.ChangeRequestArgs): Promise<void>;\n async notify(command: string, args: any): Promise<void> {\n await this.ensureServerIsRunning();\n this.sendMessage(command, true, args);\n }\n\n async request<K extends keyof TypeScriptRequestTypes>(\n command: K,\n args: TypeScriptRequestTypes[K][0],\n token?: CancellationToken\n ): Promise<TypeScriptRequestTypes[K][1]> {\n await this.ensureServerIsRunning();\n this.sendMessage(command, false, args);\n const seq = this.seq;\n const deferred = new Deferred<TypeScriptRequestTypes[K][1]>();\n this.deferreds[seq] = deferred;\n const request = deferred.promise;\n\n let onCancelled;\n if (token) {\n onCancelled = token.onCancellationRequested(() => {\n onCancelled.dispose();\n if (this.cancellationPipeName) {\n const requestCancellationPipeName = `${this.cancellationPipeName}${seq}`;\n fs.writeFile(requestCancellationPipeName, '', (err) => {\n if (!err) {\n // eslint-disable-next-line\n request.then(() =>\n fs.unlink(requestCancellationPipeName, () => {\n /* no-op */\n })\n );\n }\n });\n }\n });\n }\n\n try {\n const result = await request;\n onCancelled?.dispose();\n return result;\n } catch (error) {\n this.logger.error(`Error in request: ${error}`);\n throw error;\n }\n }\n\n kill() {\n this.tsServerProcess?.kill();\n this.tsServerProcess?.stdin?.destroy();\n this.readlineInterface?.close();\n this.tsServerProcess = null;\n this.readlineInterface = null;\n }\n\n private log(msg: string, obj: Record<string, any> = {}) {\n msg = `[tsserver] ${msg}`;\n if (this.options.logToConsole) {\n this.logger.console(`${msg} ${JSON.stringify(obj, undefined, 4)}`);\n } else {\n this.logger.trace(msg, obj);\n }\n }\n\n protected sendMessage(command: string, notification: boolean, args?: any): void {\n this.seq += 1;\n const request: ts.server.protocol.Request = {\n command,\n seq: this.seq,\n type: 'request',\n };\n if (args) {\n request.arguments = args;\n }\n const serializedRequest = `${JSON.stringify(request)}\\n`;\n this.tsServerProcess?.stdin?.write(serializedRequest);\n this.log(notification ? 'notify' : 'request', request);\n }\n\n protected processMessage(untrimmedMessageString: string, resolve?: () => void, reject?: (err) => void): void {\n const messageString = untrimmedMessageString.trim();\n if (!messageString || messageString.startsWith('Content-Length:')) {\n return;\n }\n let message: ts.server.protocol.Message;\n\n try {\n message = JSON.parse(messageString);\n } catch {\n // If the message isn't valid JSON, it's not a valid tsserver message. Reject the promise.\n reject?.(new Error(`Received invalid message from TSServer: ${untrimmedMessageString}`));\n return;\n }\n\n this.log('processMessage', message);\n\n if (this.isEvent(message)) {\n resolve?.();\n }\n\n if (this.isResponse(message)) {\n this.resolveResponse(message, message.request_seq, message.success);\n } else if (this.isEvent(message)) {\n if (this.isRequestCompletedEvent(message)) {\n this.resolveResponse(message, message.body.request_seq, true);\n } else if (this.options.onEvent) {\n this.options.onEvent(message);\n }\n }\n }\n\n private resolveResponse(message: ts.server.protocol.Message, request_seq: number, success: boolean) {\n const deferred = this.deferreds[request_seq];\n this.log('request completed', { request_seq, success });\n if (deferred) {\n if (success) {\n this.deferreds[request_seq].resolve(message);\n } else {\n this.deferreds[request_seq].reject(message);\n }\n delete this.deferreds[request_seq];\n }\n }\n\n private isEvent(message: ts.server.protocol.Message): message is ts.server.protocol.Event {\n return message.type === 'event';\n }\n\n private isResponse(message: ts.server.protocol.Message): message is ts.server.protocol.Response {\n return message.type === 'response';\n }\n\n private isRequestCompletedEvent(\n message: ts.server.protocol.Message\n ): message is ts.server.protocol.RequestCompletedEvent {\n return this.isEvent(message) && message.event === 'requestCompleted';\n }\n\n private async ensureServerIsRunning() {\n if (!this.tsServerProcess) {\n await this.restart();\n }\n }\n}\n"],"mappings":";;;;;;AAWA,SAAAA,GAAA;EAAA,MAAAC,IAAA,GAAAC,uBAAA,CAAAC,OAAA;EAAAH,EAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,KAAA;EAAA,MAAAH,IAAA,GAAAC,uBAAA,CAAAC,OAAA;EAAAC,IAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,GAAA;EAAA,MAAAJ,IAAA,GAAAC,uBAAA,CAAAC,OAAA;EAAAE,EAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,SAAA;EAAA,MAAAL,IAAA,GAAAC,uBAAA,CAAAC,OAAA;EAAAG,QAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EA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AAS,CAAC2F,WAAW,CAAC;IACpC;EACF;EAEQH,OAAOA,CAACF,OAAmC,EAAuC;IACxF,OAAOA,OAAO,CAACP,IAAI,KAAK,OAAO;EACjC;EAEQU,UAAUA,CAACH,OAAmC,EAA0C;IAC9F,OAAOA,OAAO,CAACP,IAAI,KAAK,UAAU;EACpC;EAEQc,uBAAuBA,CAC7BP,OAAmC,EACkB;IACrD,OAAO,IAAI,CAACE,OAAO,CAACF,OAAO,CAAC,IAAIA,OAAO,CAACU,KAAK,KAAK,kBAAkB;EACtE;EAEA,MAAc5C,qBAAqBA,CAAA,EAAG;IACpC,IAAI,CAAC,IAAI,CAACzC,eAAe,EAAE;MACzB,MAAM,IAAI,CAACN,OAAO,CAAC,CAAC;IACtB;EACF;AACF;AAAC4F,OAAA,CAAAnG,oBAAA,GAAAA,oBAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["fs","data","_interopRequireWildcard","require","path","cp","readline","decoder","_tempy","_interopRequireDefault","_utils","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","ProcessBasedTsServer","seq","deferreds","constructor","options","tsServerArgs","logger","restart","kill","start","Promise","resolve","reject","tsServerProcess","Error","tsserverPath","logFile","logVerbosity","maxTsServerMemory","globalPlugins","pluginProbeLocations","args","push","length","join","cancellationPipeName","tempy","file","name","info","tsserverPathIsModule","extname","silent","execArgv","fork","spawn","readlineInterface","createInterface","stdout","stdin","undefined","process","on","line","processMessage","dec","StringDecoder","stderr","addListener","stringMsg","write","error","notify","command","ensureServerIsRunning","sendMessage","request","token","deferred","Deferred","promise","onCancelled","onCancellationRequested","dispose","requestCancellationPipeName","writeFile","err","then","unlink","result","destroy","close","log","msg","obj","logToConsole","console","JSON","stringify","trace","notification","type","arguments","serializedRequest","untrimmedMessageString","messageString","trim","startsWith","message","parse","isEvent","isResponse","resolveResponse","request_seq","success","isRequestCompletedEvent","body","onEvent","event","exports"],"sources":["process-based-tsserver.ts"],"sourcesContent":["/**\n * part of this file was copied over from https://github.com/typescript-language-server/typescript-language-server/blob/master/src/tsp-client.ts\n */\n\n/*\n * Copyright (C) 2017, 2018 TypeFox and others.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0\n */\n\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as cp from 'child_process';\nimport * as readline from 'readline';\nimport type { Logger } from '@teambit/logger';\nimport type { Readable, Writable } from 'stream';\nimport * as decoder from 'string_decoder';\nimport type ts from 'typescript/lib/tsserverlibrary';\nimport tempy from 'tempy';\nimport type { CancellationToken } from 'vscode-jsonrpc';\nimport type { CommandTypes } from './tsp-command-types';\nimport { Deferred } from './utils';\n\nexport interface TspClientOptions {\n logger: Logger;\n tsserverPath: string;\n logToConsole?: boolean;\n onEvent?: (event: ts.server.protocol.Event) => void;\n}\n\nexport interface TsServerArgs {\n logFile?: string;\n logVerbosity?: string;\n maxTsServerMemory?: number;\n globalPlugins?: string[];\n pluginProbeLocations?: string[];\n}\n\nexport interface StandardTsServerRequests {\n [CommandTypes.ApplyCodeActionCommand]: [\n ts.server.protocol.ApplyCodeActionCommandRequestArgs,\n ts.server.protocol.ApplyCodeActionCommandResponse,\n ];\n [CommandTypes.CompletionDetails]: [\n ts.server.protocol.CompletionDetailsRequestArgs,\n ts.server.protocol.CompletionDetailsResponse,\n ];\n [CommandTypes.CompletionInfo]: [ts.server.protocol.CompletionsRequestArgs, ts.server.protocol.CompletionInfoResponse];\n [CommandTypes.Configure]: [ts.server.protocol.ConfigureRequestArguments, ts.server.protocol.ConfigureResponse];\n [CommandTypes.Definition]: [ts.server.protocol.FileLocationRequestArgs, ts.server.protocol.DefinitionResponse];\n [CommandTypes.DefinitionAndBoundSpan]: [\n ts.server.protocol.FileLocationRequestArgs,\n ts.server.protocol.DefinitionInfoAndBoundSpanResponse,\n ];\n [CommandTypes.DocCommentTemplate]: [\n ts.server.protocol.FileLocationRequestArgs,\n ts.server.protocol.DocCommandTemplateResponse,\n ];\n [CommandTypes.DocumentHighlights]: [\n ts.server.protocol.DocumentHighlightsRequestArgs,\n ts.server.protocol.DocumentHighlightsResponse,\n ];\n [CommandTypes.Format]: [ts.server.protocol.FormatRequestArgs, ts.server.protocol.FormatResponse];\n [CommandTypes.Formatonkey]: [ts.server.protocol.FormatOnKeyRequestArgs, ts.server.protocol.FormatResponse];\n [CommandTypes.GetApplicableRefactors]: [\n ts.server.protocol.GetApplicableRefactorsRequestArgs,\n ts.server.protocol.GetApplicableRefactorsResponse,\n ];\n [CommandTypes.GetCodeFixes]: [ts.server.protocol.CodeFixRequestArgs, ts.server.protocol.CodeFixResponse];\n [CommandTypes.GetCombinedCodeFix]: [\n ts.server.protocol.GetCombinedCodeFixRequestArgs,\n ts.server.protocol.GetCombinedCodeFixResponse,\n ];\n [CommandTypes.GetEditsForFileRename]: [\n ts.server.protocol.GetEditsForFileRenameRequestArgs,\n ts.server.protocol.GetEditsForFileRenameResponse,\n ];\n [CommandTypes.GetEditsForRefactor]: [\n ts.server.protocol.GetEditsForRefactorRequestArgs,\n ts.server.protocol.GetEditsForRefactorResponse,\n ];\n [CommandTypes.GetOutliningSpans]: [ts.server.protocol.FileRequestArgs, ts.server.protocol.OutliningSpansResponse];\n [CommandTypes.GetSupportedCodeFixes]: [null, ts.server.protocol.GetSupportedCodeFixesResponse];\n [CommandTypes.Implementation]: [\n ts.server.protocol.FileLocationRequestArgs,\n ts.server.protocol.ImplementationResponse,\n ];\n [CommandTypes.JsxClosingTag]: [ts.server.protocol.JsxClosingTagRequestArgs, ts.server.protocol.JsxClosingTagResponse];\n [CommandTypes.Navto]: [ts.server.protocol.NavtoRequestArgs, ts.server.protocol.NavtoResponse];\n [CommandTypes.NavTree]: [ts.server.protocol.FileRequestArgs, ts.server.protocol.NavTreeResponse];\n [CommandTypes.OrganizeImports]: [\n ts.server.protocol.OrganizeImportsRequestArgs,\n ts.server.protocol.OrganizeImportsResponse,\n ];\n [CommandTypes.PrepareCallHierarchy]: [\n ts.server.protocol.FileLocationRequestArgs,\n ts.server.protocol.PrepareCallHierarchyResponse,\n ];\n [CommandTypes.ProvideCallHierarchyIncomingCalls]: [\n ts.server.protocol.FileLocationRequestArgs,\n ts.server.protocol.ProvideCallHierarchyIncomingCallsResponse,\n ];\n [CommandTypes.ProvideCallHierarchyOutgoingCalls]: [\n ts.server.protocol.FileLocationRequestArgs,\n ts.server.protocol.ProvideCallHierarchyOutgoingCallsResponse,\n ];\n [CommandTypes.ProjectInfo]: [ts.server.protocol.ProjectInfoRequestArgs, ts.server.protocol.ProjectInfoResponse];\n [CommandTypes.ProvideInlayHints]: [ts.server.protocol.InlayHintsRequestArgs, ts.server.protocol.InlayHintsResponse];\n [CommandTypes.Quickinfo]: [ts.server.protocol.FileLocationRequestArgs, ts.server.protocol.QuickInfoResponse];\n [CommandTypes.References]: [ts.server.protocol.FileLocationRequestArgs, ts.server.protocol.ReferencesResponse];\n [CommandTypes.Rename]: [ts.server.protocol.RenameRequestArgs, ts.server.protocol.RenameResponse];\n [CommandTypes.SelectionRange]: [\n ts.server.protocol.SelectionRangeRequestArgs,\n ts.server.protocol.SelectionRangeResponse,\n ];\n [CommandTypes.SignatureHelp]: [ts.server.protocol.SignatureHelpRequestArgs, ts.server.protocol.SignatureHelpResponse];\n [CommandTypes.TypeDefinition]: [\n ts.server.protocol.FileLocationRequestArgs,\n ts.server.protocol.TypeDefinitionResponse,\n ];\n [CommandTypes.UpdateOpen]: [ts.server.protocol.UpdateOpenRequestArgs, ts.server.protocol.Response];\n}\n\nexport interface NoResponseTsServerRequests {\n [CommandTypes.Change]: [ts.server.protocol.ChangeRequestArgs, null];\n [CommandTypes.Close]: [ts.server.protocol.FileRequestArgs, null];\n [CommandTypes.CompilerOptionsForInferredProjects]: [\n ts.server.protocol.SetCompilerOptionsForInferredProjectsArgs,\n ts.server.protocol.SetCompilerOptionsForInferredProjectsResponse,\n ];\n [CommandTypes.Configure]: [ts.server.protocol.ConfigureRequestArguments, ts.server.protocol.ConfigureResponse];\n [CommandTypes.ConfigurePlugin]: [\n ts.server.protocol.ConfigurePluginRequestArguments,\n ts.server.protocol.ConfigurePluginResponse,\n ];\n [CommandTypes.Open]: [ts.server.protocol.OpenRequestArgs, null];\n}\n\nexport interface AsyncTsServerRequests {\n [CommandTypes.Geterr]: [ts.server.protocol.GeterrRequestArgs, ts.server.protocol.Response];\n [CommandTypes.GeterrForProject]: [ts.server.protocol.GeterrForProjectRequestArgs, ts.server.protocol.Response];\n}\n\nexport type TypeScriptRequestTypes = StandardTsServerRequests & NoResponseTsServerRequests & AsyncTsServerRequests;\n\nexport class ProcessBasedTsServer {\n private readlineInterface: readline.ReadLine | null;\n private tsServerProcess: cp.ChildProcess | null;\n private seq = 0;\n\n private readonly deferreds: {\n [seq: number]: Deferred<any>;\n } = {};\n\n private logger: Logger;\n private cancellationPipeName: string | undefined;\n\n constructor(\n private options: TspClientOptions,\n private tsServerArgs: TsServerArgs = {}\n ) {\n this.logger = options.logger;\n }\n\n async restart() {\n this.kill();\n await this.start();\n }\n\n start() {\n return new Promise<void>((resolve, reject) => {\n if (this.tsServerProcess) {\n reject(new Error('server already started'));\n return;\n }\n\n const { tsserverPath } = this.options;\n const { logFile, logVerbosity, maxTsServerMemory, globalPlugins, pluginProbeLocations } = this.tsServerArgs;\n const args: string[] = [];\n if (logFile) {\n args.push('--logFile', logFile);\n }\n if (logVerbosity) {\n args.push('--logVerbosity', logVerbosity);\n }\n if (globalPlugins && globalPlugins.length) {\n args.push('--globalPlugins', globalPlugins.join(','));\n }\n if (pluginProbeLocations && pluginProbeLocations.length) {\n args.push('--pluginProbeLocations', pluginProbeLocations.join(','));\n }\n this.cancellationPipeName = tempy.file({ name: 'tscancellation' });\n args.push('--cancellationPipeName', `${this.cancellationPipeName}*`);\n this.logger.info(`Starting tsserver : '${tsserverPath} ${args.join(' ')}'`);\n const tsserverPathIsModule = path.extname(tsserverPath) === '.js';\n const options = {\n silent: true,\n execArgv: maxTsServerMemory ? [`--max-old-space-size=${maxTsServerMemory}`] : [],\n };\n this.tsServerProcess = tsserverPathIsModule ? cp.fork(tsserverPath, args, options) : cp.spawn(tsserverPath, args);\n\n this.readlineInterface = readline.createInterface(\n this.tsServerProcess.stdout as Readable,\n this.tsServerProcess.stdin as Writable,\n undefined\n );\n process.on('exit', () => {\n this.kill();\n reject(new Error('TSServer was killed'));\n });\n\n this.readlineInterface.on('line', (line) => {\n this.processMessage(line, resolve, reject);\n });\n\n const dec = new decoder.StringDecoder('utf-8');\n this.tsServerProcess.stderr?.addListener('data', (data) => {\n const stringMsg = typeof data === 'string' ? data : dec.write(data);\n this.logger.error(stringMsg);\n reject(new Error(stringMsg));\n });\n });\n }\n\n async notify(command: CommandTypes.Open, args: ts.server.protocol.OpenRequestArgs): Promise<void>;\n async notify(command: CommandTypes.Close, args: ts.server.protocol.FileRequestArgs): Promise<void>;\n async notify(command: CommandTypes.Saveto, args: ts.server.protocol.SavetoRequestArgs): Promise<void>;\n async notify(command: CommandTypes.Change, args: ts.server.protocol.ChangeRequestArgs): Promise<void>;\n async notify(command: string, args: any): Promise<void> {\n await this.ensureServerIsRunning();\n this.sendMessage(command, true, args);\n }\n\n async request<K extends keyof TypeScriptRequestTypes>(\n command: K,\n args: TypeScriptRequestTypes[K][0],\n token?: CancellationToken\n ): Promise<TypeScriptRequestTypes[K][1]> {\n await this.ensureServerIsRunning();\n this.sendMessage(command, false, args);\n const seq = this.seq;\n const deferred = new Deferred<TypeScriptRequestTypes[K][1]>();\n this.deferreds[seq] = deferred;\n const request = deferred.promise;\n\n let onCancelled;\n if (token) {\n onCancelled = token.onCancellationRequested(() => {\n onCancelled.dispose();\n if (this.cancellationPipeName) {\n const requestCancellationPipeName = `${this.cancellationPipeName}${seq}`;\n fs.writeFile(requestCancellationPipeName, '', (err) => {\n if (!err) {\n // eslint-disable-next-line\n request.then(() =>\n fs.unlink(requestCancellationPipeName, () => {\n /* no-op */\n })\n );\n }\n });\n }\n });\n }\n\n try {\n const result = await request;\n onCancelled?.dispose();\n return result;\n } catch (error) {\n this.logger.error(`Error in request: ${error}`);\n throw error;\n }\n }\n\n kill() {\n this.tsServerProcess?.kill();\n this.tsServerProcess?.stdin?.destroy();\n this.readlineInterface?.close();\n this.tsServerProcess = null;\n this.readlineInterface = null;\n }\n\n private log(msg: string, obj: Record<string, any> = {}) {\n msg = `[tsserver] ${msg}`;\n if (this.options.logToConsole) {\n this.logger.console(`${msg} ${JSON.stringify(obj, undefined, 4)}`);\n } else {\n this.logger.trace(msg, obj);\n }\n }\n\n protected sendMessage(command: string, notification: boolean, args?: any): void {\n this.seq += 1;\n const request: ts.server.protocol.Request = {\n command,\n seq: this.seq,\n type: 'request',\n };\n if (args) {\n request.arguments = args;\n }\n const serializedRequest = `${JSON.stringify(request)}\\n`;\n this.tsServerProcess?.stdin?.write(serializedRequest);\n this.log(notification ? 'notify' : 'request', request);\n }\n\n protected processMessage(untrimmedMessageString: string, resolve?: () => void, reject?: (err) => void): void {\n const messageString = untrimmedMessageString.trim();\n if (!messageString || messageString.startsWith('Content-Length:')) {\n return;\n }\n let message: ts.server.protocol.Message;\n\n try {\n message = JSON.parse(messageString);\n } catch {\n // If the message isn't valid JSON, it's not a valid tsserver message. Reject the promise.\n reject?.(new Error(`Received invalid message from TSServer: ${untrimmedMessageString}`));\n return;\n }\n\n this.log('processMessage', message);\n\n if (this.isEvent(message)) {\n resolve?.();\n }\n\n if (this.isResponse(message)) {\n this.resolveResponse(message, message.request_seq, message.success);\n } else if (this.isEvent(message)) {\n if (this.isRequestCompletedEvent(message)) {\n this.resolveResponse(message, message.body.request_seq, true);\n } else if (this.options.onEvent) {\n this.options.onEvent(message);\n }\n }\n }\n\n private resolveResponse(message: ts.server.protocol.Message, request_seq: number, success: boolean) {\n const deferred = this.deferreds[request_seq];\n this.log('request completed', { request_seq, success });\n if (deferred) {\n if (success) {\n this.deferreds[request_seq].resolve(message);\n } else {\n this.deferreds[request_seq].reject(message);\n }\n delete this.deferreds[request_seq];\n }\n }\n\n private isEvent(message: ts.server.protocol.Message): message is ts.server.protocol.Event {\n return message.type === 'event';\n }\n\n private isResponse(message: ts.server.protocol.Message): message is ts.server.protocol.Response {\n return message.type === 'response';\n }\n\n private isRequestCompletedEvent(\n message: ts.server.protocol.Message\n ): message is ts.server.protocol.RequestCompletedEvent {\n return this.isEvent(message) && message.event === 'requestCompleted';\n }\n\n private async ensureServerIsRunning() {\n if (!this.tsServerProcess) {\n await this.restart();\n }\n }\n}\n"],"mappings":";;;;;;AAWA,SAAAA,GAAA;EAAA,MAAAC,IAAA,GAAAC,uBAAA,CAAAC,OAAA;EAAAH,EAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,KAAA;EAAA,MAAAH,IAAA,GAAAC,uBAAA,CAAAC,OAAA;EAAAC,IAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,GAAA;EAAA,MAAAJ,IAAA,GAAAC,uBAAA,CAAAC,OAAA;EAAAE,EAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,SAAA;EAAA,MAAAL,IAAA,GAAAC,uBAAA,CAAAC,OAAA;EAAAG,QAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA,SAAAM,QAAA;EAAA,MAAAN,IAAA,GAAAC,uBAAA,CAAAC,OAAA;EAAAI,OAAA,YAAAA,CAAA;IAAA,OAAAN,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAO,OAAA;EAAA,MAAAP,IAAA,GAAAQ,sBAAA,CAAAN,OAAA;EAAAK,MAAA,YAAAA,CAAA;IAAA,OAAAP,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;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,KAAK,kBAAkB;EACtE;EAEA,MAAc5C,qBAAqBA,CAAA,EAAG;IACpC,IAAI,CAAC,IAAI,CAACzC,eAAe,EAAE;MACzB,MAAM,IAAI,CAACN,OAAO,CAAC,CAAC;IACtB;EACF;AACF;AAAC4F,OAAA,CAAAnG,oBAAA,GAAAA,oBAAA","ignoreList":[]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Logger } from '@teambit/logger';
|
|
1
|
+
import type { 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
|
+
import type { Diagnostic } from './format-diagnostics';
|
|
6
6
|
export type TsserverClientOpts = {
|
|
7
7
|
verbose?: boolean;
|
|
8
8
|
tsServerPath?: string;
|
|
@@ -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","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,I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AAO,CAAC2G,uBAAuB,EAAE;QACxC,IAAI,CAAC/G,cAAc,CAACoF,IAAI,CAAC;UACvB5D,IAAI;UACJ6F,UAAU,EAAEH,IAAI;UAChBC;QACF,CAAC,CAAC;MACJ;IACF,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;EACUzG,gBAAgBA,CAAA,EAAW;IACjC,IAAI,IAAI,CAACN,OAAO,CAACkH,YAAY,EAAE;MAC7B,OAAO,IAAI,CAAClH,OAAO,CAACkH,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,IAAI7F,KAAK,CAAC,kBAAkB,IAAA6F,8BAAqB,EAAC,CAAC,sCAAsC,CAAC;EAClG;AACF;AAACC,OAAA,CAAAhI,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 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 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,S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,OAAO,CAAEC,IAAI,IAAK;MACzC,MAAMC,SAAS,GAAG,IAAAC,qCAAgB,EAACF,IAAI,EAAE1F,IAAI,CAAC;MAC9C,IAAI,IAAI,CAACpB,OAAO,CAAC0G,eAAe,EAAE;QAChC,IAAI,CAAC3G,MAAM,CAACuC,OAAO,CAACyE,SAAS,CAAC;MAChC;MACA,IAAI,IAAI,CAAC/G,OAAO,CAAC2G,uBAAuB,EAAE;QACxC,IAAI,CAAC/G,cAAc,CAACoF,IAAI,CAAC;UACvB5D,IAAI;UACJ6F,UAAU,EAAEH,IAAI;UAChBC;QACF,CAAC,CAAC;MACJ;IACF,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;EACUzG,gBAAgBA,CAAA,EAAW;IACjC,IAAI,IAAI,CAACN,OAAO,CAACkH,YAAY,EAAE;MAC7B,OAAO,IAAI,CAAClH,OAAO,CAACkH,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,IAAI7F,KAAK,CAAC,kBAAkB,IAAA6F,8BAAqB,EAAC,CAAC,sCAAsC,CAAC;EAClG;AACF;AAACC,OAAA,CAAAhI,cAAA,GAAAA,cAAA","ignoreList":[]}
|
package/format-diagnostics.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/ts-server",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.66",
|
|
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.66"
|
|
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.
|
|
23
|
+
"@teambit/node.envs.node-babel-mocha": "0.1.18"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {},
|
|
26
26
|
"license": "Apache-2.0",
|
|
@@ -13,13 +13,13 @@ import * as fs from 'fs';
|
|
|
13
13
|
import * as path from 'path';
|
|
14
14
|
import * as cp from 'child_process';
|
|
15
15
|
import * as readline from 'readline';
|
|
16
|
-
import { Logger } from '@teambit/logger';
|
|
17
|
-
import { Readable, Writable } from 'stream';
|
|
16
|
+
import type { Logger } from '@teambit/logger';
|
|
17
|
+
import type { Readable, Writable } from 'stream';
|
|
18
18
|
import * as decoder from 'string_decoder';
|
|
19
19
|
import type ts from 'typescript/lib/tsserverlibrary';
|
|
20
20
|
import tempy from 'tempy';
|
|
21
|
-
import { CancellationToken } from 'vscode-jsonrpc';
|
|
22
|
-
import { CommandTypes } from './tsp-command-types';
|
|
21
|
+
import type { CancellationToken } from 'vscode-jsonrpc';
|
|
22
|
+
import type { CommandTypes } from './tsp-command-types';
|
|
23
23
|
import { Deferred } from './utils';
|
|
24
24
|
|
|
25
25
|
export interface TspClientOptions {
|
package/ts-server-client.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fs from 'fs-extra';
|
|
2
|
-
import { Logger } from '@teambit/logger';
|
|
2
|
+
import type { Logger } from '@teambit/logger';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import type ts from 'typescript/lib/tsserverlibrary';
|
|
5
5
|
import { CheckTypes } from '@teambit/watcher';
|
|
@@ -9,7 +9,8 @@ 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 {
|
|
12
|
+
import type { Diagnostic } from './format-diagnostics';
|
|
13
|
+
import { formatDiagnostic } from './format-diagnostics';
|
|
13
14
|
|
|
14
15
|
export type TsserverClientOpts = {
|
|
15
16
|
verbose?: boolean; // print tsserver events to the console.
|