Add the setting to schema definitions:
globalSettingsSchema in schemas/index.tsglobalSettingsRecord in schemas/index.tsterminalCommandDelay: z.number().optional(),Add the setting to type definitions:
exports/types.tsexports/roo-code.d.tsshared/ExtensionMessage.tsshared/WebviewMessage.tsterminalCommandDelay?: number | undefinedAdd test coverage:
Add the message type to WebviewMessage.ts:
| "multisearchDiffEnabled"Add the setting to ExtensionStateContext.tsx:
Example:
interface ExtensionStateContextType {
multisearchDiffEnabled: boolean
setMultisearchDiffEnabled: (value: boolean) => void
}
Add the setting to ClineProvider.ts:
Example:
case "multisearchDiffEnabled":
await this.updateGlobalState("multisearchDiffEnabled", message.bool)
await this.postStateToWebview()
break
Add the checkbox UI to SettingsView.tsx:
Example:
<VSCodeCheckbox
checked={multisearchDiffEnabled}
onChange={(e: any) => setMultisearchDiffEnabled(e.target.checked)}
>
<span style={{ fontWeight: "500" }}>Enable multi-search diff matching</span>
</VSCodeCheckbox>
Add the setting to handleSubmit in SettingsView.tsx:
Example:
vscode.postMessage({ type: "multisearchDiffEnabled", bool: multisearchDiffEnabled })
Style Considerations:
Example:
<div>
<VSCodeCheckbox
checked={terminalPowershellCounter ?? true}
onChange={(e: any) => setCachedStateField("terminalPowershellCounter", e.target.checked)}
data-testid="terminal-powershell-counter-checkbox">
<span className="font-medium">{t("settings:terminal.powershellCounter.label")}</span>
</VSCodeCheckbox>
<div className="text-vscode-descriptionForeground text-sm mt-1">
{t("settings:terminal.powershellCounter.description")}
</div>
</div>
Add the message type to WebviewMessage.ts:
| "preferredLanguage"Add the setting to ExtensionStateContext.tsx:
Example:
interface ExtensionStateContextType {
preferredLanguage: string
setPreferredLanguage: (value: string) => void
}
Add the setting to ClineProvider.ts:
Example:
case "preferredLanguage":
await this.updateGlobalState("preferredLanguage", message.text)
await this.postStateToWebview()
break
Add the select UI to SettingsView.tsx:
Example:
<select
value={preferredLanguage}
onChange={(e) => setPreferredLanguage(e.target.value)}
style={{
width: "100%",
padding: "4px 8px",
backgroundColor: "var(--vscode-input-background)",
color: "var(--vscode-input-foreground)",
border: "1px solid var(--vscode-input-border)",
borderRadius: "2px"
}}>
<option value="English">English</option>
<option value="Spanish">Spanish</option>
...
</select>
Add the setting to handleSubmit in SettingsView.tsx:
Example:
vscode.postMessage({ type: "preferredLanguage", text: preferredLanguage })
These steps ensure that:
To add a new configuration item to the system, the following changes are necessary:
Feature-Specific Class (if applicable)
Schema Definition
Type Definitions
UI Component
Translations
State Management
Message Handling
Implementation-Specific Logic
Testing
Ensuring Settings Persistence Across Reload
To ensure settings persist across application reload, several key components must be properly configured:
Initial State in ExtensionStateContextProvider:
Example:
const [state, setState] = useState<ExtensionState>({
// existing settings...
newSetting: false, // Default value for the new setting
})
State Loading in ClineProvider:
Example:
return {
// existing settings...
newSetting: stateValues.newSetting ?? false,
}
State Initialization in resolveWebviewView:
Example:
this.getState().then(
({
// existing settings...
newSetting,
}) => {
// Initialize the setting with its stored value or default
FeatureClass.setNewSetting(newSetting ?? false)
},
)
State Transmission to Webview:
Example:
return {
// existing settings...
newSetting: newSetting ?? false,
}
Setter Method in ExtensionStateContext:
Example:
const contextValue: ExtensionStateContextType = {
// existing properties and methods...
setNewSetting: (value) => setState((prevState) => ({ ...prevState, newSetting: value })),
}
Debugging Settings Persistence Issues
If a setting is not persisting across reload, check the following:
Complete Chain of Persistence:
Default Values Consistency:
Message Handling:
UI Integration:
Type Definitions:
Storage Mechanism:
These checks help identify and resolve common issues with settings persistence.