added more tests for cases when typingOptions are provided by external projects, set typing options after root files are added

This commit is contained in:
Vladimir Matveev 2016-08-24 13:37:03 -07:00
parent 8fe0d2d6df
commit dd979e8ede
5 changed files with 169 additions and 54 deletions

View File

@ -46,7 +46,6 @@ namespace ts {
}
onProjectClosed(p: server.Project) {
}
attach(projectService: server.ProjectService) {
@ -114,6 +113,32 @@ namespace ts {
fileOrFolderList);
}
interface CreateProjectServiceParameters {
cancellationToken?: HostCancellationToken;
logger?: server.Logger;
useSingleInferredProject?: boolean;
typingsInstaller?: server.ITypingsInstaller;
eventHandler?: server.ProjectServiceEventHandler;
}
class TestProjectService extends server.ProjectService {
constructor(host: server.ServerHost, logger: server.Logger, cancellationToken: HostCancellationToken, useSingleInferredProject: boolean,
typingsInstaller: server.ITypingsInstaller, eventHandler: server.ProjectServiceEventHandler) {
super(host, logger, cancellationToken, useSingleInferredProject, typingsInstaller, eventHandler);
}
checkNumberOfProjects(count: { inferredProjects?: number, configuredProjects?: number, externalProjects?: number }) {
checkNumberOfProjects(this, count);
}
}
function createProjectService(host: server.ServerHost, parameters: CreateProjectServiceParameters = {}) {
const cancellationToken = parameters.cancellationToken || nullCancellationToken;
const logger = parameters.logger || nullLogger;
const useSingleInferredProject = parameters.useSingleInferredProject !== undefined ? parameters.useSingleInferredProject : false;
return new TestProjectService(host, logger, cancellationToken, useSingleInferredProject, parameters.typingsInstaller, parameters.eventHandler);
}
interface FileOrFolder {
path: string;
content?: string;
@ -495,7 +520,7 @@ namespace ts {
content: `export let x: number`
};
const host = createServerHost([appFile, moduleFile, libFile]);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useOneInferredProject*/ false, /*typingsInstaller*/ undefined);
const projectService = createProjectService(host);
const { configFileName } = projectService.openClientFile(appFile.path);
assert(!configFileName, `should not find config, got: '${configFileName}`);
@ -533,7 +558,7 @@ namespace ts {
};
const host = createServerHost([configFile, libFile, file1, file2, file3]);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useOneInferredProject*/ false, /*typingsInstaller*/ undefined);
const projectService = createProjectService(host);
const { configFileName, configFileErrors } = projectService.openClientFile(file1.path);
assert(configFileName, "should find config file");
@ -560,7 +585,7 @@ namespace ts {
const host = createServerHost(filesWithoutConfig);
const filesWithConfig = [libFile, commonFile1, commonFile2, configFile];
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useOneInferredProject*/ false, /*typingsInstaller*/ undefined);
const projectService = createProjectService(host);
projectService.openClientFile(commonFile1.path);
projectService.openClientFile(commonFile2.path);
@ -591,7 +616,7 @@ namespace ts {
content: `{}`
};
const host = createServerHost([commonFile1, libFile, configFile]);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useOneInferredProject*/ false, /*typingsInstaller*/ undefined);
const projectService = createProjectService(host);
projectService.openClientFile(commonFile1.path);
checkWatchedDirectories(host, ["/a/b"]);
checkNumberOfConfiguredProjects(projectService, 1);
@ -619,7 +644,7 @@ namespace ts {
}`
};
const host = createServerHost([commonFile1, commonFile2, configFile]);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useOneInferredProject*/ false, /*typingsInstaller*/ undefined);
const projectService = createProjectService(host);
projectService.openClientFile(commonFile1.path);
projectService.openClientFile(commonFile2.path);
@ -635,7 +660,7 @@ namespace ts {
content: `{}`
};
const host = createServerHost([commonFile1, commonFile2, configFile]);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useOneInferredProject*/ false, /*typingsInstaller*/ undefined);
const projectService = createProjectService(host);
projectService.openClientFile(commonFile1.path);
checkNumberOfConfiguredProjects(projectService, 1);
@ -665,7 +690,7 @@ namespace ts {
};
const files = [commonFile1, commonFile2, configFile];
const host = createServerHost(files);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useOneInferredProject*/ false, /*typingsInstaller*/ undefined);
const projectService = createProjectService(host);
projectService.openClientFile(commonFile1.path);
const project = projectService.configuredProjects[0];
@ -698,7 +723,7 @@ namespace ts {
};
const host = createServerHost([commonFile1, commonFile2, excludedFile1, configFile]);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useOneInferredProject*/ false, /*typingsInstaller*/ undefined);
const projectService = createProjectService(host);
projectService.openClientFile(commonFile1.path);
checkNumberOfConfiguredProjects(projectService, 1);
@ -732,7 +757,7 @@ namespace ts {
};
const files = [file1, nodeModuleFile, classicModuleFile, configFile];
const host = createServerHost(files);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useOneInferredProject*/ false, /*typingsInstaller*/ undefined);
const projectService = createProjectService(host);
projectService.openClientFile(file1.path);
projectService.openClientFile(nodeModuleFile.path);
projectService.openClientFile(classicModuleFile.path);
@ -773,7 +798,7 @@ namespace ts {
}`
};
const host = createServerHost([file1, file2, configFile]);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useOneInferredProject*/ false, /*typingsInstaller*/ undefined);
const projectService = createProjectService(host);
projectService.openClientFile(file1.path);
projectService.closeClientFile(file1.path);
projectService.openClientFile(file2.path);
@ -800,7 +825,7 @@ namespace ts {
}`
};
const host = createServerHost([file1, file2, configFile]);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useOneInferredProject*/ false, /*typingsInstaller*/ undefined);
const projectService = createProjectService(host);
projectService.openClientFile(file1.path);
projectService.closeClientFile(file1.path);
projectService.openClientFile(file2.path);
@ -833,7 +858,7 @@ namespace ts {
};
const host = createServerHost([file1, file2, file3, libFile]);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useOneInferredProject*/ true, /*typingsInstaller*/ undefined);
const projectService = createProjectService(host, { useSingleInferredProject: true });
projectService.openClientFile(file1.path);
projectService.openClientFile(file2.path);
projectService.openClientFile(file3.path);
@ -866,7 +891,7 @@ namespace ts {
}`
};
const host = createServerHost([file1, configFile, libFile]);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useOneInferredProject*/ true, /*typingsInstaller*/ undefined);
const projectService = createProjectService(host, { useSingleInferredProject: true });
projectService.openClientFile(file1.path);
checkNumberOfConfiguredProjects(projectService, 1);
@ -885,7 +910,7 @@ namespace ts {
};
const externalProjectName = "externalproject";
const host = createServerHost([file1, file2]);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useOneInferredProject*/ false, /*typingsInstaller*/ undefined);
const projectService = createProjectService(host);
projectService.openExternalProject({
rootFiles: toExternalFiles([file1.path, file2.path]),
options: {},
@ -943,7 +968,7 @@ namespace ts {
};
const externalProjectName = "externalproject";
const host = createServerHost([file1, file2, file3, config1, config2]);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useOneInferredProject*/ false, /*typingsInstaller*/ undefined);
const projectService = createProjectService(host);
projectService.openExternalProject({
rootFiles: toExternalFiles([config1.path, config2.path, file3.path]),
options: {},
@ -981,7 +1006,7 @@ namespace ts {
};
const externalProjectName = "externalproject";
const host = createServerHost([file1, configFile]);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useOneInferredProject*/ false, /*typingsInstaller*/ undefined);
const projectService = createProjectService(host);
projectService.openClientFile(file1.path);
checkNumberOfProjects(projectService, { configuredProjects: 1 });
@ -1012,7 +1037,7 @@ namespace ts {
};
const externalProjectName = "externalproject";
const host = createServerHost([file1, configFile]);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useOneInferredProject*/ false, /*typingsInstaller*/ undefined);
const projectService = createProjectService(host);
projectService.openClientFile(file1.path);
checkNumberOfProjects(projectService, { configuredProjects: 1 });
@ -1047,7 +1072,7 @@ namespace ts {
content: `export let y = 1;`
};
const host = createServerHost([file1, file2, file3]);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useSingleInferredProject*/ false, /*typingsInstaller*/ undefined);
const projectService = createProjectService(host);
projectService.openClientFile(file1.path);
@ -1084,7 +1109,7 @@ namespace ts {
content: `export let y = 1;`
};
const host = createServerHost([file1, file2, file3]);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useSingleInferredProject*/ false, /*typingsInstaller*/ undefined);
const projectService = createProjectService(host);
projectService.openClientFile(file1.path);
@ -1123,7 +1148,7 @@ namespace ts {
};
const host = createServerHost([file1, file2, file3]);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useSingleInferredProject*/ false, /*typingsInstaller*/ undefined);
const projectService = createProjectService(host);
projectService.openClientFile(file1.path);
checkNumberOfProjects(projectService, { inferredProjects: 1 });
@ -1156,7 +1181,7 @@ namespace ts {
content: "export let y = 1;"
};
const host = createServerHost([file1, file2, file3]);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useSingleInferredProject*/ false, /*typingsInstaller*/ undefined);
const projectService = createProjectService(host);
projectService.openClientFile(file2.path);
checkNumberOfProjects(projectService, { inferredProjects: 1 });
@ -1191,7 +1216,7 @@ namespace ts {
};
const host = createServerHost([file1, configFile]);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useSingleInferredProject*/ false, /*typingsInstaller*/ undefined);
const projectService = createProjectService(host);
projectService.openClientFile(file1.path);
checkNumberOfProjects(projectService, { configuredProjects: 1 });
@ -1222,7 +1247,7 @@ namespace ts {
};
const host = createServerHost([file1, file2, configFile]);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useSingleInferredProject*/ false, /*typingsInstaller*/ undefined);
const projectService = createProjectService(host);
projectService.openClientFile(file1.path);
checkNumberOfProjects(projectService, { configuredProjects: 1 });
@ -1255,7 +1280,7 @@ namespace ts {
};
const host = createServerHost([file1, file2, configFile]);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useSingleInferredProject*/ false, /*typingsInstaller*/ undefined);
const projectService = createProjectService(host);
projectService.openClientFile(file1.path);
checkNumberOfProjects(projectService, { configuredProjects: 1 });
@ -1283,7 +1308,7 @@ namespace ts {
content: "let y = 1"
};
const host = createServerHost([file1, file2]);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useSingleInferredProject*/ false, /*typingsInstaller*/ undefined);
const projectService = createProjectService(host);
projectService.openExternalProject({ projectFileName: "project", options: {}, rootFiles: toExternalFiles([file1.path]) });
checkNumberOfProjects(projectService, { externalProjects: 1 });
@ -1309,7 +1334,7 @@ namespace ts {
};
const host = createServerHost([file1, file2, file3]);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useSingleInferredProject*/ false, /*typingsInstaller*/ undefined);
const projectService = createProjectService(host);
projectService.openExternalProject({ projectFileName: "project", options: { moduleResolution: ModuleResolutionKind.NodeJs }, rootFiles: toExternalFiles([file1.path, file2.path]) });
checkNumberOfProjects(projectService, { externalProjects: 1 });
@ -1336,7 +1361,7 @@ namespace ts {
content: JSON.stringify({ compilerOptions: {} })
};
const host = createServerHost([file1, file2, config]);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useSingleInferredProject*/ false, /*typingsInstaller*/ undefined);
const projectService = createProjectService(host);
projectService.openClientFile(file1.path);
checkNumberOfProjects(projectService, { configuredProjects: 1 });
@ -1364,7 +1389,7 @@ namespace ts {
content: "export let x = 1"
};
const host = createServerHost([file1, file2]);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useSingleInferredProject*/ false, /*typingsInstaller*/ undefined);
const projectService = createProjectService(host);
projectService.openClientFile(file1.path);
projectService.openClientFile(file2.path);
@ -1389,7 +1414,7 @@ namespace ts {
content: `<html><script language="javascript">var x = 1;</></html>`
};
const host = createServerHost([file1]);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useSingleInferredProject*/ false, /*typingsInstaller*/ undefined);
const projectService = createProjectService(host);
const projectFileName = "projectFileName";
projectService.openExternalProject({ projectFileName, options: {}, rootFiles: [{ fileName: file1.path, scriptKind: ScriptKind.JS, hasMixedContent: true }] });
@ -1427,7 +1452,7 @@ namespace ts {
content: "export let x: number"
};
const host = createServerHost([file1, modFile]);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useSingleInferredProject*/ false, /*typingsInstaller*/ undefined);
const projectService = createProjectService(host);
projectService.openClientFile(file1.path);
projectService.openClientFile(modFile.path);
@ -1444,7 +1469,7 @@ namespace ts {
content: "{x: 1}"
};
const host = createServerHost([file1]);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useSingleInferredProject*/ true, /*typingsInstaller*/ undefined);
const projectService = createProjectService(host, { useSingleInferredProject: true });
projectService.setCompilerOptionsForInferredProjects({ target: ScriptTarget.ES5, allowJs: false });
projectService.openClientFile(file1.path);
projectService.inferredProjects[0].getLanguageService(/*ensureSynchronized*/ false).getOutliningSpans(file1.path);
@ -1472,7 +1497,7 @@ namespace ts {
content: "{}"
};
const host = createServerHost([file1, file2, tsconfig1, tsconfig2]);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useSingleInferredProject*/ false, /*typingsInstaller*/ undefined);
const projectService = createProjectService(host);
projectService.openClientFile(file2.path);
checkNumberOfProjects(projectService, { configuredProjects: 1 });
@ -1909,7 +1934,7 @@ namespace ts {
const host = createServerHost([file1, tsconfig, packageJson]);
const installer = new TestTypingsInstaller("/a/data/", host);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useSingleInferredProject*/ true, installer);
const projectService = createProjectService(host, { useSingleInferredProject: true, typingsInstaller: installer });
projectService.openClientFile(file1.path);
checkNumberOfProjects(projectService, { configuredProjects: 1 });
@ -1949,7 +1974,7 @@ namespace ts {
const host = createServerHost([file1, packageJson]);
const installer = new TestTypingsInstaller("/a/data/", host);
const projectService = new server.ProjectService(host, nullLogger, nullCancellationToken, /*useSingleInferredProject*/ true, installer);
const projectService = createProjectService(host, { useSingleInferredProject: true, typingsInstaller: installer });
projectService.openClientFile(file1.path);
checkNumberOfProjects(projectService, { inferredProjects: 1 });
@ -1966,5 +1991,97 @@ namespace ts {
checkNumberOfProjects(projectService, { inferredProjects: 1 });
checkProjectActualFiles(p, [ file1.path, jquery.path ]);
});
it ("external project - no typing options, no .d.ts/js files", () => {
const file1 = {
path: "/a/b/app.ts",
content: ""
};
const host = createServerHost([file1]);
const installer = new (class extends TestTypingsInstaller {
constructor() {
super("", host);
}
enqueueInstallTypingsRequest() {
assert(false, "auto discovery should not be enabled");
}
})();
const projectFileName = "/a/app/test.csproj";
const projectService = createProjectService(host, { typingsInstaller: installer });
projectService.openExternalProject({
projectFileName,
options: {},
rootFiles: [toExternalFile(file1.path)]
});
// by default auto discovery will kick in if project contain only .js/.d.ts files
// in this case project contain only ts files - no auto discovery
projectService.checkNumberOfProjects({ externalProjects: 1 });
});
it ("external project - no autoDiscovery in typing options, no .d.ts/js files", () => {
const file1 = {
path: "/a/b/app.ts",
content: ""
};
const host = createServerHost([file1]);
const installer = new (class extends TestTypingsInstaller {
constructor() {
super("", host);
}
enqueueInstallTypingsRequest() {
assert(false, "auto discovery should not be enabled");
}
})();
const projectFileName = "/a/app/test.csproj";
const projectService = createProjectService(host, { typingsInstaller: installer });
projectService.openExternalProject({
projectFileName,
options: {},
rootFiles: [toExternalFile(file1.path)],
typingOptions: { include: ["jquery"] }
});
// by default auto discovery will kick in if project contain only .js/.d.ts files
// in this case project contain only ts files - no auto discovery even if typing options is set
projectService.checkNumberOfProjects({ externalProjects: 1 });
});
it ("external project - autoDiscovery = true, no .d.ts/js files", () => {
const file1 = {
path: "/a/b/app.ts",
content: ""
};
const host = createServerHost([file1]);
let enqueueIsCalled = false;
let runTsdIsCalled = false;
const installer = new (class extends TestTypingsInstaller {
constructor() {
super("", host);
}
enqueueInstallTypingsRequest(project: server.Project, typingOptions: TypingOptions) {
enqueueIsCalled = true;
super.enqueueInstallTypingsRequest(project, typingOptions);
}
runTsd(cachePath: string, typingsToInstall: string[], postInstallAction: (installedTypings: string[]) => void): void {
assert.deepEqual(typingsToInstall, ["node"]);
runTsdIsCalled = true;
super.runTsd(cachePath, typingsToInstall, postInstallAction);
}
})();
const projectFileName = "/a/app/test.csproj";
const projectService = createProjectService(host, { typingsInstaller: installer });
projectService.openExternalProject({
projectFileName,
options: {},
rootFiles: [toExternalFile(file1.path)],
typingOptions: { enableAutoDiscovery: true, include: ["node"] }
});
// autoDiscovery is set in typing options - use it even if project contains only .ts files
projectService.checkNumberOfProjects({ externalProjects: 1 });
assert.isTrue(enqueueIsCalled, "expected 'enqueueIsCalled' to be true");
assert.isTrue(runTsdIsCalled, "expected 'runTsdIsCalled' to be true");
});
});
}

View File

@ -711,11 +711,11 @@ namespace ts.server {
this,
this.documentRegistry,
options,
typingOptions,
/*languageServiceEnabled*/ !this.exceededTotalSizeLimitForNonTsFiles(options, files, externalFilePropertyReader),
!!options.compileOnSave);
const errors = this.addFilesToProjectAndUpdateGraph(project, files, externalFilePropertyReader, /*clientFileName*/ undefined);
const errors = this.addFilesToProjectAndUpdateGraph(project, files, externalFilePropertyReader, /*clientFileName*/ undefined, typingOptions);
this.externalProjects.push(project);
return { project, errors };
}
@ -728,12 +728,11 @@ namespace ts.server {
this.documentRegistry,
projectOptions.configHasFilesProperty,
projectOptions.compilerOptions,
projectOptions.typingOptions,
projectOptions.wildcardDirectories,
/*languageServiceEnabled*/ !sizeLimitExceeded,
/*compileOnSaveEnabled*/ !!projectOptions.compileOnSave);
const errors = this.addFilesToProjectAndUpdateGraph(project, projectOptions.files, fileNamePropertyReader, clientFileName);
const errors = this.addFilesToProjectAndUpdateGraph(project, projectOptions.files, fileNamePropertyReader, clientFileName, projectOptions.typingOptions);
project.watchConfigFile(project => this.onConfigChangedForConfiguredProject(project));
if (!sizeLimitExceeded) {
@ -751,7 +750,7 @@ namespace ts.server {
}
}
private addFilesToProjectAndUpdateGraph<T>(project: ConfiguredProject | ExternalProject, files: T[], propertyReader: FilePropertyReader<T>, clientFileName: string): Diagnostic[] {
private addFilesToProjectAndUpdateGraph<T>(project: ConfiguredProject | ExternalProject, files: T[], propertyReader: FilePropertyReader<T>, clientFileName: string, typingOptions: TypingOptions): Diagnostic[] {
let errors: Diagnostic[];
for (const f of files) {
const rootFilename = propertyReader.getFileName(f);
@ -765,6 +764,7 @@ namespace ts.server {
(errors || (errors = [])).push(createCompilerDiagnostic(Diagnostics.File_0_not_found, rootFilename));
}
}
project.setTypingOptions(typingOptions);
project.updateGraph();
return errors;
}

View File

@ -22,8 +22,8 @@ namespace ts.server {
const jsOrDts = [".js", ".d.ts"];
export function allFilesAreJsOrDts(project: Project): boolean {
return project.getFileNames().every(f => fileExtensionIsAny(f, jsOrDts));
export function allRootFilesAreJsOrDts(project: Project): boolean {
return project.getRootScriptInfos().every(f => fileExtensionIsAny(f.fileName, jsOrDts));
}
export abstract class Project {
@ -518,7 +518,7 @@ namespace ts.server {
getTypingOptions(): TypingOptions {
return {
enableAutoDiscovery: allFilesAreJsOrDts(this),
enableAutoDiscovery: allRootFilesAreJsOrDts(this),
include: [],
exclude: []
};
@ -526,6 +526,7 @@ namespace ts.server {
}
export class ConfiguredProject extends Project {
private typingOptions: TypingOptions;
private projectFileWatcher: FileWatcher;
private directoryWatcher: FileWatcher;
private directoriesWatchedForWildcards: Map<FileWatcher>;
@ -537,7 +538,6 @@ namespace ts.server {
documentRegistry: ts.DocumentRegistry,
hasExplicitListOfFiles: boolean,
compilerOptions: CompilerOptions,
private typingOptions: TypingOptions,
private wildcardDirectories: Map<WatchDirectoryFlags>,
languageServiceEnabled: boolean,
public compileOnSaveEnabled = false) {
@ -627,11 +627,9 @@ namespace ts.server {
projectService: ProjectService,
documentRegistry: ts.DocumentRegistry,
compilerOptions: CompilerOptions,
typingOptions: TypingOptions,
languageServiceEnabled: boolean,
public compileOnSaveEnabled = true) {
super(ProjectKind.External, projectService, documentRegistry, /*hasExplicitListOfFiles*/ true, languageServiceEnabled, compilerOptions, compileOnSaveEnabled);
this.setTypingOptions(typingOptions);
}
getTypingOptions() {
@ -642,7 +640,7 @@ namespace ts.server {
if (!newTypingOptions) {
// set default typings options
newTypingOptions = {
enableAutoDiscovery: allFilesAreJsOrDts(this),
enableAutoDiscovery: allRootFilesAreJsOrDts(this),
include: [],
exclude: []
};
@ -650,7 +648,7 @@ namespace ts.server {
else {
if (newTypingOptions.enableAutoDiscovery === undefined) {
// if autoDiscovery was not specified by the caller - set it based on the content of the project
newTypingOptions.enableAutoDiscovery = allFilesAreJsOrDts(this);
newTypingOptions.enableAutoDiscovery = allRootFilesAreJsOrDts(this);
}
if (!newTypingOptions.include) {
newTypingOptions.include = [];

View File

@ -77,7 +77,7 @@ namespace ts.server {
getTypingsForProject(project: Project): TypingsArray {
const typingOptions = project.getTypingOptions();
if (!typingOptions.enableAutoDiscovery) {
if (!typingOptions || !typingOptions.enableAutoDiscovery) {
return <any>emptyArray;
}

View File

@ -29,6 +29,8 @@ namespace ts.JsTyping {
// that we are confident require typings
let safeList: Map<string>;
const EmptySafeList: Map<string> = createMap<string>();
/**
* @param host is the object providing I/O related operations.
* @param fileNames are the file names that belong to the same project
@ -63,7 +65,7 @@ namespace ts.JsTyping {
if (!safeList) {
const result = readConfigFile(safeListPath, (path: string) => host.readFile(path));
safeList = createMap<string>(result.config);
safeList = result.config ? createMap<string>(result.config) : EmptySafeList;
}
const filesToWatch: string[] = [];
@ -163,10 +165,8 @@ namespace ts.JsTyping {
const jsFileNames = filter(fileNames, hasJavaScriptFileExtension);
const inferredTypingNames = map(jsFileNames, f => removeFileExtension(getBaseFileName(f.toLowerCase())));
const cleanedTypingNames = map(inferredTypingNames, f => f.replace(/((?:\.|-)min(?=\.|$))|((?:-|\.)\d+)/g, ""));
if (safeList === undefined) {
mergeTypings(cleanedTypingNames);
}
else {
if (safeList !== EmptySafeList) {
mergeTypings(filter(cleanedTypingNames, f => f in safeList));
}