Skip to content

Commit bf5faa0

Browse files
committed
Use inherited setCompilerOptions for inferred project
1 parent a8a1a82 commit bf5faa0

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3068,9 +3068,11 @@ namespace ts.projectSystem {
30683068
projectService.openClientFile(file1.path);
30693069

30703070
const project = projectService.inferredProjects[0];
3071-
const sourceFile = project.getSourceFile(<Path>file1.path);
3072-
assert.isTrue("test" in sourceFile.resolvedModules);
3073-
assert.equal((<ResolvedModule>sourceFile.resolvedModules["test"]).resolvedFileName, moduleFile.path);
3071+
const sourceFileForFile1 = project.getSourceFile(<Path>file1.path);
3072+
const sourceFileForModuleFile = project.getSourceFile(<Path>moduleFile.path);
3073+
3074+
assert.isNotNull(sourceFileForFile1);
3075+
assert.isNotNull(sourceFileForModuleFile);
30743076
});
30753077
});
30763078

src/server/editorServices.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,19 +1072,17 @@ namespace ts.server {
10721072
? this.inferredProjects[0]
10731073
: new InferredProject(this, this.documentRegistry, this.compilerOptionsForInferredProjects);
10741074

1075+
if (root.scriptKind === ScriptKind.JS || root.scriptKind === ScriptKind.JSX) {
1076+
project.isJsInferredProject = true;
1077+
}
1078+
10751079
project.addRoot(root);
10761080

10771081
this.directoryWatchers.startWatchingContainingDirectoriesForFile(
10781082
root.fileName,
10791083
project,
10801084
fileName => this.onConfigFileAddedForInferredProject(fileName));
10811085

1082-
if (root.scriptKind === ScriptKind.JS || root.scriptKind === ScriptKind.JSX) {
1083-
const options = project.getCompilerOptions();
1084-
options.maxNodeModuleJsDepth = 2;
1085-
project.setCompilerOptions(options);
1086-
}
1087-
10881086
project.updateGraph();
10891087

10901088
if (!useExistingProject) {

src/server/project.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,9 +566,6 @@ namespace ts.server {
566566

567567
setCompilerOptions(compilerOptions: CompilerOptions) {
568568
if (compilerOptions) {
569-
if (this.projectKind === ProjectKind.Inferred) {
570-
compilerOptions.allowJs = true;
571-
}
572569
compilerOptions.allowNonTsExtensions = true;
573570
if (changesAffectModuleResolution(this.compilerOptions, compilerOptions)) {
574571
// reset cached unresolved imports if changes in compiler options affected module resolution
@@ -715,6 +712,26 @@ namespace ts.server {
715712
}
716713
})();
717714

715+
private _isJsInferredProject = false;
716+
set isJsInferredProject(newValue: boolean) {
717+
if (newValue && !this._isJsInferredProject) {
718+
this.setCompilerOptions(this.getCompilerOptions());
719+
}
720+
this._isJsInferredProject = newValue;
721+
}
722+
723+
setCompilerOptions(newOptions: CompilerOptions) {
724+
if (!newOptions) {
725+
return;
726+
}
727+
728+
if (this._isJsInferredProject && typeof newOptions.maxNodeModuleJsDepth !== "number") {
729+
newOptions.maxNodeModuleJsDepth = 2;
730+
}
731+
newOptions.allowJs = true;
732+
super.setCompilerOptions(newOptions);
733+
}
734+
718735
// Used to keep track of what directories are watched for this project
719736
directoriesWatchedForTsconfig: string[] = [];
720737

0 commit comments

Comments
 (0)