From df65cc31207b4b1ab0229db51e66f3c14a01124d Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 7 Nov 2016 16:05:21 -0800 Subject: [PATCH] Update LKG --- lib/protocol.d.ts | 20 +++++++ lib/tsc.js | 10 +++- lib/tsserver.js | 114 +++++++++++++++++++++++++++--------- lib/tsserverlibrary.d.ts | 39 +++++++++++- lib/tsserverlibrary.js | 57 ++++++++++++++---- lib/typescript.d.ts | 6 +- lib/typescript.js | 12 ++-- lib/typescriptServices.d.ts | 6 +- lib/typescriptServices.js | 12 ++-- lib/typingsInstaller.js | 64 ++++++++++++++------ 10 files changed, 269 insertions(+), 71 deletions(-) diff --git a/lib/protocol.d.ts b/lib/protocol.d.ts index 603ee14effd..72b0608188e 100644 --- a/lib/protocol.d.ts +++ b/lib/protocol.d.ts @@ -1524,6 +1524,26 @@ declare namespace ts.server.protocol { spans: TextSpan[]; childItems?: NavigationTree[]; } + type TelemetryEventName = "telemetry"; + interface TelemetryEvent extends Event { + event: TelemetryEventName; + body: TelemetryEventBody; + } + interface TelemetryEventBody { + telemetryEventName: string; + payload: any; + } + type TypingsInstalledTelemetryEventName = "typingsInstalled"; + interface TypingsInstalledTelemetryEventBody extends TelemetryEventBody { + telemetryEventName: TypingsInstalledTelemetryEventName; + payload: TypingsInstalledTelemetryEventPayload; + } + interface TypingsInstalledTelemetryEventPayload { + /** + * Comma separated list of installed typing packages + */ + installedPackages: string; + } interface NavBarResponse extends Response { body?: NavigationBarItem[]; } diff --git a/lib/tsc.js b/lib/tsc.js index fff7700b2be..fa6fd2d9051 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -1689,7 +1689,7 @@ var ts; }, readFile: readFile, writeFile: writeFile, - watchFile: function (fileName, callback) { + watchFile: function (fileName, callback, pollingInterval) { if (useNonPollingWatchers) { var watchedFile_1 = watchedFileSet.addFile(fileName, callback); return { @@ -1697,7 +1697,7 @@ var ts; }; } else { - _fs.watchFile(fileName, { persistent: true, interval: 250 }, fileChanged); + _fs.watchFile(fileName, { persistent: true, interval: pollingInterval || 250 }, fileChanged); return { close: function () { return _fs.unwatchFile(fileName, fileChanged); } }; @@ -37592,6 +37592,7 @@ var ts; getTypeCount: function () { return getDiagnosticsProducingTypeChecker().getTypeCount(); }, getFileProcessingDiagnostics: function () { return fileProcessingDiagnostics; }, getResolvedTypeReferenceDirectives: function () { return resolvedTypeReferenceDirectives; }, + isSourceFileFromExternalLibrary: isSourceFileFromExternalLibrary, dropDiagnosticsProducingTypeChecker: dropDiagnosticsProducingTypeChecker }; verifyCompilerOptions(); @@ -37731,11 +37732,14 @@ var ts; getSourceFile: program.getSourceFile, getSourceFileByPath: program.getSourceFileByPath, getSourceFiles: program.getSourceFiles, - isSourceFileFromExternalLibrary: function (file) { return !!sourceFilesFoundSearchingNodeModules[file.path]; }, + isSourceFileFromExternalLibrary: isSourceFileFromExternalLibrary, writeFile: writeFileCallback || (function (fileName, data, writeByteOrderMark, onError, sourceFiles) { return host.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles); }), isEmitBlocked: isEmitBlocked }; } + function isSourceFileFromExternalLibrary(file) { + return sourceFilesFoundSearchingNodeModules[file.path]; + } function getDiagnosticsProducingTypeChecker() { return diagnosticsProducingTypeChecker || (diagnosticsProducingTypeChecker = ts.createTypeChecker(program, true)); } diff --git a/lib/tsserver.js b/lib/tsserver.js index 9ce9c5c7140..11d6df676e3 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -1694,7 +1694,7 @@ var ts; }, readFile: readFile, writeFile: writeFile, - watchFile: function (fileName, callback) { + watchFile: function (fileName, callback, pollingInterval) { if (useNonPollingWatchers) { var watchedFile_1 = watchedFileSet.addFile(fileName, callback); return { @@ -1702,7 +1702,7 @@ var ts; }; } else { - _fs.watchFile(fileName, { persistent: true, interval: 250 }, fileChanged); + _fs.watchFile(fileName, { persistent: true, interval: pollingInterval || 250 }, fileChanged); return { close: function () { return _fs.unwatchFile(fileName, fileChanged); } }; @@ -5145,7 +5145,7 @@ var ts; mergeTypings(typingOptions.include); exclude = typingOptions.exclude || []; var possibleSearchDirs = ts.map(fileNames, ts.getDirectoryPath); - if (projectRootPath !== undefined) { + if (projectRootPath) { possibleSearchDirs.push(projectRootPath); } searchDirs = ts.deduplicate(possibleSearchDirs); @@ -5262,6 +5262,32 @@ var ts; })(JsTyping = ts.JsTyping || (ts.JsTyping = {})); })(ts || (ts = {})); var ts; +(function (ts) { + var server; + (function (server) { + server.ActionSet = "action::set"; + server.ActionInvalidate = "action::invalidate"; + server.EventInstall = "event::install"; + var Arguments; + (function (Arguments) { + Arguments.GlobalCacheLocation = "--globalTypingsCacheLocation"; + Arguments.LogFile = "--logFile"; + Arguments.EnableTelemetry = "--enableTelemetry"; + })(Arguments = server.Arguments || (server.Arguments = {})); + function hasArgument(argumentName) { + return ts.sys.args.indexOf(argumentName) >= 0; + } + server.hasArgument = hasArgument; + function findArgument(argumentName) { + var index = ts.sys.args.indexOf(argumentName); + return index >= 0 && index < ts.sys.args.length - 1 + ? ts.sys.args[index + 1] + : undefined; + } + server.findArgument = findArgument; + })(server = ts.server || (ts.server = {})); +})(ts || (ts = {})); +var ts; (function (ts) { var server; (function (server) { @@ -5293,7 +5319,7 @@ var ts; function createInstallTypingsRequest(project, typingOptions, cachePath) { return { projectName: project.getProjectName(), - fileNames: project.getFileNames(), + fileNames: project.getFileNames(true), compilerOptions: project.getCompilerOptions(), typingOptions: typingOptions, projectRootPath: getProjectRootPath(project), @@ -38981,6 +39007,7 @@ var ts; getTypeCount: function () { return getDiagnosticsProducingTypeChecker().getTypeCount(); }, getFileProcessingDiagnostics: function () { return fileProcessingDiagnostics; }, getResolvedTypeReferenceDirectives: function () { return resolvedTypeReferenceDirectives; }, + isSourceFileFromExternalLibrary: isSourceFileFromExternalLibrary, dropDiagnosticsProducingTypeChecker: dropDiagnosticsProducingTypeChecker }; verifyCompilerOptions(); @@ -39120,11 +39147,14 @@ var ts; getSourceFile: program.getSourceFile, getSourceFileByPath: program.getSourceFileByPath, getSourceFiles: program.getSourceFiles, - isSourceFileFromExternalLibrary: function (file) { return !!sourceFilesFoundSearchingNodeModules[file.path]; }, + isSourceFileFromExternalLibrary: isSourceFileFromExternalLibrary, writeFile: writeFileCallback || (function (fileName, data, writeByteOrderMark, onError, sourceFiles) { return host.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles); }), isEmitBlocked: isEmitBlocked }; } + function isSourceFileFromExternalLibrary(file) { + return sourceFilesFoundSearchingNodeModules[file.path]; + } function getDiagnosticsProducingTypeChecker() { return diagnosticsProducingTypeChecker || (diagnosticsProducingTypeChecker = ts.createTypeChecker(program, true)); } @@ -52462,7 +52492,7 @@ var ts; } return this.getLanguageService().getEmitOutput(info.fileName, emitOnlyDtsFiles); }; - Project.prototype.getFileNames = function () { + Project.prototype.getFileNames = function (excludeFilesFromExternalLibraries) { if (!this.program) { return []; } @@ -52476,8 +52506,15 @@ var ts; } return rootFiles; } - var sourceFiles = this.program.getSourceFiles(); - return sourceFiles.map(function (sourceFile) { return server.asNormalizedPath(sourceFile.fileName); }); + var result = []; + for (var _i = 0, _a = this.program.getSourceFiles(); _i < _a.length; _i++) { + var f = _a[_i]; + if (excludeFilesFromExternalLibraries && this.program.isSourceFileFromExternalLibrary(f)) { + continue; + } + result.push(server.asNormalizedPath(f.fileName)); + } + return result; }; Project.prototype.getAllEmittableFiles = function () { if (!this.languageServiceEnabled) { @@ -53067,11 +53104,11 @@ var ts; return; } switch (response.kind) { - case "set": + case server.ActionSet: this.typingsCache.updateTypingsForProject(response.projectName, response.compilerOptions, response.typingOptions, response.typings); project.updateGraph(); break; - case "invalidate": + case server.ActionInvalidate: this.typingsCache.invalidateCachedTypingsForProject(project); break; } @@ -56241,8 +56278,9 @@ var ts; return Logger; }()); var NodeTypingsInstaller = (function () { - function NodeTypingsInstaller(logger, eventPort, globalTypingsCacheLocation, newLine) { + function NodeTypingsInstaller(telemetryEnabled, logger, eventPort, globalTypingsCacheLocation, newLine) { var _this = this; + this.telemetryEnabled = telemetryEnabled; this.logger = logger; this.eventPort = eventPort; this.globalTypingsCacheLocation = globalTypingsCacheLocation; @@ -56253,15 +56291,21 @@ var ts; }); } } + NodeTypingsInstaller.prototype.setTelemetrySender = function (telemetrySender) { + this.telemetrySender = telemetrySender; + }; NodeTypingsInstaller.prototype.attach = function (projectService) { var _this = this; this.projectService = projectService; if (this.logger.hasLevel(server.LogLevel.requestTime)) { this.logger.info("Binding..."); } - var args = ["--globalTypingsCacheLocation", this.globalTypingsCacheLocation]; + var args = [server.Arguments.GlobalCacheLocation, this.globalTypingsCacheLocation]; + if (this.telemetryEnabled) { + args.push(server.Arguments.EnableTelemetry); + } if (this.logger.loggingEnabled() && this.logger.getLogFileName()) { - args.push("--logFile", ts.combinePaths(ts.getDirectoryPath(ts.normalizeSlashes(this.logger.getLogFileName())), "ti-" + process.pid + ".log")); + args.push(server.Arguments.LogFile, ts.combinePaths(ts.getDirectoryPath(ts.normalizeSlashes(this.logger.getLogFileName())), "ti-" + process.pid + ".log")); } var execArgv = []; { @@ -56297,8 +56341,21 @@ var ts; if (this.logger.hasLevel(server.LogLevel.verbose)) { this.logger.info("Received response: " + JSON.stringify(response)); } + if (response.kind === server.EventInstall) { + if (this.telemetrySender) { + var body = { + telemetryEventName: "typingsInstalled", + payload: { + installedPackages: response.packagesToInstall.join(",") + } + }; + var eventName = "telemetry"; + this.telemetrySender.event(body, eventName); + } + return; + } this.projectService.updateTypingsForProject(response); - if (response.kind == "set" && this.socket) { + if (response.kind == server.ActionSet && this.socket) { this.socket.write(server.formatMessage({ seq: 0, type: "event", message: response }, this.logger, Buffer.byteLength, this.newLine), "utf8"); } }; @@ -56306,10 +56363,14 @@ var ts; }()); var IOSession = (function (_super) { __extends(IOSession, _super); - function IOSession(host, cancellationToken, installerEventPort, canUseEvents, useSingleInferredProject, disableAutomaticTypingAcquisition, globalTypingsCacheLocation, logger) { - _super.call(this, host, cancellationToken, useSingleInferredProject, disableAutomaticTypingAcquisition - ? server.nullTypingsInstaller - : new NodeTypingsInstaller(logger, installerEventPort, globalTypingsCacheLocation, host.newLine), Buffer.byteLength, process.hrtime, logger, canUseEvents); + function IOSession(host, cancellationToken, installerEventPort, canUseEvents, useSingleInferredProject, disableAutomaticTypingAcquisition, globalTypingsCacheLocation, telemetryEnabled, logger) { + var typingsInstaller = disableAutomaticTypingAcquisition + ? undefined + : new NodeTypingsInstaller(telemetryEnabled, logger, installerEventPort, globalTypingsCacheLocation, host.newLine); + _super.call(this, host, cancellationToken, useSingleInferredProject, typingsInstaller || server.nullTypingsInstaller, Buffer.byteLength, process.hrtime, logger, canUseEvents); + if (telemetryEnabled && typingsInstaller) { + typingsInstaller.setTelemetrySender(this); + } } IOSession.prototype.exit = function () { this.logger.info("Exiting..."); @@ -56489,17 +56550,16 @@ var ts; ; var eventPort; { - var index = sys.args.indexOf("--eventPort"); - if (index >= 0 && index < sys.args.length - 1) { - var v = parseInt(sys.args[index + 1]); - if (!isNaN(v)) { - eventPort = v; - } + var str = server.findArgument("--eventPort"); + var v = str && parseInt(str); + if (!isNaN(v)) { + eventPort = v; } } - var useSingleInferredProject = sys.args.indexOf("--useSingleInferredProject") >= 0; - var disableAutomaticTypingAcquisition = sys.args.indexOf("--disableAutomaticTypingAcquisition") >= 0; - var ioSession = new IOSession(sys, cancellationToken, eventPort, eventPort === undefined, useSingleInferredProject, disableAutomaticTypingAcquisition, getGlobalTypingsCacheLocation(), logger); + var useSingleInferredProject = server.hasArgument("--useSingleInferredProject"); + var disableAutomaticTypingAcquisition = server.hasArgument("--disableAutomaticTypingAcquisition"); + var telemetryEnabled = server.hasArgument(server.Arguments.EnableTelemetry); + var ioSession = new IOSession(sys, cancellationToken, eventPort, eventPort === undefined, useSingleInferredProject, disableAutomaticTypingAcquisition, getGlobalTypingsCacheLocation(), telemetryEnabled, logger); process.on("uncaughtException", function (err) { ioSession.logError(err, "unknown"); }); diff --git a/lib/tsserverlibrary.d.ts b/lib/tsserverlibrary.d.ts index a07ac624951..80b05d8f955 100644 --- a/lib/tsserverlibrary.d.ts +++ b/lib/tsserverlibrary.d.ts @@ -647,6 +647,23 @@ declare namespace ts.server.protocol { spans: TextSpan[]; childItems?: NavigationTree[]; } + type TelemetryEventName = "telemetry"; + interface TelemetryEvent extends Event { + event: TelemetryEventName; + body: TelemetryEventBody; + } + interface TelemetryEventBody { + telemetryEventName: string; + payload: any; + } + type TypingsInstalledTelemetryEventName = "typingsInstalled"; + interface TypingsInstalledTelemetryEventBody extends TelemetryEventBody { + telemetryEventName: TypingsInstalledTelemetryEventName; + payload: TypingsInstalledTelemetryEventPayload; + } + interface TypingsInstalledTelemetryEventPayload { + installedPackages: string; + } interface NavBarResponse extends Response { body?: NavigationBarItem[]; } @@ -1974,6 +1991,7 @@ declare namespace ts { getTypeCount(): number; getFileProcessingDiagnostics(): DiagnosticCollection; getResolvedTypeReferenceDirectives(): Map; + isSourceFileFromExternalLibrary(file: SourceFile): boolean; structureIsReused?: boolean; } interface SourceMapSpan { @@ -3096,7 +3114,7 @@ declare namespace ts { readFile(path: string, encoding?: string): string; getFileSize?(path: string): number; writeFile(path: string, data: string, writeByteOrderMark?: boolean): void; - watchFile?(path: string, callback: FileWatcherCallback): FileWatcher; + watchFile?(path: string, callback: FileWatcherCallback, pollingInterval?: number): FileWatcher; watchDirectory?(path: string, callback: DirectoryWatcherCallback, recursive?: boolean): FileWatcher; resolvePath(path: string): string; fileExists(path: string): boolean; @@ -7813,6 +7831,18 @@ declare namespace ts.JsTyping { filesToWatch: string[]; }; } +declare namespace ts.server { + const ActionSet: ActionSet; + const ActionInvalidate: ActionInvalidate; + const EventInstall: EventInstall; + namespace Arguments { + const GlobalCacheLocation: string; + const LogFile: string; + const EnableTelemetry: string; + } + function hasArgument(argumentName: string): boolean; + function findArgument(argumentName: string): string; +} declare namespace ts.server { enum LogLevel { terse = 0, @@ -9513,7 +9543,7 @@ declare namespace ts.server { getRootScriptInfos(): ScriptInfo[]; getScriptInfos(): ScriptInfo[]; getFileEmitOutput(info: ScriptInfo, emitOnlyDtsFiles: boolean): EmitOutput; - getFileNames(): NormalizedPath[]; + getFileNames(excludeFilesFromExternalLibraries?: boolean): NormalizedPath[]; getAllEmittableFiles(): string[]; containsScriptInfo(info: ScriptInfo): boolean; containsFile(filename: NormalizedPath, requireOpen?: boolean): boolean; @@ -9702,6 +9732,9 @@ declare namespace ts.server { fileName: NormalizedPath; project: Project; } + interface EventSender { + event(payload: any, eventName: string): void; + } namespace CommandNames { const Brace: protocol.CommandTypes.Brace; const BraceFull: protocol.CommandTypes.BraceFull; @@ -9768,7 +9801,7 @@ declare namespace ts.server { const CompilerOptionsForInferredProjects: protocol.CommandTypes.CompilerOptionsForInferredProjects; } function formatMessage(msg: T, logger: server.Logger, byteLength: (s: string, encoding: string) => number, newLine: string): string; - class Session { + class Session implements EventSender { private host; protected readonly typingsInstaller: ITypingsInstaller; private byteLength; diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index 8b468b42c4b..4b6a6dd43b8 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -1694,7 +1694,7 @@ var ts; }, readFile: readFile, writeFile: writeFile, - watchFile: function (fileName, callback) { + watchFile: function (fileName, callback, pollingInterval) { if (useNonPollingWatchers) { var watchedFile_1 = watchedFileSet.addFile(fileName, callback); return { @@ -1702,7 +1702,7 @@ var ts; }; } else { - _fs.watchFile(fileName, { persistent: true, interval: 250 }, fileChanged); + _fs.watchFile(fileName, { persistent: true, interval: pollingInterval || 250 }, fileChanged); return { close: function () { return _fs.unwatchFile(fileName, fileChanged); } }; @@ -5145,7 +5145,7 @@ var ts; mergeTypings(typingOptions.include); exclude = typingOptions.exclude || []; var possibleSearchDirs = ts.map(fileNames, ts.getDirectoryPath); - if (projectRootPath !== undefined) { + if (projectRootPath) { possibleSearchDirs.push(projectRootPath); } searchDirs = ts.deduplicate(possibleSearchDirs); @@ -5262,6 +5262,32 @@ var ts; })(JsTyping = ts.JsTyping || (ts.JsTyping = {})); })(ts || (ts = {})); var ts; +(function (ts) { + var server; + (function (server) { + server.ActionSet = "action::set"; + server.ActionInvalidate = "action::invalidate"; + server.EventInstall = "event::install"; + var Arguments; + (function (Arguments) { + Arguments.GlobalCacheLocation = "--globalTypingsCacheLocation"; + Arguments.LogFile = "--logFile"; + Arguments.EnableTelemetry = "--enableTelemetry"; + })(Arguments = server.Arguments || (server.Arguments = {})); + function hasArgument(argumentName) { + return ts.sys.args.indexOf(argumentName) >= 0; + } + server.hasArgument = hasArgument; + function findArgument(argumentName) { + var index = ts.sys.args.indexOf(argumentName); + return index >= 0 && index < ts.sys.args.length - 1 + ? ts.sys.args[index + 1] + : undefined; + } + server.findArgument = findArgument; + })(server = ts.server || (ts.server = {})); +})(ts || (ts = {})); +var ts; (function (ts) { var server; (function (server) { @@ -5293,7 +5319,7 @@ var ts; function createInstallTypingsRequest(project, typingOptions, cachePath) { return { projectName: project.getProjectName(), - fileNames: project.getFileNames(), + fileNames: project.getFileNames(true), compilerOptions: project.getCompilerOptions(), typingOptions: typingOptions, projectRootPath: getProjectRootPath(project), @@ -38981,6 +39007,7 @@ var ts; getTypeCount: function () { return getDiagnosticsProducingTypeChecker().getTypeCount(); }, getFileProcessingDiagnostics: function () { return fileProcessingDiagnostics; }, getResolvedTypeReferenceDirectives: function () { return resolvedTypeReferenceDirectives; }, + isSourceFileFromExternalLibrary: isSourceFileFromExternalLibrary, dropDiagnosticsProducingTypeChecker: dropDiagnosticsProducingTypeChecker }; verifyCompilerOptions(); @@ -39120,11 +39147,14 @@ var ts; getSourceFile: program.getSourceFile, getSourceFileByPath: program.getSourceFileByPath, getSourceFiles: program.getSourceFiles, - isSourceFileFromExternalLibrary: function (file) { return !!sourceFilesFoundSearchingNodeModules[file.path]; }, + isSourceFileFromExternalLibrary: isSourceFileFromExternalLibrary, writeFile: writeFileCallback || (function (fileName, data, writeByteOrderMark, onError, sourceFiles) { return host.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles); }), isEmitBlocked: isEmitBlocked }; } + function isSourceFileFromExternalLibrary(file) { + return sourceFilesFoundSearchingNodeModules[file.path]; + } function getDiagnosticsProducingTypeChecker() { return diagnosticsProducingTypeChecker || (diagnosticsProducingTypeChecker = ts.createTypeChecker(program, true)); } @@ -52462,7 +52492,7 @@ var ts; } return this.getLanguageService().getEmitOutput(info.fileName, emitOnlyDtsFiles); }; - Project.prototype.getFileNames = function () { + Project.prototype.getFileNames = function (excludeFilesFromExternalLibraries) { if (!this.program) { return []; } @@ -52476,8 +52506,15 @@ var ts; } return rootFiles; } - var sourceFiles = this.program.getSourceFiles(); - return sourceFiles.map(function (sourceFile) { return server.asNormalizedPath(sourceFile.fileName); }); + var result = []; + for (var _i = 0, _a = this.program.getSourceFiles(); _i < _a.length; _i++) { + var f = _a[_i]; + if (excludeFilesFromExternalLibraries && this.program.isSourceFileFromExternalLibrary(f)) { + continue; + } + result.push(server.asNormalizedPath(f.fileName)); + } + return result; }; Project.prototype.getAllEmittableFiles = function () { if (!this.languageServiceEnabled) { @@ -53067,11 +53104,11 @@ var ts; return; } switch (response.kind) { - case "set": + case server.ActionSet: this.typingsCache.updateTypingsForProject(response.projectName, response.compilerOptions, response.typingOptions, response.typings); project.updateGraph(); break; - case "invalidate": + case server.ActionInvalidate: this.typingsCache.invalidateCachedTypingsForProject(project); break; } diff --git a/lib/typescript.d.ts b/lib/typescript.d.ts index ab4ffc4e48d..39d6b7421c8 100644 --- a/lib/typescript.d.ts +++ b/lib/typescript.d.ts @@ -1774,7 +1774,11 @@ declare namespace ts { readFile(path: string, encoding?: string): string; getFileSize?(path: string): number; writeFile(path: string, data: string, writeByteOrderMark?: boolean): void; - watchFile?(path: string, callback: FileWatcherCallback): FileWatcher; + /** + * @pollingInterval - this parameter is used in polling-based watchers and ignored in watchers that + * use native OS file watching + */ + watchFile?(path: string, callback: FileWatcherCallback, pollingInterval?: number): FileWatcher; watchDirectory?(path: string, callback: DirectoryWatcherCallback, recursive?: boolean): FileWatcher; resolvePath(path: string): string; fileExists(path: string): boolean; diff --git a/lib/typescript.js b/lib/typescript.js index 7c7360031d2..e703e860b73 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -2845,7 +2845,7 @@ var ts; }, readFile: readFile, writeFile: writeFile, - watchFile: function (fileName, callback) { + watchFile: function (fileName, callback, pollingInterval) { if (useNonPollingWatchers) { var watchedFile_1 = watchedFileSet.addFile(fileName, callback); return { @@ -2853,7 +2853,7 @@ var ts; }; } else { - _fs.watchFile(fileName, { persistent: true, interval: 250 }, fileChanged); + _fs.watchFile(fileName, { persistent: true, interval: pollingInterval || 250 }, fileChanged); return { close: function () { return _fs.unwatchFile(fileName, fileChanged); } }; @@ -45198,6 +45198,7 @@ var ts; getTypeCount: function () { return getDiagnosticsProducingTypeChecker().getTypeCount(); }, getFileProcessingDiagnostics: function () { return fileProcessingDiagnostics; }, getResolvedTypeReferenceDirectives: function () { return resolvedTypeReferenceDirectives; }, + isSourceFileFromExternalLibrary: isSourceFileFromExternalLibrary, dropDiagnosticsProducingTypeChecker: dropDiagnosticsProducingTypeChecker }; verifyCompilerOptions(); @@ -45360,11 +45361,14 @@ var ts; getSourceFile: program.getSourceFile, getSourceFileByPath: program.getSourceFileByPath, getSourceFiles: program.getSourceFiles, - isSourceFileFromExternalLibrary: function (file) { return !!sourceFilesFoundSearchingNodeModules[file.path]; }, + isSourceFileFromExternalLibrary: isSourceFileFromExternalLibrary, writeFile: writeFileCallback || (function (fileName, data, writeByteOrderMark, onError, sourceFiles) { return host.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles); }), isEmitBlocked: isEmitBlocked }; } + function isSourceFileFromExternalLibrary(file) { + return sourceFilesFoundSearchingNodeModules[file.path]; + } function getDiagnosticsProducingTypeChecker() { return diagnosticsProducingTypeChecker || (diagnosticsProducingTypeChecker = ts.createTypeChecker(program, /*produceDiagnostics:*/ true)); } @@ -50402,7 +50406,7 @@ var ts; mergeTypings(typingOptions.include); exclude = typingOptions.exclude || []; var possibleSearchDirs = ts.map(fileNames, ts.getDirectoryPath); - if (projectRootPath !== undefined) { + if (projectRootPath) { possibleSearchDirs.push(projectRootPath); } searchDirs = ts.deduplicate(possibleSearchDirs); diff --git a/lib/typescriptServices.d.ts b/lib/typescriptServices.d.ts index 5aa16737b67..2a99204dffa 100644 --- a/lib/typescriptServices.d.ts +++ b/lib/typescriptServices.d.ts @@ -1774,7 +1774,11 @@ declare namespace ts { readFile(path: string, encoding?: string): string; getFileSize?(path: string): number; writeFile(path: string, data: string, writeByteOrderMark?: boolean): void; - watchFile?(path: string, callback: FileWatcherCallback): FileWatcher; + /** + * @pollingInterval - this parameter is used in polling-based watchers and ignored in watchers that + * use native OS file watching + */ + watchFile?(path: string, callback: FileWatcherCallback, pollingInterval?: number): FileWatcher; watchDirectory?(path: string, callback: DirectoryWatcherCallback, recursive?: boolean): FileWatcher; resolvePath(path: string): string; fileExists(path: string): boolean; diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index 7c7360031d2..e703e860b73 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -2845,7 +2845,7 @@ var ts; }, readFile: readFile, writeFile: writeFile, - watchFile: function (fileName, callback) { + watchFile: function (fileName, callback, pollingInterval) { if (useNonPollingWatchers) { var watchedFile_1 = watchedFileSet.addFile(fileName, callback); return { @@ -2853,7 +2853,7 @@ var ts; }; } else { - _fs.watchFile(fileName, { persistent: true, interval: 250 }, fileChanged); + _fs.watchFile(fileName, { persistent: true, interval: pollingInterval || 250 }, fileChanged); return { close: function () { return _fs.unwatchFile(fileName, fileChanged); } }; @@ -45198,6 +45198,7 @@ var ts; getTypeCount: function () { return getDiagnosticsProducingTypeChecker().getTypeCount(); }, getFileProcessingDiagnostics: function () { return fileProcessingDiagnostics; }, getResolvedTypeReferenceDirectives: function () { return resolvedTypeReferenceDirectives; }, + isSourceFileFromExternalLibrary: isSourceFileFromExternalLibrary, dropDiagnosticsProducingTypeChecker: dropDiagnosticsProducingTypeChecker }; verifyCompilerOptions(); @@ -45360,11 +45361,14 @@ var ts; getSourceFile: program.getSourceFile, getSourceFileByPath: program.getSourceFileByPath, getSourceFiles: program.getSourceFiles, - isSourceFileFromExternalLibrary: function (file) { return !!sourceFilesFoundSearchingNodeModules[file.path]; }, + isSourceFileFromExternalLibrary: isSourceFileFromExternalLibrary, writeFile: writeFileCallback || (function (fileName, data, writeByteOrderMark, onError, sourceFiles) { return host.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles); }), isEmitBlocked: isEmitBlocked }; } + function isSourceFileFromExternalLibrary(file) { + return sourceFilesFoundSearchingNodeModules[file.path]; + } function getDiagnosticsProducingTypeChecker() { return diagnosticsProducingTypeChecker || (diagnosticsProducingTypeChecker = ts.createTypeChecker(program, /*produceDiagnostics:*/ true)); } @@ -50402,7 +50406,7 @@ var ts; mergeTypings(typingOptions.include); exclude = typingOptions.exclude || []; var possibleSearchDirs = ts.map(fileNames, ts.getDirectoryPath); - if (projectRootPath !== undefined) { + if (projectRootPath) { possibleSearchDirs.push(projectRootPath); } searchDirs = ts.deduplicate(possibleSearchDirs); diff --git a/lib/typingsInstaller.js b/lib/typingsInstaller.js index 3fcd60ae200..fdbb477291e 100644 --- a/lib/typingsInstaller.js +++ b/lib/typingsInstaller.js @@ -1694,7 +1694,7 @@ var ts; }, readFile: readFile, writeFile: writeFile, - watchFile: function (fileName, callback) { + watchFile: function (fileName, callback, pollingInterval) { if (useNonPollingWatchers) { var watchedFile_1 = watchedFileSet.addFile(fileName, callback); return { @@ -1702,7 +1702,7 @@ var ts; }; } else { - _fs.watchFile(fileName, { persistent: true, interval: 250 }, fileChanged); + _fs.watchFile(fileName, { persistent: true, interval: pollingInterval || 250 }, fileChanged); return { close: function () { return _fs.unwatchFile(fileName, fileChanged); } }; @@ -5145,7 +5145,7 @@ var ts; mergeTypings(typingOptions.include); exclude = typingOptions.exclude || []; var possibleSearchDirs = ts.map(fileNames, ts.getDirectoryPath); - if (projectRootPath !== undefined) { + if (projectRootPath) { possibleSearchDirs.push(projectRootPath); } searchDirs = ts.deduplicate(possibleSearchDirs); @@ -5262,6 +5262,32 @@ var ts; })(JsTyping = ts.JsTyping || (ts.JsTyping = {})); })(ts || (ts = {})); var ts; +(function (ts) { + var server; + (function (server) { + server.ActionSet = "action::set"; + server.ActionInvalidate = "action::invalidate"; + server.EventInstall = "event::install"; + var Arguments; + (function (Arguments) { + Arguments.GlobalCacheLocation = "--globalTypingsCacheLocation"; + Arguments.LogFile = "--logFile"; + Arguments.EnableTelemetry = "--enableTelemetry"; + })(Arguments = server.Arguments || (server.Arguments = {})); + function hasArgument(argumentName) { + return ts.sys.args.indexOf(argumentName) >= 0; + } + server.hasArgument = hasArgument; + function findArgument(argumentName) { + var index = ts.sys.args.indexOf(argumentName); + return index >= 0 && index < ts.sys.args.length - 1 + ? ts.sys.args[index + 1] + : undefined; + } + server.findArgument = findArgument; + })(server = ts.server || (ts.server = {})); +})(ts || (ts = {})); +var ts; (function (ts) { function tryReadTypesSection(packageJsonPath, baseDirectory, state) { var jsonContent = ts.readJson(packageJsonPath, state.host); @@ -5734,12 +5760,13 @@ var ts; } typingsInstaller.validatePackageName = validatePackageName; var TypingsInstaller = (function () { - function TypingsInstaller(installTypingHost, globalCachePath, safeListPath, throttleLimit, log) { + function TypingsInstaller(installTypingHost, globalCachePath, safeListPath, throttleLimit, telemetryEnabled, log) { if (log === void 0) { log = nullLog; } this.installTypingHost = installTypingHost; this.globalCachePath = globalCachePath; this.safeListPath = safeListPath; this.throttleLimit = throttleLimit; + this.telemetryEnabled = telemetryEnabled; this.log = log; this.packageNameToTypingLocation = ts.createMap(); this.missingTypingsSet = ts.createMap(); @@ -5926,6 +5953,12 @@ var ts; var requestId = this.installRunCount; this.installRunCount++; this.installTypingsAsync(requestId, scopedTypings, cachePath, function (ok) { + if (_this.telemetryEnabled) { + _this.sendResponse({ + kind: server.EventInstall, + packagesToInstall: scopedTypings + }); + } if (!ok) { return; } @@ -5978,10 +6011,10 @@ var ts; _this.log.writeLine("Got FS notification for " + f + ", handler is already invoked '" + isInvoked + "'"); } if (!isInvoked) { - _this.sendResponse({ projectName: projectName, kind: "invalidate" }); + _this.sendResponse({ projectName: projectName, kind: server.ActionInvalidate }); isInvoked = true; } - }); + }, 2000); watchers.push(w); } this.projectWatchers[projectName] = watchers; @@ -5992,7 +6025,7 @@ var ts; typingOptions: request.typingOptions, compilerOptions: request.compilerOptions, typings: typings, - kind: "set" + kind: server.ActionSet }; }; TypingsInstaller.prototype.installTypingsAsync = function (requestId, args, cwd, onRequestCompleted) { @@ -6073,8 +6106,8 @@ var ts; } var NodeTypingsInstaller = (function (_super) { __extends(NodeTypingsInstaller, _super); - function NodeTypingsInstaller(globalTypingsCacheLocation, throttleLimit, log) { - _super.call(this, ts.sys, globalTypingsCacheLocation, ts.toPath("typingSafeList.json", __dirname, ts.createGetCanonicalFileName(ts.sys.useCaseSensitiveFileNames)), throttleLimit, log); + function NodeTypingsInstaller(globalTypingsCacheLocation, throttleLimit, telemetryEnabled, log) { + _super.call(this, ts.sys, globalTypingsCacheLocation, ts.toPath("typingSafeList.json", __dirname, ts.createGetCanonicalFileName(ts.sys.useCaseSensitiveFileNames)), throttleLimit, telemetryEnabled, log); if (this.log.isEnabled()) { this.log.writeLine("Process id: " + process.pid); } @@ -6134,14 +6167,9 @@ var ts; return NodeTypingsInstaller; }(typingsInstaller.TypingsInstaller)); typingsInstaller.NodeTypingsInstaller = NodeTypingsInstaller; - function findArgument(argumentName) { - var index = ts.sys.args.indexOf(argumentName); - return index >= 0 && index < ts.sys.args.length - 1 - ? ts.sys.args[index + 1] - : undefined; - } - var logFilePath = findArgument("--logFile"); - var globalTypingsCacheLocation = findArgument("--globalTypingsCacheLocation"); + var logFilePath = server.findArgument(server.Arguments.LogFile); + var globalTypingsCacheLocation = server.findArgument(server.Arguments.GlobalCacheLocation); + var telemetryEnabled = server.hasArgument(server.Arguments.EnableTelemetry); var log = new FileLog(logFilePath); if (log.isEnabled()) { process.on("uncaughtException", function (e) { @@ -6154,7 +6182,7 @@ var ts; } process.exit(0); }); - var installer = new NodeTypingsInstaller(globalTypingsCacheLocation, 5, log); + var installer = new NodeTypingsInstaller(globalTypingsCacheLocation, 5, telemetryEnabled, log); installer.listen(); })(typingsInstaller = server.typingsInstaller || (server.typingsInstaller = {})); })(server = ts.server || (ts.server = {}));