fix: improve loading state management in project context updates. (#1787)

This commit is contained in:
Emt-lin 2025-09-06 03:38:00 +08:00 committed by GitHub
parent 946fb139ef
commit 0512e21471
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -98,7 +98,7 @@ export default class ProjectManager {
// If this is the current project, reload its context and recreate chain
if (this.currentProjectId === nextProject.id) {
await Promise.all([
this.loadProjectContext(nextProject),
this.loadProjectContext(nextProject, true),
// Recreate chain to pick up new system prompt
this.getCurrentChainManager().createChainWithNewModel(),
]);
@ -190,10 +190,15 @@ export default class ProjectManager {
await this.plugin.chatUIState.handleProjectSwitch();
}
private async loadProjectContext(project: ProjectConfig): Promise<ContextCache | null> {
private async loadProjectContext(
project: ProjectConfig,
forUpdate: boolean = false
): Promise<ContextCache | null> {
// for update context condition
this.loadTracker.clearAllLoadStates();
setProjectLoading(true);
if (forUpdate) {
this.loadTracker.clearAllLoadStates();
setProjectLoading(true);
}
try {
if (!project.contextSource) {
@ -202,10 +207,6 @@ export default class ProjectManager {
}
logInfo(`[loadProjectContext] Starting for project: ${project.name}`);
logInfo(
`[loadProjectContext] Project ${project.name}: Cleared all project context load states`
);
const contextCache = await this.projectContextCache.getOrInitializeCache(project);
const projectAllFiles = this.getProjectAllFiles(project);
@ -232,6 +233,10 @@ export default class ProjectManager {
} catch (error) {
logError(`[loadProjectContext] Failed for project ${project.name}:`, error);
throw error;
} finally {
if (forUpdate) {
setProjectLoading(false);
}
}
}
@ -323,7 +328,7 @@ export default class ProjectManager {
);
}
const updatedCache = await this.loadProjectContext(project);
const updatedCache = await this.loadProjectContext(project, true);
if (!updatedCache) {
logError(`[getProjectContext] Project ${project.name}: loadProjectContext returned null.`);
return null;