Skip to content

Commit 37b9b70

Browse files
committed
PR Feedback
1 parent fa7f3e8 commit 37b9b70

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,23 +188,26 @@ namespace ts.projectSystem {
188188

189189
export function createSession(host: server.ServerHost, opts: Partial<server.SessionOptions> = {}) {
190190
if (opts.typingsInstaller === undefined) {
191-
opts.typingsInstaller = new TestTypingsInstaller("/a/data/", /*throttleLimit*/5, host);
191+
opts.typingsInstaller = new TestTypingsInstaller("/a/data/", /*throttleLimit*/ 5, host);
192192
}
193+
193194
if (opts.eventHandler !== undefined) {
194195
opts.canUseEvents = true;
195196
}
196-
return new TestSession({
197+
198+
const sessionOptions: server.SessionOptions = {
197199
host,
198200
cancellationToken: server.nullCancellationToken,
199201
useSingleInferredProject: false,
200202
useInferredProjectPerProjectRoot: false,
201-
typingsInstaller: opts.typingsInstaller,
203+
typingsInstaller: undefined,
202204
byteLength: Utils.byteLength,
203205
hrtime: process.hrtime,
204206
logger: nullLogger,
205-
canUseEvents: false,
206-
...opts
207-
});
207+
canUseEvents: false
208+
};
209+
210+
return new TestSession({ ...sessionOptions, ...opts });
208211
}
209212

210213
export interface CreateProjectServiceParameters {

src/server/editorServices.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -467,27 +467,28 @@ namespace ts.server {
467467
}
468468

469469
setCompilerOptionsForInferredProjects(projectCompilerOptions: protocol.ExternalProjectCompilerOptions, projectRootPath?: string): void {
470-
// ignore this settings if we are not creating inferred projects per project root.
471-
if (projectRootPath && !this.useInferredProjectPerProjectRoot) return;
470+
Debug.assert(projectRootPath === undefined || this.useInferredProjectPerProjectRoot, "Setting compiler options per project root path is only supported when useInferredProjectPerProjectRoot is enabled");
472471

473-
const compilerOptionsForInferredProjects = convertCompilerOptions(projectCompilerOptions);
472+
const compilerOptions = convertCompilerOptions(projectCompilerOptions);
474473

475474
// always set 'allowNonTsExtensions' for inferred projects since user cannot configure it from the outside
476475
// previously we did not expose a way for user to change these settings and this option was enabled by default
477-
compilerOptionsForInferredProjects.allowNonTsExtensions = true;
476+
compilerOptions.allowNonTsExtensions = true;
478477

479478
if (projectRootPath) {
480-
this.compilerOptionsForInferredProjectsPerProjectRoot.set(projectRootPath, compilerOptionsForInferredProjects);
479+
this.compilerOptionsForInferredProjectsPerProjectRoot.set(projectRootPath, compilerOptions);
481480
}
482481
else {
483-
this.compilerOptionsForInferredProjects = compilerOptionsForInferredProjects;
482+
this.compilerOptionsForInferredProjects = compilerOptions;
484483
}
485484

486485
const updatedProjects: Project[] = [];
487486
for (const project of this.inferredProjects) {
488-
if (project.projectRootPath === projectRootPath || (project.projectRootPath && !this.compilerOptionsForInferredProjectsPerProjectRoot.has(project.projectRootPath))) {
489-
project.setCompilerOptions(compilerOptionsForInferredProjects);
490-
project.compileOnSaveEnabled = compilerOptionsForInferredProjects.compileOnSave;
487+
if (projectRootPath ?
488+
project.projectRootPath === projectRootPath :
489+
!project.projectRootPath || !this.compilerOptionsForInferredProjectsPerProjectRoot.has(project.projectRootPath)) {
490+
project.setCompilerOptions(compilerOptions);
491+
project.compileOnSaveEnabled = compilerOptions.compileOnSave;
491492
updatedProjects.push(project);
492493
}
493494
}
@@ -1319,7 +1320,8 @@ namespace ts.server {
13191320
return this.createInferredProject(/*isSingleInferredProject*/ false, projectRootPath);
13201321
}
13211322

1322-
// we don't have an explicit root path, so we should try to find an inferred project that best matches the file.
1323+
// we don't have an explicit root path, so we should try to find an inferred project
1324+
// that more closely contains the file.
13231325
let bestMatch: InferredProject;
13241326
for (const project of this.inferredProjects) {
13251327
// ignore single inferred projects (handled elsewhere)
@@ -1340,6 +1342,14 @@ namespace ts.server {
13401342
return undefined;
13411343
}
13421344

1345+
// If `useInferredProjectPerProjectRoot` is not enabled, then there will only be one
1346+
// inferred project for all files. If `useInferredProjectPerProjectRoot` is enabled
1347+
// then we want to put all files that are not opened with a `projectRootPath` into
1348+
// the same inferred project.
1349+
//
1350+
// To avoid the cost of searching through the array and to optimize for the case where
1351+
// `useInferredProjectPerProjectRoot` is not enabled, we will always put the inferred
1352+
// project for non-rooted files at the front of the array.
13431353
if (this.inferredProjects.length > 0 && this.inferredProjects[0].projectRootPath === undefined) {
13441354
return this.inferredProjects[0];
13451355
}

0 commit comments

Comments
 (0)