Skip to content

Commit f99ff77

Browse files
committed
Temp
1 parent 709c1b6 commit f99ff77

File tree

4 files changed

+494
-130
lines changed

4 files changed

+494
-130
lines changed

src/server/editorServices.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,8 @@ enum ProjectAncestorLoadKind {
10011001
FindCreateDelayLoad,
10021002
}
10031003

1004-
enum ConfiguredProjectKind {
1004+
/** @internal */
1005+
export enum ConfiguredProjectKind {
10051006
Find,
10061007
Create,
10071008
Reload,
@@ -1784,7 +1785,7 @@ export class ProjectService {
17841785
}
17851786

17861787
/** @internal */
1787-
private onConfigFileChanged(canonicalConfigFilePath: NormalizedPath, eventKind: FileWatcherEventKind) {
1788+
private onConfigFileChanged(configFileName: NormalizedPath, canonicalConfigFilePath: NormalizedPath, eventKind: FileWatcherEventKind) {
17881789
const configFileExistenceInfo = this.configFileExistenceInfoCache.get(canonicalConfigFilePath)!;
17891790
if (eventKind === FileWatcherEventKind.Deleted) {
17901791
// Update the cached status
@@ -1797,15 +1798,14 @@ export class ProjectService {
17971798
this.getConfiguredProjectByCanonicalConfigFilePath(canonicalConfigFilePath) :
17981799
undefined;
17991800
if (project) this.removeProject(project);
1800-
// TODO:: sheetal configFileForOpenFiles:: update needed when deleting ancestor project
18011801
}
18021802
else {
18031803
// Update the cached status
18041804
configFileExistenceInfo.exists = true;
18051805
}
18061806

18071807
// Update projects watching config
1808-
this.delayUpdateProjectsFromParsedConfigOnConfigFileChange(canonicalConfigFilePath, "Change in config file detected");
1808+
this.delayUpdateProjectsFromParsedConfigOnConfigFileChange(canonicalConfigFilePath, `Change in config file ${configFileName} detected`);
18091809

18101810
// Reload the configured projects for the open files in the map as they are affected by this config file
18111811
// If the configured project was deleted, we want to reload projects for all the open files including files
@@ -1814,11 +1814,11 @@ export class ProjectService {
18141814
// we would need to schedule the project reload for only the root of inferred projects
18151815
// Get open files to reload projects for
18161816
const updatedProjects = new Set<ConfiguredProject>();
1817+
// Add the already scheduled project as updated
1818+
if (configFileExistenceInfo.config?.projects.has(canonicalConfigFilePath)) {
1819+
updatedProjects.add(this.findConfiguredProjectByProjectName(configFileName)!);
1820+
}
18171821
configFileExistenceInfo.openFilesImpactedByConfigFile?.forEach((isRootOfInferredProject, path) => {
1818-
// Filter out the files that need to be ignored
1819-
// If file is added or modified, reload the project only for open files that are not root of inferred project
1820-
if (eventKind !== FileWatcherEventKind.Deleted && !isRootOfInferredProject) return;
1821-
18221822
// Invalidate default config file name for open file
18231823
this.configFileForOpenFiles.delete(path);
18241824

@@ -1833,11 +1833,10 @@ export class ProjectService {
18331833
const project = this.findConfiguredProjectByProjectName(configFileName) || this.createConfiguredProject(configFileName);
18341834
if (tryAddToSet(updatedProjects, project)) {
18351835
project.pendingUpdateLevel = ProgramUpdateLevel.Full;
1836-
project.pendingUpdateReason = "Change in config file detected";
1836+
project.pendingUpdateReason = `Change in config file ${configFileName} detected`;
18371837
this.delayUpdateProjectGraph(project);
18381838
}
1839-
// TODO:: After this update we need to ensure that we try and create Project for the open script info (through refs etc)
1840-
// TODO:: sheetal: ensureProjectForOpenFile needs to handle that?
1839+
(project.pendingOpenFileProjectUpdates ??= new Set()).add(path);
18411840
}
18421841
});
18431842

@@ -2087,7 +2086,7 @@ export class ProjectService {
20872086
if (!configFileExistenceInfo.watcher || configFileExistenceInfo.watcher === noopConfigFileWatcher) {
20882087
configFileExistenceInfo.watcher = this.watchFactory.watchFile(
20892088
configFileName,
2090-
(_fileName, eventKind) => this.onConfigFileChanged(canonicalConfigFilePath, eventKind),
2089+
(_fileName, eventKind) => this.onConfigFileChanged(configFileName, canonicalConfigFilePath, eventKind),
20912090
PollingInterval.High,
20922091
this.getWatchOptionsFromProjectWatchOptions(configFileExistenceInfo?.config?.parsedCommandLine?.watchOptions),
20932092
WatchType.ConfigFile,
@@ -2217,7 +2216,7 @@ export class ProjectService {
22172216
configFileExistenceInfo.watcher ||= canWatchDirectoryOrFile(getPathComponents(getDirectoryPath(canonicalConfigFilePath) as Path)) ?
22182217
this.watchFactory.watchFile(
22192218
configFileName,
2220-
(_filename, eventKind) => this.onConfigFileChanged(canonicalConfigFilePath, eventKind),
2219+
(_filename, eventKind) => this.onConfigFileChanged(configFileName, canonicalConfigFilePath, eventKind),
22212220
PollingInterval.High,
22222221
this.hostConfiguration.watchOptions,
22232222
WatchType.ConfigFileForInferredRoot,
@@ -3828,9 +3827,11 @@ export class ProjectService {
38283827
return info;
38293828
}
38303829

3831-
private tryFindDefaultConfiguredProjectForOpenScriptInfo(info: ScriptInfo, kind: ConfiguredProjectKind.Find | ConfiguredProjectKind.Create): DefaultConfiguredProjectResult | undefined;
3832-
private tryFindDefaultConfiguredProjectForOpenScriptInfo(info: ScriptInfo, kind: ConfiguredProjectKind.Reload, reloadedProjects: Set<ConfiguredProject>): DefaultConfiguredProjectResult | undefined;
3833-
private tryFindDefaultConfiguredProjectForOpenScriptInfo(info: ScriptInfo, kind: ConfiguredProjectKind, reloadedProjects?: Set<ConfiguredProject>): string | DefaultConfiguredProjectResult | undefined {
3830+
/** @internal */
3831+
tryFindDefaultConfiguredProjectForOpenScriptInfo(info: ScriptInfo, kind: ConfiguredProjectKind.Find | ConfiguredProjectKind.Create): DefaultConfiguredProjectResult | undefined;
3832+
/** @internal */
3833+
tryFindDefaultConfiguredProjectForOpenScriptInfo(info: ScriptInfo, kind: ConfiguredProjectKind.Reload, reloadedProjects: Set<ConfiguredProject>): DefaultConfiguredProjectResult | undefined;
3834+
tryFindDefaultConfiguredProjectForOpenScriptInfo(info: ScriptInfo, kind: ConfiguredProjectKind, reloadedProjects?: Set<ConfiguredProject>): string | DefaultConfiguredProjectResult | undefined {
38343835
const configFileName = this.getConfigFileNameForFile(info, kind === ConfiguredProjectKind.Find);
38353836
if (!configFileName) return;
38363837
let project = this.findConfiguredProjectByProjectName(configFileName);

src/server/project.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ import {
135135
import {
136136
ActionInvalidate,
137137
asNormalizedPath,
138+
ConfiguredProjectKind,
138139
createModuleSpecifierCache,
139140
emptyArray,
140141
Errors,
@@ -2671,6 +2672,8 @@ export class ConfiguredProject extends Project {
26712672
pendingUpdateLevel: ProgramUpdateLevel | undefined;
26722673
/** @internal */
26732674
pendingUpdateReason: string | undefined;
2675+
/** @internal */
2676+
pendingOpenFileProjectUpdates: Set<Path> | undefined;
26742677

26752678
/** @internal */
26762679
openFileWatchTriggered = new Map<string, ProgramUpdateLevel>();
@@ -2762,6 +2765,8 @@ export class ConfiguredProject extends Project {
27622765
const isInitialLoad = this.isInitialLoadPending();
27632766
this.isInitialLoadPending = returnFalse;
27642767
const updateLevel = this.pendingUpdateLevel;
2768+
const pendingOpenFileProjectUpdates = this.pendingOpenFileProjectUpdates;
2769+
this.pendingOpenFileProjectUpdates = undefined;
27652770
this.pendingUpdateLevel = ProgramUpdateLevel.Update;
27662771
let result: boolean;
27672772
switch (updateLevel) {
@@ -2781,6 +2786,13 @@ export class ConfiguredProject extends Project {
27812786
this.compilerHost = undefined;
27822787
this.projectService.sendProjectLoadingFinishEvent(this);
27832788
this.projectService.sendProjectTelemetry(this);
2789+
2790+
pendingOpenFileProjectUpdates?.forEach(path => {
2791+
const info = this.projectService.getScriptInfoForPath(path);
2792+
if (info && this.projectService.openFiles.has(info.path)) {
2793+
this.projectService.tryFindDefaultConfiguredProjectForOpenScriptInfo(info, ConfiguredProjectKind.Create);
2794+
}
2795+
});
27842796
return result;
27852797
}
27862798

src/testRunner/unittests/tsserver/projectReferences.ts

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,7 @@ const b: B = new B();`,
16901690
/* eslint-enable local/argument-trivia */
16911691
});
16921692

1693-
it("when file is not in the first project found but is contained by project from solution", () => {
1693+
it("when file is not in the first project found but is contained by project from solution sheetal", () => {
16941694
const appDemo: File = {
16951695
path: "/home/src/projects/project/app/Component-demos.ts",
16961696
content: dedent`
@@ -1768,11 +1768,6 @@ const b: B = new B();`,
17681768
files: [appDemo],
17691769
session,
17701770
});
1771-
const info = session.getProjectService().getScriptInfo(appDemo.path)!;
1772-
session.logger.startGroup();
1773-
session.logger.info(`getDefaultProject for ${appDemo.path}: ${info.getDefaultProject().projectName}`);
1774-
session.logger.info(`findDefaultConfiguredProject for ${appDemo.path}: ${session.getProjectService().findDefaultConfiguredProject(info)?.projectName}`);
1775-
session.logger.endGroup();
17761771
verifyProjectManagement(); // Should not remove projects for file
17771772

17781773
closeFilesForSession([appDemo], session);
@@ -1800,26 +1795,30 @@ const b: B = new B();`,
18001795

18011796
baselineTsserverLogs("projectReferences", "when file is not in the first project found but is contained by project from solution", session);
18021797

1798+
function printDefaultProject() {
1799+
const info = session.getProjectService().getScriptInfo(appDemo.path);
1800+
session.logger.startGroup();
1801+
session.logger.info(`getDefaultProject: ${session.getProjectService().tryGetDefaultProjectForFile(appDemo.path as ts.server.NormalizedPath)?.projectName}`);
1802+
session.logger.info(`findDefaultConfiguredProject: ${info && session.getProjectService().findDefaultConfiguredProject(info)?.projectName}`);
1803+
session.logger.endGroup();
1804+
}
1805+
18031806
function verifyProjectManagement() {
1807+
printDefaultProject();
18041808
openFilesForSession([randomTs], session); // Verify Project management
18051809
closeFilesForSession([randomTs], session);
1810+
printDefaultProject();
18061811
}
18071812

18081813
function verifyAppConfigNotComposite(projManagementBeforeRevert: boolean) {
18091814
// Not composite
1810-
host.writeFile(appConfig.path, appConfig.content.replace(`"composite": true,`, ""));
1811-
host.runQueuedTimeoutCallbacks();
1812-
if (projManagementBeforeRevert) verifyProjectManagement();
1813-
// Revert
1814-
host.writeFile(appConfig.path, appConfig.content);
1815-
host.runQueuedTimeoutCallbacks();
1816-
if (!projManagementBeforeRevert) verifyProjectManagement();
1815+
verifyConfigChange(appConfig, appConfig.content.replace(`"composite": true,`, ""), projManagementBeforeRevert);
18171816
}
18181817

18191818
function verifySolutionConfigNotComposite(projManagementBeforeRevert: boolean) {
18201819
// Not referencing demos
1821-
host.writeFile(
1822-
solutionConfig.path,
1820+
verifyConfigChange(
1821+
solutionConfig,
18231822
jsonToReadableText({
18241823
compilerOptions: {
18251824
outDir: "./dist/",
@@ -1828,35 +1827,31 @@ const b: B = new B();`,
18281827
{ path: "./app/tsconfig.json" },
18291828
],
18301829
}),
1830+
projManagementBeforeRevert,
18311831
);
1832-
host.runQueuedTimeoutCallbacks();
1833-
if (projManagementBeforeRevert) verifyProjectManagement();
1834-
// Revert
1835-
host.writeFile(solutionConfig.path, solutionConfig.content);
1836-
host.runQueuedTimeoutCallbacks();
1837-
if (!projManagementBeforeRevert) verifyProjectManagement();
18381832
}
18391833

18401834
function verifySolutionConfigDelete(projManagementBeforeRevert: boolean) {
1841-
// Not referencing demos
1842-
host.deleteFile(solutionConfig.path);
1843-
host.runQueuedTimeoutCallbacks();
1844-
if (projManagementBeforeRevert) verifyProjectManagement();
1845-
// Revert
1846-
host.writeFile(solutionConfig.path, solutionConfig.content);
1847-
host.runQueuedTimeoutCallbacks();
1848-
if (!projManagementBeforeRevert) verifyProjectManagement();
1835+
// Delete solution file
1836+
verifyConfigChange(solutionConfig, /*change*/ undefined, projManagementBeforeRevert);
18491837
}
18501838

18511839
function verfiyDemoConfigChange(projManagementBeforeRevert: boolean) {
18521840
// Make some errors in demo::
1853-
host.writeFile(demoConfig.path, demoConfig.content.replace(`"../app/**/*-demos.*"`, ""));
1841+
verifyConfigChange(demoConfig, demoConfig.content.replace(`"../app/**/*-demos.*"`, ""), projManagementBeforeRevert);
1842+
}
1843+
1844+
function verifyConfigChange(config: File, change: string | undefined, projManagementBeforeRevert: boolean) {
1845+
if (change !== undefined) host.writeFile(config.path, change);
1846+
else host.deleteFile(config.path);
18541847
host.runQueuedTimeoutCallbacks();
18551848
if (projManagementBeforeRevert) verifyProjectManagement();
1849+
else printDefaultProject();
18561850
// Revert
1857-
host.writeFile(demoConfig.path, demoConfig.content);
1851+
host.writeFile(config.path, config.content);
18581852
host.runQueuedTimeoutCallbacks();
18591853
if (!projManagementBeforeRevert) verifyProjectManagement();
1854+
else printDefaultProject();
18601855
}
18611856
});
18621857
});

0 commit comments

Comments
 (0)