mirror of
https://github.com/cline/cline.git
synced 2026-09-24 23:20:16 +08:00
cleanup unnecessary functions in StateManager to reduce clutter (#6134)
This commit is contained in:
@@ -225,6 +225,7 @@ export class Controller {
|
||||
})
|
||||
|
||||
const cwd = this.workspaceManager?.getPrimaryRoot()?.path || (await getCwd(getDesktopDir()))
|
||||
|
||||
this.task = new Task(
|
||||
this,
|
||||
this.mcpHub,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { WorkspaceRoot } from "@core/workspace"
|
||||
import { ApiConfiguration, fireworksDefaultModelId } from "@shared/api"
|
||||
import chokidar, { FSWatcher } from "chokidar"
|
||||
import type { ExtensionContext } from "vscode"
|
||||
@@ -555,54 +554,6 @@ export class StateManager {
|
||||
return this.workspaceStateCache[key]
|
||||
}
|
||||
|
||||
/**
|
||||
* Get workspace roots from global state
|
||||
*/
|
||||
getWorkspaceRoots(): WorkspaceRoot[] | undefined {
|
||||
return this.getGlobalStateKey("workspaceRoots")
|
||||
}
|
||||
|
||||
/**
|
||||
* Set workspace roots in global state
|
||||
*/
|
||||
setWorkspaceRoots(roots: WorkspaceRoot[]): void {
|
||||
this.setGlobalState("workspaceRoots", roots)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get primary root index from global state.
|
||||
* The primary root is the main workspace folder that Cline focuses on when dealing with
|
||||
* multi-root workspaces. In VS Code, you can have multiple folders open in one workspace,
|
||||
* and the primary root index indicates which folder (by its position in the array, 0-based)
|
||||
* should be treated as the main/default working directory for operations.
|
||||
*/
|
||||
getPrimaryRootIndex(): number {
|
||||
return this.getGlobalStateKey("primaryRootIndex") ?? 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Set primary root index in global state
|
||||
*/
|
||||
setPrimaryRootIndex(index: number): void {
|
||||
this.setGlobalState("primaryRootIndex", index)
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if multi-root workspace feature is enabled
|
||||
*/
|
||||
isMultiRootEnabled(): boolean {
|
||||
// Feature flag - defaults to false
|
||||
// For now, always return false to disable multi-root support by default
|
||||
return this.getGlobalStateKey("multiRootEnabled") ?? false
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable or disable multi-root workspace feature
|
||||
*/
|
||||
setMultiRootEnabled(enabled: boolean): void {
|
||||
this.setGlobalState("multiRootEnabled", enabled)
|
||||
}
|
||||
|
||||
/**
|
||||
* Reinitialize the state manager by clearing all state and reloading from disk
|
||||
* Used for error recovery when write operations fail
|
||||
|
||||
@@ -87,8 +87,8 @@ export interface GlobalState {
|
||||
|
||||
// Multi-root workspace support
|
||||
workspaceRoots: WorkspaceRoot[] | undefined
|
||||
primaryRootIndex: number | undefined
|
||||
multiRootEnabled: boolean | undefined
|
||||
primaryRootIndex: number
|
||||
multiRootEnabled: boolean
|
||||
|
||||
// Plan mode configurations
|
||||
planModeApiProvider: ApiProvider
|
||||
|
||||
@@ -324,9 +324,16 @@ export async function readGlobalStateFromDisk(context: ExtensionContext): Promis
|
||||
const taskHistory = await readTaskHistoryFromState(context)
|
||||
|
||||
// Multi-root workspace support
|
||||
const workspaceRoots = context.globalState.get("workspaceRoots") as GlobalState["workspaceRoots"]
|
||||
const primaryRootIndex = context.globalState.get("primaryRootIndex") as number | undefined
|
||||
const multiRootEnabled = context.globalState.get("multiRootEnabled") as boolean | undefined
|
||||
const workspaceRoots = context.globalState.get<GlobalState["workspaceRoots"]>("workspaceRoots")
|
||||
/**
|
||||
* Get primary root index from global state.
|
||||
* The primary root is the main workspace folder that Cline focuses on when dealing with
|
||||
* multi-root workspaces. In VS Code, you can have multiple folders open in one workspace,
|
||||
* and the primary root index indicates which folder (by its position in the array, 0-based)
|
||||
* should be treated as the main/default working directory for operations.
|
||||
*/
|
||||
const primaryRootIndex = context.globalState.get<GlobalState["primaryRootIndex"]>("primaryRootIndex")
|
||||
const multiRootEnabled = context.globalState.get<GlobalState["multiRootEnabled"]>("multiRootEnabled")
|
||||
|
||||
return {
|
||||
// api configuration fields
|
||||
@@ -463,8 +470,10 @@ export async function readGlobalStateFromDisk(context: ExtensionContext): Promis
|
||||
customPrompt,
|
||||
// Multi-root workspace support
|
||||
workspaceRoots,
|
||||
primaryRootIndex,
|
||||
multiRootEnabled,
|
||||
primaryRootIndex: primaryRootIndex ?? 0,
|
||||
// Feature flag - defaults to false
|
||||
// For now, always return false to disable multi-root support by default
|
||||
multiRootEnabled: multiRootEnabled ?? false,
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("[StateHelpers] Failed to read global state:", error)
|
||||
|
||||
@@ -282,7 +282,7 @@ export class Task {
|
||||
context: controller.context,
|
||||
workspaceManager: this.workspaceManager,
|
||||
globalStoragePath: controller.context.globalStorageUri.fsPath,
|
||||
isMultiRootEnabled: stateManager.isMultiRootEnabled(),
|
||||
isMultiRootEnabled: stateManager.getGlobalStateKey("multiRootEnabled"),
|
||||
updateTaskHistory: this.updateTaskHistory,
|
||||
say: this.say.bind(this),
|
||||
cancelTask: this.cancelTask,
|
||||
@@ -294,7 +294,7 @@ export class Task {
|
||||
// If multi-root, kick off non-blocking initialization
|
||||
if (
|
||||
shouldUseMultiRoot({
|
||||
isMultiRootEnabled: stateManager.isMultiRootEnabled(),
|
||||
isMultiRootEnabled: stateManager.getGlobalStateKey("multiRootEnabled"),
|
||||
workspaceManager: this.workspaceManager,
|
||||
enableCheckpoints: enableCheckpointsSetting,
|
||||
})
|
||||
|
||||
@@ -31,14 +31,27 @@ describe("setupWorkspaceManager", () => {
|
||||
}) => {
|
||||
const state: { roots?: WorkspaceRoot[]; primaryIndex?: number } = {}
|
||||
return {
|
||||
isMultiRootEnabled: () => multiRootEnabled,
|
||||
getWorkspaceRoots: () => savedRoots,
|
||||
getPrimaryRootIndex: () => savedPrimaryIndex,
|
||||
setWorkspaceRoots: (roots: WorkspaceRoot[]) => {
|
||||
state.roots = roots
|
||||
getGlobalStateKey: (key: string) => {
|
||||
switch (key) {
|
||||
case "multiRootEnabled":
|
||||
return multiRootEnabled
|
||||
case "workspaceRoots":
|
||||
return savedRoots
|
||||
case "primaryRootIndex":
|
||||
return savedPrimaryIndex
|
||||
default:
|
||||
return undefined
|
||||
}
|
||||
},
|
||||
setPrimaryRootIndex: (idx: number) => {
|
||||
state.primaryIndex = idx
|
||||
setGlobalState: (key: string, value: any) => {
|
||||
switch (key) {
|
||||
case "workspaceRoots":
|
||||
state.roots = value
|
||||
break
|
||||
case "primaryRootIndex":
|
||||
state.primaryIndex = value
|
||||
break
|
||||
}
|
||||
},
|
||||
// for assertions
|
||||
_state: state,
|
||||
|
||||
+11
-14
@@ -3,6 +3,7 @@ import { telemetryService } from "@/services/telemetry"
|
||||
import type { HistoryItem } from "@/shared/HistoryItem"
|
||||
import { ShowMessageType } from "@/shared/proto/host/window"
|
||||
import { getCwd, getDesktopDir } from "@/utils/path"
|
||||
import { StateManager } from "../storage/StateManager"
|
||||
import type { WorkspaceRoot } from "./WorkspaceRoot"
|
||||
import { WorkspaceRootManager } from "./WorkspaceRootManager"
|
||||
|
||||
@@ -18,18 +19,12 @@ export async function setupWorkspaceManager({
|
||||
stateManager,
|
||||
detectRoots,
|
||||
}: {
|
||||
stateManager: {
|
||||
isMultiRootEnabled(): boolean
|
||||
getWorkspaceRoots(): WorkspaceRoot[] | undefined
|
||||
getPrimaryRootIndex(): number
|
||||
setWorkspaceRoots(roots: WorkspaceRoot[]): void
|
||||
setPrimaryRootIndex(idx: number): void
|
||||
}
|
||||
stateManager: StateManager
|
||||
historyItem?: HistoryItem
|
||||
detectRoots: DetectRoots
|
||||
}): Promise<WorkspaceRootManager> {
|
||||
const cwd = await getCwd(getDesktopDir())
|
||||
const multiRootEnabled = stateManager.isMultiRootEnabled()
|
||||
const multiRootEnabled = stateManager.getGlobalStateKey("multiRootEnabled")
|
||||
const startTime = performance.now()
|
||||
|
||||
try {
|
||||
@@ -50,8 +45,8 @@ export async function setupWorkspaceManager({
|
||||
)
|
||||
|
||||
// Persist
|
||||
stateManager.setWorkspaceRoots(manager.getRoots())
|
||||
stateManager.setPrimaryRootIndex(manager.getPrimaryIndex())
|
||||
stateManager.setGlobalState("workspaceRoots", manager.getRoots())
|
||||
stateManager.setGlobalState("primaryRootIndex", manager.getPrimaryIndex())
|
||||
return manager
|
||||
}
|
||||
|
||||
@@ -88,8 +83,9 @@ export async function setupWorkspaceManager({
|
||||
)
|
||||
|
||||
console.log(`[WorkspaceManager] Single-root mode: ${cwd}`)
|
||||
stateManager.setWorkspaceRoots(manager.getRoots())
|
||||
stateManager.setPrimaryRootIndex(manager.getPrimaryIndex())
|
||||
const roots = manager.getRoots()
|
||||
stateManager.setGlobalState("workspaceRoots", roots)
|
||||
stateManager.setGlobalState("primaryRootIndex", manager.getPrimaryIndex())
|
||||
return manager
|
||||
} catch (error) {
|
||||
// Telemetry + graceful fallback to single-root from cwd
|
||||
@@ -98,8 +94,9 @@ export async function setupWorkspaceManager({
|
||||
|
||||
console.error("[WorkspaceManager] Initialization failed:", error)
|
||||
const manager = await WorkspaceRootManager.fromLegacyCwd(cwd)
|
||||
stateManager.setWorkspaceRoots(manager.getRoots())
|
||||
stateManager.setPrimaryRootIndex(manager.getPrimaryIndex())
|
||||
const roots = manager.getRoots()
|
||||
stateManager.setGlobalState("workspaceRoots", roots)
|
||||
stateManager.setGlobalState("primaryRootIndex", manager.getPrimaryIndex())
|
||||
|
||||
HostProvider.window.showMessage({
|
||||
type: ShowMessageType.WARNING,
|
||||
|
||||
Reference in New Issue
Block a user