Make statemanager global singleton (#6619)
* do not initialize duplicate statemanager in migration; use vscode api directly * make state manager a singleton * move statemanager init to common.ts
This commit is contained in:
1 parent
1cee9f33a7
commit
a5699e883d
3 files changed
+78
-49
No files matched your search
@@ -68,50 +68,34 @@ export class Controller {
|
||||
constructor(readonly context: vscode.ExtensionContext) {
|
||||
PromptRegistry.getInstance() // Ensure prompts and tools are registered
|
||||
HostProvider.get().logToChannel("ClineProvider instantiated")
|
||||
this.stateManager = new StateManager(context)
|
||||
this.stateManager = StateManager.get()
|
||||
this.authService = AuthService.getInstance(this)
|
||||
this.ocaAuthService = OcaAuthService.initialize(this)
|
||||
this.accountService = ClineAccountService.getInstance()
|
||||
this.authService.restoreRefreshTokenAndRetrieveAuthInfo()
|
||||
|
||||
// Initialize cache service asynchronously - critical for extension functionality
|
||||
this.stateManager
|
||||
.initialize()
|
||||
.then(() => {
|
||||
this.authService.restoreRefreshTokenAndRetrieveAuthInfo()
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(
|
||||
"[Controller] CRITICAL: Failed to initialize StateManager - extension may not function properly:",
|
||||
error,
|
||||
)
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
message: "Failed to initialize Cline's application state. Please restart the extension.",
|
||||
})
|
||||
})
|
||||
|
||||
// Set up persistence error recovery
|
||||
this.stateManager.onPersistenceError = async ({ error }: PersistenceErrorEvent) => {
|
||||
console.error("[Controller] Cache persistence failed, recovering:", error)
|
||||
try {
|
||||
await this.stateManager.reInitialize(this.task?.taskId)
|
||||
StateManager.get().registerCallbacks({
|
||||
onPersistenceError: async ({ error }: PersistenceErrorEvent) => {
|
||||
console.error("[Controller] Cache persistence failed, recovering:", error)
|
||||
try {
|
||||
await StateManager.get().reInitialize(this.task?.taskId)
|
||||
await this.postStateToWebview()
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.WARNING,
|
||||
message: "Saving settings to storage failed.",
|
||||
})
|
||||
} catch (recoveryError) {
|
||||
console.error("[Controller] Cache recovery failed:", recoveryError)
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
message: "Failed to save settings. Please restart the extension.",
|
||||
})
|
||||
}
|
||||
},
|
||||
onSyncExternalChange: async () => {
|
||||
await this.postStateToWebview()
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.WARNING,
|
||||
message: "Saving settings to storage failed.",
|
||||
})
|
||||
} catch (recoveryError) {
|
||||
console.error("[Controller] Cache recovery failed:", recoveryError)
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.ERROR,
|
||||
message: "Failed to save settings. Please restart the extension.",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
this.stateManager.onSyncExternalChange = async () => {
|
||||
await this.postStateToWebview()
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
this.mcpHub = new McpHub(
|
||||
() => ensureMcpServersDirectoryExists(),
|
||||
|
||||
Reference in new issue
Block a user