diff --git a/lib/tsc.js b/lib/tsc.js index c2edd68676cda..b69b99382d26f 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -10534,6 +10534,10 @@ var ts; || kind === 251; } ts.isTypeElement = isTypeElement; + function isClassOrTypeElement(node) { + return isTypeElement(node) || isClassElement(node); + } + ts.isClassOrTypeElement = isClassOrTypeElement; function isObjectLiteralElementLike(node) { var kind = node.kind; return kind === 268 diff --git a/lib/tsserver.js b/lib/tsserver.js index 3d12c7b36766b..d5ba2727c19ec 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -10985,6 +10985,10 @@ var ts; || kind === 251; } ts.isTypeElement = isTypeElement; + function isClassOrTypeElement(node) { + return isTypeElement(node) || isClassElement(node); + } + ts.isClassOrTypeElement = isClassOrTypeElement; function isObjectLiteralElementLike(node) { var kind = node.kind; return kind === 268 @@ -78631,10 +78635,7 @@ var ts; } }; ChangeTracker.prototype.insertNodeAfter = function (sourceFile, after, newNode) { - if (ts.isStatementButNotDeclaration(after) || - after.kind === 151 || - after.kind === 150 || - after.kind === 152) { + if (needSemicolonBetween(after, newNode)) { if (sourceFile.text.charCodeAt(after.end - 1) !== 59) { this.changes.push({ kind: ChangeKind.ReplaceWithSingleNode, @@ -78652,7 +78653,7 @@ var ts; if (ts.isClassDeclaration(node) || ts.isModuleDeclaration(node)) { return { prefix: this.newLineCharacter, suffix: this.newLineCharacter }; } - else if (ts.isStatement(node) || ts.isClassElement(node) || ts.isTypeElement(node)) { + else if (ts.isStatement(node) || ts.isClassOrTypeElement(node)) { return { suffix: this.newLineCharacter }; } else if (ts.isVariableDeclaration(node)) { @@ -79017,6 +79018,10 @@ var ts; } } } + function needSemicolonBetween(a, b) { + return (ts.isPropertySignature(a) || ts.isPropertyDeclaration(a)) && ts.isClassOrTypeElement(b) && b.name.kind === 146 + || ts.isStatementButNotDeclaration(a) && ts.isStatementButNotDeclaration(b); + } })(textChanges = ts.textChanges || (ts.textChanges = {})); })(ts || (ts = {})); var ts; @@ -85937,6 +85942,11 @@ var ts; : undefined; } server.findArgument = findArgument; + function nowString() { + var d = new Date(); + return d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds() + "." + d.getMilliseconds(); + } + server.nowString = nowString; })(server = ts.server || (ts.server = {})); })(ts || (ts = {})); var ts; @@ -88963,6 +88973,8 @@ var ts; } this.currentDirectory = this.host.getCurrentDirectory(); this.toCanonicalFileName = ts.createGetCanonicalFileName(this.host.useCaseSensitiveFileNames); + this.globalCacheLocationDirectoryPath = this.typingsInstaller.globalTypingsCacheLocation && + ts.ensureTrailingDirectorySeparator(this.toPath(this.typingsInstaller.globalTypingsCacheLocation)); this.throttledOperations = new server.ThrottledOperations(this.host, this.logger); if (this.typesMapLocation) { this.loadTypesMap(); @@ -89060,8 +89072,8 @@ var ts; else { if (_this.pendingEnsureProjectForOpenFiles) { _this.ensureProjectForOpenFiles(); + _this.sendProjectsUpdatedInBackgroundEvent(); } - _this.sendProjectsUpdatedInBackgroundEvent(); } }); }; @@ -89132,7 +89144,6 @@ var ts; return undefined; } if (server.isInferredProjectName(projectName)) { - this.ensureProjectStructuresUptoDate(); return findProjectByName(projectName, this.inferredProjects); } return this.findExternalProjectByProjectName(projectName) || this.findConfiguredProjectByProjectName(server.toNormalizedPath(projectName)); @@ -89884,7 +89895,9 @@ var ts; ProjectService.prototype.watchClosedScriptInfo = function (info) { var _this = this; ts.Debug.assert(!info.fileWatcher); - if (!info.isDynamicOrHasMixedContent()) { + if (!info.isDynamicOrHasMixedContent() && + (!this.globalCacheLocationDirectoryPath || + !ts.startsWith(info.path, this.globalCacheLocationDirectoryPath))) { var fileName = info.fileName; info.fileWatcher = this.watchFactory.watchFilePath(this.host, fileName, function (fileName, eventKind, path) { return _this.onSourceFileChanged(fileName, eventKind, path); }, ts.PollingInterval.Medium, info.path, "Closed Script info"); } @@ -93041,7 +93054,7 @@ var ts; if (type === void 0) { type = server.Msg.Err; } if (!this.canWrite) return; - s = "[" + nowString() + "] " + s + "\n"; + s = "[" + server.nowString() + "] " + s + "\n"; if (!this.inGroup || this.firstInGroup) { var prefix = Logger.padStringRight(type + " " + this.seq.toString(), " "); s = prefix + s; @@ -93069,10 +93082,6 @@ var ts; }; return Logger; }()); - function nowString() { - var d = new Date(); - return d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds() + "." + d.getMilliseconds(); - } var NodeTypingsInstaller = (function () { function NodeTypingsInstaller(telemetryEnabled, logger, host, globalTypingsCacheLocation, typingSafeListLocation, typesMapLocation, npmLocation, event) { this.telemetryEnabled = telemetryEnabled; diff --git a/lib/tsserverlibrary.d.ts b/lib/tsserverlibrary.d.ts index a2f9506dc1cac..77138318586b3 100644 --- a/lib/tsserverlibrary.d.ts +++ b/lib/tsserverlibrary.d.ts @@ -3219,6 +3219,7 @@ declare namespace ts { function isClassLike(node: Node): node is ClassLikeDeclaration; function isAccessor(node: Node): node is AccessorDeclaration; function isTypeElement(node: Node): node is TypeElement; + function isClassOrTypeElement(node: Node): node is ClassElement | TypeElement; function isObjectLiteralElementLike(node: Node): node is ObjectLiteralElementLike; /** * Node test that determines whether a node is a valid type node. @@ -7847,6 +7848,7 @@ declare namespace ts.server { readonly useSingleInferredProject: boolean; readonly useInferredProjectPerProjectRoot: boolean; readonly typingsInstaller: ITypingsInstaller; + private readonly globalCacheLocationDirectoryPath; readonly throttleWaitMilliseconds?: number; private readonly eventHandler?; readonly globalPlugins: ReadonlyArray; diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index 23174981520dc..8493f57c2d839 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -3648,10 +3648,6 @@ var ts; return path; } ts.removeTrailingDirectorySeparator = removeTrailingDirectorySeparator; - /** - * Adds a trailing directory separator to a path, if it does not already have one. - * @param path The path. - */ function ensureTrailingDirectorySeparator(path) { if (path.charAt(path.length - 1) !== ts.directorySeparator) { return path + ts.directorySeparator; @@ -11497,6 +11493,10 @@ var ts; || kind === 251 /* MissingDeclaration */; } ts.isTypeElement = isTypeElement; + function isClassOrTypeElement(node) { + return isTypeElement(node) || isClassElement(node); + } + ts.isClassOrTypeElement = isClassOrTypeElement; function isObjectLiteralElementLike(node) { var kind = node.kind; return kind === 268 /* PropertyAssignment */ @@ -94878,10 +94878,7 @@ var ts; } }; ChangeTracker.prototype.insertNodeAfter = function (sourceFile, after, newNode) { - if (ts.isStatementButNotDeclaration(after) || - after.kind === 151 /* PropertyDeclaration */ || - after.kind === 150 /* PropertySignature */ || - after.kind === 152 /* MethodSignature */) { + if (needSemicolonBetween(after, newNode)) { // check if previous statement ends with semicolon // if not - insert semicolon to preserve the code from changing the meaning due to ASI if (sourceFile.text.charCodeAt(after.end - 1) !== 59 /* semicolon */) { @@ -94901,7 +94898,7 @@ var ts; if (ts.isClassDeclaration(node) || ts.isModuleDeclaration(node)) { return { prefix: this.newLineCharacter, suffix: this.newLineCharacter }; } - else if (ts.isStatement(node) || ts.isClassElement(node) || ts.isTypeElement(node)) { + else if (ts.isStatement(node) || ts.isClassOrTypeElement(node)) { return { suffix: this.newLineCharacter }; } else if (ts.isVariableDeclaration(node)) { @@ -95335,6 +95332,10 @@ var ts; } } } + function needSemicolonBetween(a, b) { + return (ts.isPropertySignature(a) || ts.isPropertyDeclaration(a)) && ts.isClassOrTypeElement(b) && b.name.kind === 146 /* ComputedPropertyName */ + || ts.isStatementButNotDeclaration(a) && ts.isStatementButNotDeclaration(b); // TODO: only if b would start with a `(` or `[` + } })(textChanges = ts.textChanges || (ts.textChanges = {})); })(ts || (ts = {})); /* @internal */ @@ -102515,6 +102516,13 @@ var ts; : undefined; } server.findArgument = findArgument; + /*@internal*/ + function nowString() { + // E.g. "12:34:56.789" + var d = new Date(); + return d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds() + "." + d.getMilliseconds(); + } + server.nowString = nowString; })(server = ts.server || (ts.server = {})); })(ts || (ts = {})); /// @@ -108711,6 +108719,8 @@ var ts; } this.currentDirectory = this.host.getCurrentDirectory(); this.toCanonicalFileName = ts.createGetCanonicalFileName(this.host.useCaseSensitiveFileNames); + this.globalCacheLocationDirectoryPath = this.typingsInstaller.globalTypingsCacheLocation && + ts.ensureTrailingDirectorySeparator(this.toPath(this.typingsInstaller.globalTypingsCacheLocation)); this.throttledOperations = new server.ThrottledOperations(this.host, this.logger); if (this.typesMapLocation) { this.loadTypesMap(); @@ -108815,10 +108825,10 @@ var ts; else { if (_this.pendingEnsureProjectForOpenFiles) { _this.ensureProjectForOpenFiles(); + // Send the event to notify that there were background project updates + // send current list of open files + _this.sendProjectsUpdatedInBackgroundEvent(); } - // Send the event to notify that there were background project updates - // send current list of open files - _this.sendProjectsUpdatedInBackgroundEvent(); } }); }; @@ -108901,7 +108911,6 @@ var ts; return undefined; } if (server.isInferredProjectName(projectName)) { - this.ensureProjectStructuresUptoDate(); return findProjectByName(projectName, this.inferredProjects); } return this.findExternalProjectByProjectName(projectName) || this.findConfiguredProjectByProjectName(server.toNormalizedPath(projectName)); @@ -109848,7 +109857,10 @@ var ts; var _this = this; ts.Debug.assert(!info.fileWatcher); // do not watch files with mixed content - server doesn't know how to interpret it - if (!info.isDynamicOrHasMixedContent()) { + // do not watch files in the global cache location + if (!info.isDynamicOrHasMixedContent() && + (!this.globalCacheLocationDirectoryPath || + !ts.startsWith(info.path, this.globalCacheLocationDirectoryPath))) { var fileName = info.fileName; info.fileWatcher = this.watchFactory.watchFilePath(this.host, fileName, function (fileName, eventKind, path) { return _this.onSourceFileChanged(fileName, eventKind, path); }, ts.PollingInterval.Medium, info.path, "Closed Script info" /* ClosedScriptInfo */); } diff --git a/lib/typescript.d.ts b/lib/typescript.d.ts index 3e6fe31c00134..0e07336edbb40 100644 --- a/lib/typescript.d.ts +++ b/lib/typescript.d.ts @@ -3274,6 +3274,7 @@ declare namespace ts { function isClassLike(node: Node): node is ClassLikeDeclaration; function isAccessor(node: Node): node is AccessorDeclaration; function isTypeElement(node: Node): node is TypeElement; + function isClassOrTypeElement(node: Node): node is ClassElement | TypeElement; function isObjectLiteralElementLike(node: Node): node is ObjectLiteralElementLike; /** * Node test that determines whether a node is a valid type node. diff --git a/lib/typescript.js b/lib/typescript.js index 11c8d4d55b964..4afd4b7ce8c9d 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -3648,10 +3648,6 @@ var ts; return path; } ts.removeTrailingDirectorySeparator = removeTrailingDirectorySeparator; - /** - * Adds a trailing directory separator to a path, if it does not already have one. - * @param path The path. - */ function ensureTrailingDirectorySeparator(path) { if (path.charAt(path.length - 1) !== ts.directorySeparator) { return path + ts.directorySeparator; @@ -13373,6 +13369,10 @@ var ts; || kind === 251 /* MissingDeclaration */; } ts.isTypeElement = isTypeElement; + function isClassOrTypeElement(node) { + return isTypeElement(node) || isClassElement(node); + } + ts.isClassOrTypeElement = isClassOrTypeElement; function isObjectLiteralElementLike(node) { var kind = node.kind; return kind === 268 /* PropertyAssignment */ @@ -96457,10 +96457,7 @@ var ts; } }; ChangeTracker.prototype.insertNodeAfter = function (sourceFile, after, newNode) { - if (ts.isStatementButNotDeclaration(after) || - after.kind === 151 /* PropertyDeclaration */ || - after.kind === 150 /* PropertySignature */ || - after.kind === 152 /* MethodSignature */) { + if (needSemicolonBetween(after, newNode)) { // check if previous statement ends with semicolon // if not - insert semicolon to preserve the code from changing the meaning due to ASI if (sourceFile.text.charCodeAt(after.end - 1) !== 59 /* semicolon */) { @@ -96480,7 +96477,7 @@ var ts; if (ts.isClassDeclaration(node) || ts.isModuleDeclaration(node)) { return { prefix: this.newLineCharacter, suffix: this.newLineCharacter }; } - else if (ts.isStatement(node) || ts.isClassElement(node) || ts.isTypeElement(node)) { + else if (ts.isStatement(node) || ts.isClassOrTypeElement(node)) { return { suffix: this.newLineCharacter }; } else if (ts.isVariableDeclaration(node)) { @@ -96914,6 +96911,10 @@ var ts; } } } + function needSemicolonBetween(a, b) { + return (ts.isPropertySignature(a) || ts.isPropertyDeclaration(a)) && ts.isClassOrTypeElement(b) && b.name.kind === 146 /* ComputedPropertyName */ + || ts.isStatementButNotDeclaration(a) && ts.isStatementButNotDeclaration(b); // TODO: only if b would start with a `(` or `[` + } })(textChanges = ts.textChanges || (ts.textChanges = {})); })(ts || (ts = {})); /* @internal */ diff --git a/lib/typescriptServices.d.ts b/lib/typescriptServices.d.ts index 0d140a74f51c7..760efeda37725 100644 --- a/lib/typescriptServices.d.ts +++ b/lib/typescriptServices.d.ts @@ -3274,6 +3274,7 @@ declare namespace ts { function isClassLike(node: Node): node is ClassLikeDeclaration; function isAccessor(node: Node): node is AccessorDeclaration; function isTypeElement(node: Node): node is TypeElement; + function isClassOrTypeElement(node: Node): node is ClassElement | TypeElement; function isObjectLiteralElementLike(node: Node): node is ObjectLiteralElementLike; /** * Node test that determines whether a node is a valid type node. diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index 11c8d4d55b964..4afd4b7ce8c9d 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -3648,10 +3648,6 @@ var ts; return path; } ts.removeTrailingDirectorySeparator = removeTrailingDirectorySeparator; - /** - * Adds a trailing directory separator to a path, if it does not already have one. - * @param path The path. - */ function ensureTrailingDirectorySeparator(path) { if (path.charAt(path.length - 1) !== ts.directorySeparator) { return path + ts.directorySeparator; @@ -13373,6 +13369,10 @@ var ts; || kind === 251 /* MissingDeclaration */; } ts.isTypeElement = isTypeElement; + function isClassOrTypeElement(node) { + return isTypeElement(node) || isClassElement(node); + } + ts.isClassOrTypeElement = isClassOrTypeElement; function isObjectLiteralElementLike(node) { var kind = node.kind; return kind === 268 /* PropertyAssignment */ @@ -96457,10 +96457,7 @@ var ts; } }; ChangeTracker.prototype.insertNodeAfter = function (sourceFile, after, newNode) { - if (ts.isStatementButNotDeclaration(after) || - after.kind === 151 /* PropertyDeclaration */ || - after.kind === 150 /* PropertySignature */ || - after.kind === 152 /* MethodSignature */) { + if (needSemicolonBetween(after, newNode)) { // check if previous statement ends with semicolon // if not - insert semicolon to preserve the code from changing the meaning due to ASI if (sourceFile.text.charCodeAt(after.end - 1) !== 59 /* semicolon */) { @@ -96480,7 +96477,7 @@ var ts; if (ts.isClassDeclaration(node) || ts.isModuleDeclaration(node)) { return { prefix: this.newLineCharacter, suffix: this.newLineCharacter }; } - else if (ts.isStatement(node) || ts.isClassElement(node) || ts.isTypeElement(node)) { + else if (ts.isStatement(node) || ts.isClassOrTypeElement(node)) { return { suffix: this.newLineCharacter }; } else if (ts.isVariableDeclaration(node)) { @@ -96914,6 +96911,10 @@ var ts; } } } + function needSemicolonBetween(a, b) { + return (ts.isPropertySignature(a) || ts.isPropertyDeclaration(a)) && ts.isClassOrTypeElement(b) && b.name.kind === 146 /* ComputedPropertyName */ + || ts.isStatementButNotDeclaration(a) && ts.isStatementButNotDeclaration(b); // TODO: only if b would start with a `(` or `[` + } })(textChanges = ts.textChanges || (ts.textChanges = {})); })(ts || (ts = {})); /* @internal */ diff --git a/lib/typingsInstaller.js b/lib/typingsInstaller.js index 68ccdccaa1644..9951f1241584f 100644 --- a/lib/typingsInstaller.js +++ b/lib/typingsInstaller.js @@ -8856,6 +8856,10 @@ var ts; || kind === 251; } ts.isTypeElement = isTypeElement; + function isClassOrTypeElement(node) { + return isTypeElement(node) || isClassElement(node); + } + ts.isClassOrTypeElement = isClassOrTypeElement; function isObjectLiteralElementLike(node) { var kind = node.kind; return kind === 268 @@ -19535,6 +19539,11 @@ var ts; : undefined; } server.findArgument = findArgument; + function nowString() { + var d = new Date(); + return d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds() + "." + d.getMilliseconds(); + } + server.nowString = nowString; })(server = ts.server || (ts.server = {})); })(ts || (ts = {})); var ts; @@ -19917,7 +19926,7 @@ var ts; }; this.writeLine = function (text) { try { - fs.appendFileSync(_this.logFile, text + ts.sys.newLine); + fs.appendFileSync(_this.logFile, "[" + server.nowString() + "] " + text + ts.sys.newLine); } catch (e) { _this.logEnabled = false;