This commit is contained in:
Mohamed Hegazy 2016-09-22 16:31:23 -07:00
Родитель 59b12d721c
Коммит 0a0b7e4baa
10 изменённых файлов: 6439 добавлений и 66 удалений

41
lib/cancellationToken.js Normal file
Просмотреть файл

@ -0,0 +1,41 @@
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
"use strict";
var fs = require("fs");
function createCancellationToken(args) {
var cancellationPipeName;
for (var i = 0; i < args.length - 1; i++) {
if (args[i] === "--cancellationPipeName") {
cancellationPipeName = args[i + 1];
break;
}
}
if (!cancellationPipeName) {
return { isCancellationRequested: function () { return false; } };
}
return {
isCancellationRequested: function () {
try {
fs.statSync(cancellationPipeName);
return true;
}
catch (e) {
return false;
}
}
};
}
module.exports = createCancellationToken;

Просмотреть файл

@ -1834,7 +1834,7 @@ var ts;
var originalWriteFile_1 = sys.writeFile;
sys.writeFile = function (path, data, writeBom) {
var directoryPath = ts.getDirectoryPath(ts.normalizeSlashes(path));
if (!sys.directoryExists(directoryPath)) {
if (directoryPath && !sys.directoryExists(directoryPath)) {
recursiveCreateDirectory(directoryPath, sys);
}
originalWriteFile_1.call(sys, path, data, writeBom);

Просмотреть файл

@ -1839,7 +1839,7 @@ var ts;
var originalWriteFile_1 = sys.writeFile;
sys.writeFile = function (path, data, writeBom) {
var directoryPath = ts.getDirectoryPath(ts.normalizeSlashes(path));
if (!sys.directoryExists(directoryPath)) {
if (directoryPath && !sys.directoryExists(directoryPath)) {
recursiveCreateDirectory(directoryPath, sys);
}
originalWriteFile_1.call(sys, path, data, writeBom);
@ -5220,7 +5220,7 @@ var ts;
return;
}
var typingNames = [];
var fileNames = host.readDirectory(nodeModulesPath, ["*.json"], undefined, undefined, 2);
var fileNames = host.readDirectory(nodeModulesPath, [".json"], undefined, undefined, 2);
for (var _i = 0, fileNames_2 = fileNames; _i < fileNames_2.length; _i++) {
var fileName = fileNames_2[_i];
var normalizedFileName = ts.normalizePath(fileName);
@ -5274,7 +5274,7 @@ var ts;
function getProjectRootPath(project) {
switch (project.projectKind) {
case server.ProjectKind.Configured:
return project.getProjectName();
return ts.getDirectoryPath(project.getProjectName());
case server.ProjectKind.Inferred:
return "";
case server.ProjectKind.External:
@ -46815,6 +46815,7 @@ var ts;
var ruleProvider;
var program;
var lastProjectVersion;
var lastTypesRootVersion = 0;
var useCaseSensitivefileNames = host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames();
var cancellationToken = new CancellationTokenObject(host.getCancellationToken && host.getCancellationToken());
var currentDirectory = host.getCurrentDirectory();
@ -46851,6 +46852,12 @@ var ts;
lastProjectVersion = hostProjectVersion;
}
}
var typeRootsVersion = host.getTypeRootsVersion ? host.getTypeRootsVersion() : 0;
if (lastTypesRootVersion !== typeRootsVersion) {
log("TypeRoots version has changed; provide new program");
program = undefined;
lastTypesRootVersion = typeRootsVersion;
}
var hostCache = new HostCache(host, getCanonicalFileName);
if (programUpToDate()) {
return;
@ -51525,11 +51532,13 @@ var ts;
this.containingProjects = [];
this.path = ts.toPath(fileName, host.getCurrentDirectory(), ts.createGetCanonicalFileName(host.useCaseSensitiveFileNames));
this.svc = server.ScriptVersionCache.fromString(host, content);
this.formatCodeSettings = server.getDefaultFormatCodeSettings(this.host);
this.scriptKind = scriptKind
? scriptKind
: ts.getScriptKindFromFileName(fileName);
}
ScriptInfo.prototype.getFormatCodeSettings = function () {
return this.formatCodeSettings;
};
ScriptInfo.prototype.attachToProject = function (project) {
var isNew = !this.isAttached(project);
if (isNew) {
@ -51583,6 +51592,9 @@ var ts;
};
ScriptInfo.prototype.setFormatOptions = function (formatSettings) {
if (formatSettings) {
if (!this.formatCodeSettings) {
this.formatCodeSettings = server.getDefaultFormatCodeSettings(this.host);
}
server.mergeMaps(this.formatCodeSettings, formatSettings);
}
};
@ -51680,8 +51692,11 @@ var ts;
this.resolveModuleName = function (moduleName, containingFile, compilerOptions, host) {
var primaryResult = ts.resolveModuleName(moduleName, containingFile, compilerOptions, host);
if (primaryResult.resolvedModule) {
return primaryResult;
if (ts.fileExtensionIsAny(primaryResult.resolvedModule.resolvedFileName, ts.supportedTypeScriptExtensions)) {
return primaryResult;
}
}
var secondaryLookupFailedLookupLocations = [];
var globalCache = _this.project.projectService.typingsInstaller.globalTypingsCacheLocation;
if (_this.project.getTypingOptions().enableAutoDiscovery && globalCache) {
var traceEnabled = ts.isTraceEnabled(compilerOptions, host);
@ -51689,11 +51704,14 @@ var ts;
ts.trace(host, ts.Diagnostics.Auto_discovery_for_typings_is_enabled_in_project_0_Running_extra_resolution_pass_for_module_1_using_cache_location_2, _this.project.getProjectName(), moduleName, globalCache);
}
var state = { compilerOptions: compilerOptions, host: host, skipTsx: false, traceEnabled: traceEnabled };
var resolvedName = ts.loadModuleFromNodeModules(moduleName, globalCache, primaryResult.failedLookupLocations, state, true);
var resolvedName = ts.loadModuleFromNodeModules(moduleName, globalCache, secondaryLookupFailedLookupLocations, state, true);
if (resolvedName) {
return ts.createResolvedModule(resolvedName, true, primaryResult.failedLookupLocations);
return ts.createResolvedModule(resolvedName, true, primaryResult.failedLookupLocations.concat(secondaryLookupFailedLookupLocations));
}
}
if (!primaryResult.resolvedModule && secondaryLookupFailedLookupLocations.length) {
primaryResult.failedLookupLocations = primaryResult.failedLookupLocations.concat(secondaryLookupFailedLookupLocations);
}
return primaryResult;
};
}
@ -51761,6 +51779,9 @@ var ts;
LSHost.prototype.getScriptFileNames = function () {
return this.project.getRootFilesLSHost();
};
LSHost.prototype.getTypeRootsVersion = function () {
return this.project.typesVersion;
};
LSHost.prototype.getScriptKind = function (fileName) {
var info = this.project.getScriptInfoLSHost(fileName);
return info && info.scriptKind;
@ -52242,6 +52263,7 @@ var ts;
this.lastReportedVersion = 0;
this.projectStructureVersion = 0;
this.projectStateVersion = 0;
this.typesVersion = 0;
if (!this.compilerOptions) {
this.compilerOptions = ts.getDefaultCompilerOptions();
this.compilerOptions.allowNonTsExtensions = true;
@ -52301,6 +52323,11 @@ var ts;
}
return this.program.getSourceFileByPath(path);
};
Project.prototype.updateTypes = function () {
this.typesVersion++;
this.markAsDirty();
this.updateGraph();
};
Project.prototype.close = function () {
if (this.program) {
for (var _i = 0, _a = this.program.getSourceFiles(); _i < _a.length; _i++) {
@ -52671,6 +52698,17 @@ var ts;
var _this = this;
this.projectFileWatcher = this.projectService.host.watchFile(this.configFileName, function (_) { return callback(_this); });
};
ConfiguredProject.prototype.watchTypeRoots = function (callback) {
var _this = this;
var roots = this.getEffectiveTypeRoots();
var watchers = [];
for (var _i = 0, roots_1 = roots; _i < roots_1.length; _i++) {
var root = roots_1[_i];
this.projectService.logger.info("Add type root watcher for: " + root);
watchers.push(this.projectService.host.watchDirectory(root, function (path) { return callback(_this, path); }, false));
}
this.typeRootsWatchers = watchers;
};
ConfiguredProject.prototype.watchConfigDirectory = function (callback) {
var _this = this;
if (this.directoryWatcher) {
@ -52706,6 +52744,13 @@ var ts;
if (this.projectFileWatcher) {
this.projectFileWatcher.close();
}
if (this.typeRootsWatchers) {
for (var _i = 0, _a = this.typeRootsWatchers; _i < _a.length; _i++) {
var watcher = _a[_i];
watcher.close();
}
this.typeRootsWatchers = undefined;
}
for (var id in this.directoriesWatchedForWildcards) {
this.directoriesWatchedForWildcards[id].close();
}
@ -52719,6 +52764,9 @@ var ts;
this.openRefCount--;
return this.openRefCount;
};
ConfiguredProject.prototype.getEffectiveTypeRoots = function () {
return ts.getEffectiveTypeRoots(this.getCompilerOptions(), this.projectService.host) || [];
};
return ConfiguredProject;
}(Project));
server.ConfiguredProject = ConfiguredProject;
@ -52945,13 +52993,14 @@ var ts;
return undefined;
};
ProjectService.prototype.getFormatCodeOptions = function (file) {
var formatCodeSettings;
if (file) {
var info = this.getScriptInfoForNormalizedPath(file);
if (info) {
return info.formatCodeSettings;
formatCodeSettings = info.getFormatCodeSettings();
}
}
return this.hostConfiguration.formatCodeOptions;
return formatCodeSettings || this.hostConfiguration.formatCodeOptions;
};
ProjectService.prototype.updateProjectGraphs = function (projects) {
var shouldRefreshInferredProjects = false;
@ -52999,6 +53048,15 @@ var ts;
}
this.printProjects();
};
ProjectService.prototype.onTypeRootFileChanged = function (project, fileName) {
var _this = this;
this.logger.info("Type root file " + fileName + " changed");
this.throttledOperations.schedule(project.configFileName + " * type root", 250, function () {
project.updateTypes();
_this.updateConfiguredProject(project);
_this.refreshInferredProjects();
});
};
ProjectService.prototype.onSourceFileInDirectoryChangedForConfiguredProject = function (project, fileName) {
var _this = this;
if (fileName && !ts.isSupportedSourceFileName(fileName, project.getCompilerOptions())) {
@ -53014,6 +53072,7 @@ var ts;
var newRootFiles = projectOptions.files.map((function (f) { return _this.getCanonicalFileName(f); }));
var currentRootFiles = project.getRootFiles().map((function (f) { return _this.getCanonicalFileName(f); }));
if (!ts.arrayIsEqualTo(currentRootFiles.sort(), newRootFiles.sort())) {
this.logger.info("Updating configured project");
this.updateConfiguredProject(project);
this.refreshInferredProjects();
}
@ -53283,6 +53342,7 @@ var ts;
this.watchConfigDirectoryForProject(project, projectOptions);
}
project.watchWildcards(function (project, path) { return _this.onSourceFileInDirectoryChangedForConfiguredProject(project, path); });
project.watchTypeRoots(function (project, path) { return _this.onTypeRootFileChanged(project, path); });
this.configuredProjects.push(project);
return project;
};
@ -53454,7 +53514,6 @@ var ts;
}
if (content !== undefined) {
info = new server.ScriptInfo(this.host, fileName, content, scriptKind, openedByClient, hasMixedContent);
info.setFormatOptions(ts.toEditorSettings(this.getFormatCodeOptions()));
this.filenameToScriptInfo.set(info.path, info);
if (!info.isOpen && !hasMixedContent) {
info.setWatcher(this.host.watchFile(fileName, function (_) { return _this.onSourceFileChanged(fileName); }));
@ -53611,20 +53670,26 @@ var ts;
this.refreshInferredProjects();
}
};
ProjectService.prototype.closeExternalProject = function (uncheckedFileName) {
ProjectService.prototype.closeConfiguredProject = function (configFile) {
var configuredProject = this.findConfiguredProjectByProjectName(configFile);
if (configuredProject && configuredProject.deleteOpenRef() === 0) {
this.removeProject(configuredProject);
}
};
ProjectService.prototype.closeExternalProject = function (uncheckedFileName, suppressRefresh) {
if (suppressRefresh === void 0) { suppressRefresh = false; }
var fileName = server.toNormalizedPath(uncheckedFileName);
var configFiles = this.externalProjectToConfiguredProjectMap[fileName];
if (configFiles) {
var shouldRefreshInferredProjects = false;
for (var _i = 0, configFiles_1 = configFiles; _i < configFiles_1.length; _i++) {
var configFile = configFiles_1[_i];
var configuredProject = this.findConfiguredProjectByProjectName(configFile);
if (configuredProject && configuredProject.deleteOpenRef() === 0) {
this.removeProject(configuredProject);
if (this.closeConfiguredProject(configFile)) {
shouldRefreshInferredProjects = true;
}
}
if (shouldRefreshInferredProjects) {
delete this.externalProjectToConfiguredProjectMap[fileName];
if (shouldRefreshInferredProjects && !suppressRefresh) {
this.refreshInferredProjects();
}
}
@ -53632,16 +53697,13 @@ var ts;
var externalProject = this.findExternalProjectByProjectName(uncheckedFileName);
if (externalProject) {
this.removeProject(externalProject);
this.refreshInferredProjects();
if (!suppressRefresh) {
this.refreshInferredProjects();
}
}
}
};
ProjectService.prototype.openExternalProject = function (proj) {
var externalProject = this.findExternalProjectByProjectName(proj.projectFileName);
if (externalProject) {
this.updateNonInferredProject(externalProject, proj.rootFiles, externalFilePropertyReader, proj.options, proj.typingOptions, proj.options.compileOnSave, undefined);
return;
}
var tsConfigFiles;
var rootFiles = [];
for (var _i = 0, _a = proj.rootFiles; _i < _a.length; _i++) {
@ -53654,6 +53716,47 @@ var ts;
rootFiles.push(file);
}
}
if (tsConfigFiles) {
tsConfigFiles.sort();
}
var externalProject = this.findExternalProjectByProjectName(proj.projectFileName);
var exisingConfigFiles;
if (externalProject) {
if (!tsConfigFiles) {
this.updateNonInferredProject(externalProject, proj.rootFiles, externalFilePropertyReader, proj.options, proj.typingOptions, proj.options.compileOnSave, undefined);
return;
}
this.closeExternalProject(proj.projectFileName, true);
}
else if (this.externalProjectToConfiguredProjectMap[proj.projectFileName]) {
if (!tsConfigFiles) {
this.closeExternalProject(proj.projectFileName, true);
}
else {
var oldConfigFiles = this.externalProjectToConfiguredProjectMap[proj.projectFileName];
var iNew = 0;
var iOld = 0;
while (iNew < tsConfigFiles.length && iOld < oldConfigFiles.length) {
var newConfig = tsConfigFiles[iNew];
var oldConfig = oldConfigFiles[iOld];
if (oldConfig < newConfig) {
this.closeConfiguredProject(oldConfig);
iOld++;
}
else if (oldConfig > newConfig) {
iNew++;
}
else {
(exisingConfigFiles || (exisingConfigFiles = [])).push(oldConfig);
iOld++;
iNew++;
}
}
for (var i = iOld; i < oldConfigFiles.length; i++) {
this.closeConfiguredProject(oldConfigFiles[i]);
}
}
}
if (tsConfigFiles) {
this.externalProjectToConfiguredProjectMap[proj.projectFileName] = tsConfigFiles;
for (var _b = 0, tsConfigFiles_1 = tsConfigFiles; _b < tsConfigFiles_1.length; _b++) {
@ -53663,14 +53766,16 @@ var ts;
var result = this.openConfigFile(tsconfigFile);
project = result.success && result.project;
}
if (project) {
if (project && !ts.contains(exisingConfigFiles, tsconfigFile)) {
project.addOpenRef();
}
}
}
else {
delete this.externalProjectToConfiguredProjectMap[proj.projectFileName];
this.createAndAddExternalProject(proj.projectFileName, rootFiles, proj.options, proj.typingOptions);
}
this.refreshInferredProjects();
};
return ProjectService;
}());
@ -54128,10 +54233,6 @@ var ts;
}
this.send(res);
};
Session.prototype.getLocation = function (position, scriptInfo) {
var _a = scriptInfo.positionToLineOffset(position), line = _a.line, offset = _a.offset;
return { line: line, offset: offset + 1 };
};
Session.prototype.semanticCheck = function (file, project) {
try {
var diags = project.getLanguageService().getSemanticDiagnostics(file);
@ -54242,8 +54343,8 @@ var ts;
length: d.length,
category: ts.DiagnosticCategory[d.category].toLowerCase(),
code: d.code,
startLocation: scriptInfo && _this.getLocation(d.start, scriptInfo),
endLocation: scriptInfo && _this.getLocation(d.start + d.length, scriptInfo)
startLocation: scriptInfo && scriptInfo.positionToLineOffset(d.start),
endLocation: scriptInfo && scriptInfo.positionToLineOffset(d.start + d.length)
}; });
};
Session.prototype.getDiagnosticsWorker = function (args, selector, includeLinePosition) {
@ -55496,7 +55597,7 @@ var ts;
return source.substring(0, s) + nt + source.substring(s + dl, source.length);
}
if (this.root.charCount() === 0) {
if (newText) {
if (newText !== undefined) {
this.load(LineIndex.linesFromText(newText).lines);
return this;
}
@ -56335,6 +56436,12 @@ var ts;
}
return this.shimHost.getProjectVersion();
};
LanguageServiceShimHostAdapter.prototype.getTypeRootsVersion = function () {
if (!this.shimHost.getTypeRootsVersion) {
return 0;
}
return this.shimHost.getTypeRootsVersion();
};
LanguageServiceShimHostAdapter.prototype.useCaseSensitiveFileNames = function () {
return this.shimHost.useCaseSensitiveFileNames ? this.shimHost.useCaseSensitiveFileNames() : false;
};

17
lib/tsserverlibrary.d.ts поставляемый
Просмотреть файл

@ -8105,6 +8105,7 @@ declare namespace ts {
readDirectory?(path: string, extensions?: string[], exclude?: string[], include?: string[]): string[];
readFile?(path: string, encoding?: string): string;
fileExists?(path: string): boolean;
getTypeRootsVersion?(): number;
resolveModuleNames?(moduleNames: string[], containingFile: string): ResolvedModule[];
resolveTypeReferenceDirectives?(typeDirectiveNames: string[], containingFile: string): ResolvedTypeReferenceDirective[];
directoryExists?(directoryName: string): boolean;
@ -8567,11 +8568,12 @@ declare namespace ts.server {
isOpen: boolean;
hasMixedContent: boolean;
readonly containingProjects: Project[];
readonly formatCodeSettings: ts.FormatCodeSettings;
private formatCodeSettings;
readonly path: Path;
private fileWatcher;
private svc;
constructor(host: ServerHost, fileName: NormalizedPath, content: string, scriptKind: ScriptKind, isOpen?: boolean, hasMixedContent?: boolean);
getFormatCodeSettings(): FormatCodeSettings;
attachToProject(project: Project): boolean;
isAttached(project: Project): boolean;
detachFromProject(project: Project): void;
@ -8615,6 +8617,7 @@ declare namespace ts.server {
getDefaultLibFileName(): string;
getScriptSnapshot(filename: string): ts.IScriptSnapshot;
getScriptFileNames(): string[];
getTypeRootsVersion(): number;
getScriptKind(fileName: string): ScriptKind;
getScriptVersion(filename: string): string;
getCurrentDirectory(): string;
@ -8699,6 +8702,7 @@ declare namespace ts.server {
private projectStateVersion;
private typingFiles;
protected projectErrors: Diagnostic[];
typesVersion: number;
isJsOnlyProject(): boolean;
constructor(projectKind: ProjectKind, projectService: ProjectService, documentRegistry: ts.DocumentRegistry, hasExplicitListOfFiles: boolean, languageServiceEnabled: boolean, compilerOptions: CompilerOptions, compileOnSaveEnabled: boolean);
getProjectErrors(): Diagnostic[];
@ -8711,6 +8715,7 @@ declare namespace ts.server {
abstract getProjectRootPath(): string | undefined;
abstract getTypingOptions(): TypingOptions;
getSourceFile(path: Path): SourceFile;
updateTypes(): void;
close(): void;
getCompilerOptions(): CompilerOptions;
hasRoots(): boolean;
@ -8759,6 +8764,7 @@ declare namespace ts.server {
private projectFileWatcher;
private directoryWatcher;
private directoriesWatchedForWildcards;
private typeRootsWatchers;
openRefCount: number;
constructor(configFileName: NormalizedPath, projectService: ProjectService, documentRegistry: ts.DocumentRegistry, hasExplicitListOfFiles: boolean, compilerOptions: CompilerOptions, wildcardDirectories: Map<WatchDirectoryFlags>, languageServiceEnabled: boolean, compileOnSaveEnabled: boolean);
getProjectRootPath(): string;
@ -8769,12 +8775,14 @@ declare namespace ts.server {
__normalizedPathTag: any;
};
watchConfigFile(callback: (project: ConfiguredProject) => void): void;
watchTypeRoots(callback: (project: ConfiguredProject, path: string) => void): void;
watchConfigDirectory(callback: (project: ConfiguredProject, path: string) => void): void;
watchWildcards(callback: (project: ConfiguredProject, path: string) => void): void;
stopWatchingDirectory(): void;
close(): void;
addOpenRef(): void;
deleteOpenRef(): number;
getEffectiveTypeRoots(): string[];
}
class ExternalProject extends Project {
readonly externalProjectName: string;
@ -8853,6 +8861,7 @@ declare namespace ts.server {
private updateProjectGraphs(projects);
private onSourceFileChanged(fileName);
private handleDeletedFile(info);
private onTypeRootFileChanged(project, fileName);
private onSourceFileInDirectoryChangedForConfiguredProject(project, fileName);
private handleChangeInSourceFileForConfiguredProject(project);
private onConfigChangedForConfiguredProject(project);
@ -8891,7 +8900,8 @@ declare namespace ts.server {
private collectChanges(lastKnownProjectVersions, currentProjects, result);
synchronizeProjectList(knownProjects: protocol.ProjectVersionInfo[]): ProjectFilesWithTSDiagnostics[];
applyChangesInOpenFiles(openFiles: protocol.ExternalFile[], changedFiles: protocol.ChangedOpenFile[], closedFiles: string[]): void;
closeExternalProject(uncheckedFileName: string): void;
private closeConfiguredProject(configFile);
closeExternalProject(uncheckedFileName: string, suppressRefresh?: boolean): void;
openExternalProject(proj: protocol.ExternalProject): void;
}
}
@ -8983,7 +8993,6 @@ declare namespace ts.server {
configFileDiagnosticEvent(triggerFile: string, configFile: string, diagnostics: ts.Diagnostic[]): void;
event(info: any, eventName: string): void;
output(info: any, cmdName: string, reqSeq?: number, errorMsg?: string): void;
private getLocation(position, scriptInfo);
private semanticCheck(file, project);
private syntacticCheck(file, project);
private updateProjectStructure(seq, matchSeq, ms?);
@ -9209,6 +9218,7 @@ declare namespace ts {
getNewLine?(): string;
getProjectVersion?(): string;
useCaseSensitiveFileNames?(): boolean;
getTypeRootsVersion?(): number;
readDirectory(rootDir: string, extension: string, basePaths?: string, excludeEx?: string, includeFileEx?: string, includeDirEx?: string, depth?: number): string;
readFile(path: string, encoding?: string): string;
fileExists(path: string): boolean;
@ -9303,6 +9313,7 @@ declare namespace ts {
trace(s: string): void;
error(s: string): void;
getProjectVersion(): string;
getTypeRootsVersion(): number;
useCaseSensitiveFileNames(): boolean;
getCompilationSettings(): CompilerOptions;
getScriptFileNames(): string[];

Просмотреть файл

@ -1839,7 +1839,7 @@ var ts;
var originalWriteFile_1 = sys.writeFile;
sys.writeFile = function (path, data, writeBom) {
var directoryPath = ts.getDirectoryPath(ts.normalizeSlashes(path));
if (!sys.directoryExists(directoryPath)) {
if (directoryPath && !sys.directoryExists(directoryPath)) {
recursiveCreateDirectory(directoryPath, sys);
}
originalWriteFile_1.call(sys, path, data, writeBom);
@ -5220,7 +5220,7 @@ var ts;
return;
}
var typingNames = [];
var fileNames = host.readDirectory(nodeModulesPath, ["*.json"], undefined, undefined, 2);
var fileNames = host.readDirectory(nodeModulesPath, [".json"], undefined, undefined, 2);
for (var _i = 0, fileNames_2 = fileNames; _i < fileNames_2.length; _i++) {
var fileName = fileNames_2[_i];
var normalizedFileName = ts.normalizePath(fileName);
@ -5274,7 +5274,7 @@ var ts;
function getProjectRootPath(project) {
switch (project.projectKind) {
case server.ProjectKind.Configured:
return project.getProjectName();
return ts.getDirectoryPath(project.getProjectName());
case server.ProjectKind.Inferred:
return "";
case server.ProjectKind.External:
@ -46815,6 +46815,7 @@ var ts;
var ruleProvider;
var program;
var lastProjectVersion;
var lastTypesRootVersion = 0;
var useCaseSensitivefileNames = host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames();
var cancellationToken = new CancellationTokenObject(host.getCancellationToken && host.getCancellationToken());
var currentDirectory = host.getCurrentDirectory();
@ -46851,6 +46852,12 @@ var ts;
lastProjectVersion = hostProjectVersion;
}
}
var typeRootsVersion = host.getTypeRootsVersion ? host.getTypeRootsVersion() : 0;
if (lastTypesRootVersion !== typeRootsVersion) {
log("TypeRoots version has changed; provide new program");
program = undefined;
lastTypesRootVersion = typeRootsVersion;
}
var hostCache = new HostCache(host, getCanonicalFileName);
if (programUpToDate()) {
return;
@ -51525,11 +51532,13 @@ var ts;
this.containingProjects = [];
this.path = ts.toPath(fileName, host.getCurrentDirectory(), ts.createGetCanonicalFileName(host.useCaseSensitiveFileNames));
this.svc = server.ScriptVersionCache.fromString(host, content);
this.formatCodeSettings = server.getDefaultFormatCodeSettings(this.host);
this.scriptKind = scriptKind
? scriptKind
: ts.getScriptKindFromFileName(fileName);
}
ScriptInfo.prototype.getFormatCodeSettings = function () {
return this.formatCodeSettings;
};
ScriptInfo.prototype.attachToProject = function (project) {
var isNew = !this.isAttached(project);
if (isNew) {
@ -51583,6 +51592,9 @@ var ts;
};
ScriptInfo.prototype.setFormatOptions = function (formatSettings) {
if (formatSettings) {
if (!this.formatCodeSettings) {
this.formatCodeSettings = server.getDefaultFormatCodeSettings(this.host);
}
server.mergeMaps(this.formatCodeSettings, formatSettings);
}
};
@ -51680,8 +51692,11 @@ var ts;
this.resolveModuleName = function (moduleName, containingFile, compilerOptions, host) {
var primaryResult = ts.resolveModuleName(moduleName, containingFile, compilerOptions, host);
if (primaryResult.resolvedModule) {
return primaryResult;
if (ts.fileExtensionIsAny(primaryResult.resolvedModule.resolvedFileName, ts.supportedTypeScriptExtensions)) {
return primaryResult;
}
}
var secondaryLookupFailedLookupLocations = [];
var globalCache = _this.project.projectService.typingsInstaller.globalTypingsCacheLocation;
if (_this.project.getTypingOptions().enableAutoDiscovery && globalCache) {
var traceEnabled = ts.isTraceEnabled(compilerOptions, host);
@ -51689,11 +51704,14 @@ var ts;
ts.trace(host, ts.Diagnostics.Auto_discovery_for_typings_is_enabled_in_project_0_Running_extra_resolution_pass_for_module_1_using_cache_location_2, _this.project.getProjectName(), moduleName, globalCache);
}
var state = { compilerOptions: compilerOptions, host: host, skipTsx: false, traceEnabled: traceEnabled };
var resolvedName = ts.loadModuleFromNodeModules(moduleName, globalCache, primaryResult.failedLookupLocations, state, true);
var resolvedName = ts.loadModuleFromNodeModules(moduleName, globalCache, secondaryLookupFailedLookupLocations, state, true);
if (resolvedName) {
return ts.createResolvedModule(resolvedName, true, primaryResult.failedLookupLocations);
return ts.createResolvedModule(resolvedName, true, primaryResult.failedLookupLocations.concat(secondaryLookupFailedLookupLocations));
}
}
if (!primaryResult.resolvedModule && secondaryLookupFailedLookupLocations.length) {
primaryResult.failedLookupLocations = primaryResult.failedLookupLocations.concat(secondaryLookupFailedLookupLocations);
}
return primaryResult;
};
}
@ -51761,6 +51779,9 @@ var ts;
LSHost.prototype.getScriptFileNames = function () {
return this.project.getRootFilesLSHost();
};
LSHost.prototype.getTypeRootsVersion = function () {
return this.project.typesVersion;
};
LSHost.prototype.getScriptKind = function (fileName) {
var info = this.project.getScriptInfoLSHost(fileName);
return info && info.scriptKind;
@ -52242,6 +52263,7 @@ var ts;
this.lastReportedVersion = 0;
this.projectStructureVersion = 0;
this.projectStateVersion = 0;
this.typesVersion = 0;
if (!this.compilerOptions) {
this.compilerOptions = ts.getDefaultCompilerOptions();
this.compilerOptions.allowNonTsExtensions = true;
@ -52301,6 +52323,11 @@ var ts;
}
return this.program.getSourceFileByPath(path);
};
Project.prototype.updateTypes = function () {
this.typesVersion++;
this.markAsDirty();
this.updateGraph();
};
Project.prototype.close = function () {
if (this.program) {
for (var _i = 0, _a = this.program.getSourceFiles(); _i < _a.length; _i++) {
@ -52671,6 +52698,17 @@ var ts;
var _this = this;
this.projectFileWatcher = this.projectService.host.watchFile(this.configFileName, function (_) { return callback(_this); });
};
ConfiguredProject.prototype.watchTypeRoots = function (callback) {
var _this = this;
var roots = this.getEffectiveTypeRoots();
var watchers = [];
for (var _i = 0, roots_1 = roots; _i < roots_1.length; _i++) {
var root = roots_1[_i];
this.projectService.logger.info("Add type root watcher for: " + root);
watchers.push(this.projectService.host.watchDirectory(root, function (path) { return callback(_this, path); }, false));
}
this.typeRootsWatchers = watchers;
};
ConfiguredProject.prototype.watchConfigDirectory = function (callback) {
var _this = this;
if (this.directoryWatcher) {
@ -52706,6 +52744,13 @@ var ts;
if (this.projectFileWatcher) {
this.projectFileWatcher.close();
}
if (this.typeRootsWatchers) {
for (var _i = 0, _a = this.typeRootsWatchers; _i < _a.length; _i++) {
var watcher = _a[_i];
watcher.close();
}
this.typeRootsWatchers = undefined;
}
for (var id in this.directoriesWatchedForWildcards) {
this.directoriesWatchedForWildcards[id].close();
}
@ -52719,6 +52764,9 @@ var ts;
this.openRefCount--;
return this.openRefCount;
};
ConfiguredProject.prototype.getEffectiveTypeRoots = function () {
return ts.getEffectiveTypeRoots(this.getCompilerOptions(), this.projectService.host) || [];
};
return ConfiguredProject;
}(Project));
server.ConfiguredProject = ConfiguredProject;
@ -52945,13 +52993,14 @@ var ts;
return undefined;
};
ProjectService.prototype.getFormatCodeOptions = function (file) {
var formatCodeSettings;
if (file) {
var info = this.getScriptInfoForNormalizedPath(file);
if (info) {
return info.formatCodeSettings;
formatCodeSettings = info.getFormatCodeSettings();
}
}
return this.hostConfiguration.formatCodeOptions;
return formatCodeSettings || this.hostConfiguration.formatCodeOptions;
};
ProjectService.prototype.updateProjectGraphs = function (projects) {
var shouldRefreshInferredProjects = false;
@ -52999,6 +53048,15 @@ var ts;
}
this.printProjects();
};
ProjectService.prototype.onTypeRootFileChanged = function (project, fileName) {
var _this = this;
this.logger.info("Type root file " + fileName + " changed");
this.throttledOperations.schedule(project.configFileName + " * type root", 250, function () {
project.updateTypes();
_this.updateConfiguredProject(project);
_this.refreshInferredProjects();
});
};
ProjectService.prototype.onSourceFileInDirectoryChangedForConfiguredProject = function (project, fileName) {
var _this = this;
if (fileName && !ts.isSupportedSourceFileName(fileName, project.getCompilerOptions())) {
@ -53014,6 +53072,7 @@ var ts;
var newRootFiles = projectOptions.files.map((function (f) { return _this.getCanonicalFileName(f); }));
var currentRootFiles = project.getRootFiles().map((function (f) { return _this.getCanonicalFileName(f); }));
if (!ts.arrayIsEqualTo(currentRootFiles.sort(), newRootFiles.sort())) {
this.logger.info("Updating configured project");
this.updateConfiguredProject(project);
this.refreshInferredProjects();
}
@ -53283,6 +53342,7 @@ var ts;
this.watchConfigDirectoryForProject(project, projectOptions);
}
project.watchWildcards(function (project, path) { return _this.onSourceFileInDirectoryChangedForConfiguredProject(project, path); });
project.watchTypeRoots(function (project, path) { return _this.onTypeRootFileChanged(project, path); });
this.configuredProjects.push(project);
return project;
};
@ -53454,7 +53514,6 @@ var ts;
}
if (content !== undefined) {
info = new server.ScriptInfo(this.host, fileName, content, scriptKind, openedByClient, hasMixedContent);
info.setFormatOptions(ts.toEditorSettings(this.getFormatCodeOptions()));
this.filenameToScriptInfo.set(info.path, info);
if (!info.isOpen && !hasMixedContent) {
info.setWatcher(this.host.watchFile(fileName, function (_) { return _this.onSourceFileChanged(fileName); }));
@ -53611,20 +53670,26 @@ var ts;
this.refreshInferredProjects();
}
};
ProjectService.prototype.closeExternalProject = function (uncheckedFileName) {
ProjectService.prototype.closeConfiguredProject = function (configFile) {
var configuredProject = this.findConfiguredProjectByProjectName(configFile);
if (configuredProject && configuredProject.deleteOpenRef() === 0) {
this.removeProject(configuredProject);
}
};
ProjectService.prototype.closeExternalProject = function (uncheckedFileName, suppressRefresh) {
if (suppressRefresh === void 0) { suppressRefresh = false; }
var fileName = server.toNormalizedPath(uncheckedFileName);
var configFiles = this.externalProjectToConfiguredProjectMap[fileName];
if (configFiles) {
var shouldRefreshInferredProjects = false;
for (var _i = 0, configFiles_1 = configFiles; _i < configFiles_1.length; _i++) {
var configFile = configFiles_1[_i];
var configuredProject = this.findConfiguredProjectByProjectName(configFile);
if (configuredProject && configuredProject.deleteOpenRef() === 0) {
this.removeProject(configuredProject);
if (this.closeConfiguredProject(configFile)) {
shouldRefreshInferredProjects = true;
}
}
if (shouldRefreshInferredProjects) {
delete this.externalProjectToConfiguredProjectMap[fileName];
if (shouldRefreshInferredProjects && !suppressRefresh) {
this.refreshInferredProjects();
}
}
@ -53632,16 +53697,13 @@ var ts;
var externalProject = this.findExternalProjectByProjectName(uncheckedFileName);
if (externalProject) {
this.removeProject(externalProject);
this.refreshInferredProjects();
if (!suppressRefresh) {
this.refreshInferredProjects();
}
}
}
};
ProjectService.prototype.openExternalProject = function (proj) {
var externalProject = this.findExternalProjectByProjectName(proj.projectFileName);
if (externalProject) {
this.updateNonInferredProject(externalProject, proj.rootFiles, externalFilePropertyReader, proj.options, proj.typingOptions, proj.options.compileOnSave, undefined);
return;
}
var tsConfigFiles;
var rootFiles = [];
for (var _i = 0, _a = proj.rootFiles; _i < _a.length; _i++) {
@ -53654,6 +53716,47 @@ var ts;
rootFiles.push(file);
}
}
if (tsConfigFiles) {
tsConfigFiles.sort();
}
var externalProject = this.findExternalProjectByProjectName(proj.projectFileName);
var exisingConfigFiles;
if (externalProject) {
if (!tsConfigFiles) {
this.updateNonInferredProject(externalProject, proj.rootFiles, externalFilePropertyReader, proj.options, proj.typingOptions, proj.options.compileOnSave, undefined);
return;
}
this.closeExternalProject(proj.projectFileName, true);
}
else if (this.externalProjectToConfiguredProjectMap[proj.projectFileName]) {
if (!tsConfigFiles) {
this.closeExternalProject(proj.projectFileName, true);
}
else {
var oldConfigFiles = this.externalProjectToConfiguredProjectMap[proj.projectFileName];
var iNew = 0;
var iOld = 0;
while (iNew < tsConfigFiles.length && iOld < oldConfigFiles.length) {
var newConfig = tsConfigFiles[iNew];
var oldConfig = oldConfigFiles[iOld];
if (oldConfig < newConfig) {
this.closeConfiguredProject(oldConfig);
iOld++;
}
else if (oldConfig > newConfig) {
iNew++;
}
else {
(exisingConfigFiles || (exisingConfigFiles = [])).push(oldConfig);
iOld++;
iNew++;
}
}
for (var i = iOld; i < oldConfigFiles.length; i++) {
this.closeConfiguredProject(oldConfigFiles[i]);
}
}
}
if (tsConfigFiles) {
this.externalProjectToConfiguredProjectMap[proj.projectFileName] = tsConfigFiles;
for (var _b = 0, tsConfigFiles_1 = tsConfigFiles; _b < tsConfigFiles_1.length; _b++) {
@ -53663,14 +53766,16 @@ var ts;
var result = this.openConfigFile(tsconfigFile);
project = result.success && result.project;
}
if (project) {
if (project && !ts.contains(exisingConfigFiles, tsconfigFile)) {
project.addOpenRef();
}
}
}
else {
delete this.externalProjectToConfiguredProjectMap[proj.projectFileName];
this.createAndAddExternalProject(proj.projectFileName, rootFiles, proj.options, proj.typingOptions);
}
this.refreshInferredProjects();
};
return ProjectService;
}());
@ -54128,10 +54233,6 @@ var ts;
}
this.send(res);
};
Session.prototype.getLocation = function (position, scriptInfo) {
var _a = scriptInfo.positionToLineOffset(position), line = _a.line, offset = _a.offset;
return { line: line, offset: offset + 1 };
};
Session.prototype.semanticCheck = function (file, project) {
try {
var diags = project.getLanguageService().getSemanticDiagnostics(file);
@ -54242,8 +54343,8 @@ var ts;
length: d.length,
category: ts.DiagnosticCategory[d.category].toLowerCase(),
code: d.code,
startLocation: scriptInfo && _this.getLocation(d.start, scriptInfo),
endLocation: scriptInfo && _this.getLocation(d.start + d.length, scriptInfo)
startLocation: scriptInfo && scriptInfo.positionToLineOffset(d.start),
endLocation: scriptInfo && scriptInfo.positionToLineOffset(d.start + d.length)
}; });
};
Session.prototype.getDiagnosticsWorker = function (args, selector, includeLinePosition) {
@ -55496,7 +55597,7 @@ var ts;
return source.substring(0, s) + nt + source.substring(s + dl, source.length);
}
if (this.root.charCount() === 0) {
if (newText) {
if (newText !== undefined) {
this.load(LineIndex.linesFromText(newText).lines);
return this;
}
@ -55971,6 +56072,12 @@ var ts;
}
return this.shimHost.getProjectVersion();
};
LanguageServiceShimHostAdapter.prototype.getTypeRootsVersion = function () {
if (!this.shimHost.getTypeRootsVersion) {
return 0;
}
return this.shimHost.getTypeRootsVersion();
};
LanguageServiceShimHostAdapter.prototype.useCaseSensitiveFileNames = function () {
return this.shimHost.useCaseSensitiveFileNames ? this.shimHost.useCaseSensitiveFileNames() : false;
};

1
lib/typescript.d.ts поставляемый
Просмотреть файл

@ -2081,6 +2081,7 @@ declare namespace ts {
readDirectory?(path: string, extensions?: string[], exclude?: string[], include?: string[]): string[];
readFile?(path: string, encoding?: string): string;
fileExists?(path: string): boolean;
getTypeRootsVersion?(): number;
resolveModuleNames?(moduleNames: string[], containingFile: string): ResolvedModule[];
resolveTypeReferenceDirectives?(typeDirectiveNames: string[], containingFile: string): ResolvedTypeReferenceDirective[];
directoryExists?(directoryName: string): boolean;

Просмотреть файл

@ -3000,7 +3000,7 @@ var ts;
var originalWriteFile_1 = sys.writeFile;
sys.writeFile = function (path, data, writeBom) {
var directoryPath = ts.getDirectoryPath(ts.normalizeSlashes(path));
if (!sys.directoryExists(directoryPath)) {
if (directoryPath && !sys.directoryExists(directoryPath)) {
recursiveCreateDirectory(directoryPath, sys);
}
originalWriteFile_1.call(sys, path, data, writeBom);
@ -50439,7 +50439,7 @@ var ts;
return;
}
var typingNames = [];
var fileNames = host.readDirectory(nodeModulesPath, ["*.json"], /*excludes*/ undefined, /*includes*/ undefined, /*depth*/ 2);
var fileNames = host.readDirectory(nodeModulesPath, [".json"], /*excludes*/ undefined, /*includes*/ undefined, /*depth*/ 2);
for (var _i = 0, fileNames_2 = fileNames; _i < fileNames_2.length; _i++) {
var fileName = fileNames_2[_i];
var normalizedFileName = ts.normalizePath(fileName);
@ -55360,6 +55360,7 @@ var ts;
var ruleProvider;
var program;
var lastProjectVersion;
var lastTypesRootVersion = 0;
var useCaseSensitivefileNames = host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames();
var cancellationToken = new CancellationTokenObject(host.getCancellationToken && host.getCancellationToken());
var currentDirectory = host.getCurrentDirectory();
@ -55399,6 +55400,12 @@ var ts;
lastProjectVersion = hostProjectVersion;
}
}
var typeRootsVersion = host.getTypeRootsVersion ? host.getTypeRootsVersion() : 0;
if (lastTypesRootVersion !== typeRootsVersion) {
log("TypeRoots version has changed; provide new program");
program = undefined;
lastTypesRootVersion = typeRootsVersion;
}
// Get a fresh cache of the host information
var hostCache = new HostCache(host, getCanonicalFileName);
// If the program is already up-to-date, we can reuse it
@ -61640,6 +61647,12 @@ var ts;
}
return this.shimHost.getProjectVersion();
};
LanguageServiceShimHostAdapter.prototype.getTypeRootsVersion = function () {
if (!this.shimHost.getTypeRootsVersion) {
return 0;
}
return this.shimHost.getTypeRootsVersion();
};
LanguageServiceShimHostAdapter.prototype.useCaseSensitiveFileNames = function () {
return this.shimHost.useCaseSensitiveFileNames ? this.shimHost.useCaseSensitiveFileNames() : false;
};

1
lib/typescriptServices.d.ts поставляемый
Просмотреть файл

@ -2081,6 +2081,7 @@ declare namespace ts {
readDirectory?(path: string, extensions?: string[], exclude?: string[], include?: string[]): string[];
readFile?(path: string, encoding?: string): string;
fileExists?(path: string): boolean;
getTypeRootsVersion?(): number;
resolveModuleNames?(moduleNames: string[], containingFile: string): ResolvedModule[];
resolveTypeReferenceDirectives?(typeDirectiveNames: string[], containingFile: string): ResolvedTypeReferenceDirective[];
directoryExists?(directoryName: string): boolean;

Просмотреть файл

@ -3000,7 +3000,7 @@ var ts;
var originalWriteFile_1 = sys.writeFile;
sys.writeFile = function (path, data, writeBom) {
var directoryPath = ts.getDirectoryPath(ts.normalizeSlashes(path));
if (!sys.directoryExists(directoryPath)) {
if (directoryPath && !sys.directoryExists(directoryPath)) {
recursiveCreateDirectory(directoryPath, sys);
}
originalWriteFile_1.call(sys, path, data, writeBom);
@ -50439,7 +50439,7 @@ var ts;
return;
}
var typingNames = [];
var fileNames = host.readDirectory(nodeModulesPath, ["*.json"], /*excludes*/ undefined, /*includes*/ undefined, /*depth*/ 2);
var fileNames = host.readDirectory(nodeModulesPath, [".json"], /*excludes*/ undefined, /*includes*/ undefined, /*depth*/ 2);
for (var _i = 0, fileNames_2 = fileNames; _i < fileNames_2.length; _i++) {
var fileName = fileNames_2[_i];
var normalizedFileName = ts.normalizePath(fileName);
@ -55360,6 +55360,7 @@ var ts;
var ruleProvider;
var program;
var lastProjectVersion;
var lastTypesRootVersion = 0;
var useCaseSensitivefileNames = host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames();
var cancellationToken = new CancellationTokenObject(host.getCancellationToken && host.getCancellationToken());
var currentDirectory = host.getCurrentDirectory();
@ -55399,6 +55400,12 @@ var ts;
lastProjectVersion = hostProjectVersion;
}
}
var typeRootsVersion = host.getTypeRootsVersion ? host.getTypeRootsVersion() : 0;
if (lastTypesRootVersion !== typeRootsVersion) {
log("TypeRoots version has changed; provide new program");
program = undefined;
lastTypesRootVersion = typeRootsVersion;
}
// Get a fresh cache of the host information
var hostCache = new HostCache(host, getCanonicalFileName);
// If the program is already up-to-date, we can reuse it
@ -61640,6 +61647,12 @@ var ts;
}
return this.shimHost.getProjectVersion();
};
LanguageServiceShimHostAdapter.prototype.getTypeRootsVersion = function () {
if (!this.shimHost.getTypeRootsVersion) {
return 0;
}
return this.shimHost.getTypeRootsVersion();
};
LanguageServiceShimHostAdapter.prototype.useCaseSensitiveFileNames = function () {
return this.shimHost.useCaseSensitiveFileNames ? this.shimHost.useCaseSensitiveFileNames() : false;
};

6079
lib/typingsInstaller.js Normal file

Различия файлов скрыты, потому что одна или несколько строк слишком длинны