Use inherited setCompilerOptions for inferred project

This commit is contained in:
zhengbli
2016-12-28 14:46:58 -08:00
parent a8a1a826b3
commit bf5faa04a6
3 changed files with 29 additions and 12 deletions

View File

@@ -1072,6 +1072,10 @@ namespace ts.server {
? this.inferredProjects[0]
: new InferredProject(this, this.documentRegistry, this.compilerOptionsForInferredProjects);
if (root.scriptKind === ScriptKind.JS || root.scriptKind === ScriptKind.JSX) {
project.isJsInferredProject = true;
}
project.addRoot(root);
this.directoryWatchers.startWatchingContainingDirectoriesForFile(
@@ -1079,12 +1083,6 @@ namespace ts.server {
project,
fileName => this.onConfigFileAddedForInferredProject(fileName));
if (root.scriptKind === ScriptKind.JS || root.scriptKind === ScriptKind.JSX) {
const options = project.getCompilerOptions();
options.maxNodeModuleJsDepth = 2;
project.setCompilerOptions(options);
}
project.updateGraph();
if (!useExistingProject) {

View File

@@ -566,9 +566,6 @@ namespace ts.server {
setCompilerOptions(compilerOptions: CompilerOptions) {
if (compilerOptions) {
if (this.projectKind === ProjectKind.Inferred) {
compilerOptions.allowJs = true;
}
compilerOptions.allowNonTsExtensions = true;
if (changesAffectModuleResolution(this.compilerOptions, compilerOptions)) {
// reset cached unresolved imports if changes in compiler options affected module resolution
@@ -715,6 +712,26 @@ namespace ts.server {
}
})();
private _isJsInferredProject = false;
set isJsInferredProject(newValue: boolean) {
if (newValue && !this._isJsInferredProject) {
this.setCompilerOptions(this.getCompilerOptions());
}
this._isJsInferredProject = newValue;
}
setCompilerOptions(newOptions: CompilerOptions) {
if (!newOptions) {
return;
}
if (this._isJsInferredProject && typeof newOptions.maxNodeModuleJsDepth !== "number") {
newOptions.maxNodeModuleJsDepth = 2;
}
newOptions.allowJs = true;
super.setCompilerOptions(newOptions);
}
// Used to keep track of what directories are watched for this project
directoriesWatchedForTsconfig: string[] = [];