|
1 | 1 | ## For All Settings |
2 | 2 |
|
3 | | -1. Add the setting to ExtensionMessage.ts: |
| 3 | +1. Add the setting to schema definitions: |
4 | 4 |
|
5 | | - - Add the setting to the ExtensionState interface |
6 | | - - Make it required if it has a default value, optional if it can be undefined |
7 | | - - Example: `preferredLanguage: string` |
| 5 | + - Add the item to `globalSettingsSchema` in `schemas/index.ts` |
| 6 | + - Add the item to `globalSettingsRecord` in `schemas/index.ts` |
| 7 | + - Example: `terminalCommandDelay: z.number().optional(),` |
8 | 8 |
|
9 | | -2. Add test coverage: |
| 9 | +2. Add the setting to type definitions: |
| 10 | + |
| 11 | + - Add the item to `exports/types.ts` |
| 12 | + - Add the item to `exports/roo-code.d.ts` |
| 13 | + - Add the setting to `shared/ExtensionMessage.ts` |
| 14 | + - Add the setting to the WebviewMessage type in `shared/WebviewMessage.ts` |
| 15 | + - Example: `terminalCommandDelay?: number | undefined` |
| 16 | + |
| 17 | +3. Add test coverage: |
10 | 18 | - Add the setting to mockState in ClineProvider.test.ts |
11 | 19 | - Add test cases for setting persistence and state updates |
12 | 20 | - Ensure all tests pass before submitting changes |
|
64 | 72 | ``` |
65 | 73 |
|
66 | 74 | 5. Add the setting to handleSubmit in SettingsView.tsx: |
67 | | - - Add a vscode.postMessage call to send the setting's value when clicking Done |
| 75 | + |
| 76 | + - Add a vscode.postMessage call to send the setting's value when clicking Save |
| 77 | + - This step is critical for persistence - without it, the setting will not be saved when the user clicks Save |
68 | 78 | - Example: |
69 | 79 | ```typescript |
70 | 80 | vscode.postMessage({ type: "multisearchDiffEnabled", bool: multisearchDiffEnabled }) |
71 | 81 | ``` |
72 | 82 |
|
| 83 | +6. Style Considerations: |
| 84 | + - Use the VSCodeCheckbox component from @vscode/webview-ui-toolkit/react instead of HTML input elements |
| 85 | + - Wrap each checkbox in a div element for proper spacing |
| 86 | + - Use a span with className="font-medium" for the checkbox label inside the VSCodeCheckbox component |
| 87 | + - Place the description in a separate div with className="text-vscode-descriptionForeground text-sm mt-1" |
| 88 | + - Maintain consistent spacing between configuration options |
| 89 | + - Example: |
| 90 | + ```typescript |
| 91 | + <div> |
| 92 | + <VSCodeCheckbox |
| 93 | + checked={terminalPowershellCounter ?? true} |
| 94 | + onChange={(e: any) => setCachedStateField("terminalPowershellCounter", e.target.checked)} |
| 95 | + data-testid="terminal-powershell-counter-checkbox"> |
| 96 | + <span className="font-medium">{t("settings:terminal.powershellCounter.label")}</span> |
| 97 | + </VSCodeCheckbox> |
| 98 | + <div className="text-vscode-descriptionForeground text-sm mt-1"> |
| 99 | + {t("settings:terminal.powershellCounter.description")} |
| 100 | + </div> |
| 101 | + </div> |
| 102 | + ``` |
| 103 | + |
73 | 104 | ## For Select/Dropdown Settings |
74 | 105 |
|
75 | 106 | 1. Add the message type to WebviewMessage.ts: |
|
98 | 129 | - Add the setting to the return value in getState with a default value |
99 | 130 | - Add the setting to the destructured variables in getStateToPostToWebview |
100 | 131 | - Add the setting to the return value in getStateToPostToWebview |
| 132 | + - This step is critical for UI display - without it, the setting will not be displayed in the UI |
101 | 133 | - Add a case in setWebviewMessageListener to handle the setting's message type |
102 | 134 | - Example: |
103 | 135 | ```typescript |
@@ -146,3 +178,167 @@ These steps ensure that: |
146 | 178 | - The setting's value is properly synchronized between the webview and extension |
147 | 179 | - The setting has a proper UI representation in the settings view |
148 | 180 | - Test coverage is maintained for the new setting |
| 181 | + |
| 182 | +## Adding a New Configuration Item: Summary of Required Changes |
| 183 | + |
| 184 | +To add a new configuration item to the system, the following changes are necessary: |
| 185 | + |
| 186 | +1. **Feature-Specific Class** (if applicable) |
| 187 | + |
| 188 | + - For settings that affect specific features (e.g., Terminal, Browser, etc.) |
| 189 | + - Add a static property to store the value |
| 190 | + - Add getter/setter methods to access and modify the value |
| 191 | + |
| 192 | +2. **Schema Definition** |
| 193 | + |
| 194 | + - Add the item to globalSettingsSchema in schemas/index.ts |
| 195 | + - Add the item to globalSettingsRecord in schemas/index.ts |
| 196 | + |
| 197 | +3. **Type Definitions** |
| 198 | + |
| 199 | + - Add the item to exports/types.ts |
| 200 | + - Add the item to exports/roo-code.d.ts |
| 201 | + - Add the item to shared/ExtensionMessage.ts |
| 202 | + - Add the item to shared/WebviewMessage.ts |
| 203 | + |
| 204 | +4. **UI Component** |
| 205 | + |
| 206 | + - Create or update a component in webview-ui/src/components/settings/ |
| 207 | + - Add appropriate slider/input controls with min/max/step values |
| 208 | + - Ensure the props are passed correctly to the component in SettingsView.tsx |
| 209 | + - Update the component's props interface to include the new settings |
| 210 | + |
| 211 | +5. **Translations** |
| 212 | + |
| 213 | + - Add label and description in webview-ui/src/i18n/locales/en/settings.json |
| 214 | + - Update all other languages |
| 215 | + - If any language content is changed, synchronize all other languages with that change |
| 216 | + - Translations must be performed within "translation" mode so change modes for that purpose |
| 217 | + |
| 218 | +6. **State Management** |
| 219 | + |
| 220 | + - Add the item to the destructuring in SettingsView.tsx |
| 221 | + - Add the item to the handleSubmit function in SettingsView.tsx |
| 222 | + - Add the item to getStateToPostToWebview in ClineProvider.ts |
| 223 | + - Add the item to getState in ClineProvider.ts with appropriate default values |
| 224 | + - Add the item to the initialization in resolveWebviewView in ClineProvider.ts |
| 225 | + |
| 226 | +7. **Message Handling** |
| 227 | + |
| 228 | + - Add a case for the item in webviewMessageHandler.ts |
| 229 | + |
| 230 | +8. **Implementation-Specific Logic** |
| 231 | + |
| 232 | + - Implement any feature-specific behavior triggered by the setting |
| 233 | + - Examples: |
| 234 | + - Environment variables for terminal settings |
| 235 | + - API configuration changes for provider settings |
| 236 | + - UI behavior modifications for display settings |
| 237 | + |
| 238 | +9. **Testing** |
| 239 | + |
| 240 | + - Add test cases for the new settings in appropriate test files |
| 241 | + - Verify settings persistence and state updates |
| 242 | + |
| 243 | +10. **Ensuring Settings Persistence Across Reload** |
| 244 | + |
| 245 | + To ensure settings persist across application reload, several key components must be properly configured: |
| 246 | + |
| 247 | + 1. **Initial State in ExtensionStateContextProvider**: |
| 248 | + |
| 249 | + - Add the setting to the initial state in the useState call |
| 250 | + - Example: |
| 251 | + ```typescript |
| 252 | + const [state, setState] = useState<ExtensionState>({ |
| 253 | + // existing settings... |
| 254 | + newSetting: false, // Default value for the new setting |
| 255 | + }) |
| 256 | + ``` |
| 257 | + |
| 258 | + 2. **State Loading in ClineProvider**: |
| 259 | + |
| 260 | + - Add the setting to the getState method to load it from storage |
| 261 | + - Example: |
| 262 | + ```typescript |
| 263 | + return { |
| 264 | + // existing settings... |
| 265 | + newSetting: stateValues.newSetting ?? false, |
| 266 | + } |
| 267 | + ``` |
| 268 | + |
| 269 | + 3. **State Initialization in resolveWebviewView**: |
| 270 | + |
| 271 | + - Add the setting to the initialization in resolveWebviewView |
| 272 | + - Example: |
| 273 | + ```typescript |
| 274 | + this.getState().then( |
| 275 | + ({ |
| 276 | + // existing settings... |
| 277 | + newSetting, |
| 278 | + }) => { |
| 279 | + // Initialize the setting with its stored value or default |
| 280 | + FeatureClass.setNewSetting(newSetting ?? false) |
| 281 | + }, |
| 282 | + ) |
| 283 | + ``` |
| 284 | + |
| 285 | + 4. **State Transmission to Webview**: |
| 286 | + |
| 287 | + - Add the setting to the getStateToPostToWebview method |
| 288 | + - Example: |
| 289 | + ```typescript |
| 290 | + return { |
| 291 | + // existing settings... |
| 292 | + newSetting: newSetting ?? false, |
| 293 | + } |
| 294 | + ``` |
| 295 | + |
| 296 | + 5. **Setter Method in ExtensionStateContext**: |
| 297 | + - Add the setter method to the contextValue object |
| 298 | + - Example: |
| 299 | + ```typescript |
| 300 | + const contextValue: ExtensionStateContextType = { |
| 301 | + // existing properties and methods... |
| 302 | + setNewSetting: (value) => setState((prevState) => ({ ...prevState, newSetting: value })), |
| 303 | + } |
| 304 | + ``` |
| 305 | + |
| 306 | +11. **Debugging Settings Persistence Issues** |
| 307 | + |
| 308 | + If a setting is not persisting across reload, check the following: |
| 309 | + |
| 310 | + 1. **Complete Chain of Persistence**: |
| 311 | + |
| 312 | + - Verify that the setting is added to all required locations: |
| 313 | + - globalSettingsSchema and globalSettingsRecord in schemas/index.ts |
| 314 | + - Initial state in ExtensionStateContextProvider |
| 315 | + - getState method in ClineProvider.ts |
| 316 | + - getStateToPostToWebview method in ClineProvider.ts |
| 317 | + - resolveWebviewView method in ClineProvider.ts (if feature-specific) |
| 318 | + - A break in any part of this chain can prevent persistence |
| 319 | + |
| 320 | + 2. **Default Values Consistency**: |
| 321 | + |
| 322 | + - Ensure default values are consistent across all locations |
| 323 | + - Inconsistent defaults can cause unexpected behavior |
| 324 | + |
| 325 | + 3. **Message Handling**: |
| 326 | + |
| 327 | + - Confirm the webviewMessageHandler.ts has a case for the setting |
| 328 | + - Verify the message type matches what's sent from the UI |
| 329 | + |
| 330 | + 4. **UI Integration**: |
| 331 | + |
| 332 | + - Check that the setting is included in the handleSubmit function in SettingsView.tsx |
| 333 | + - Ensure the UI component correctly updates the state |
| 334 | + |
| 335 | + 5. **Type Definitions**: |
| 336 | + |
| 337 | + - Verify the setting is properly typed in all relevant interfaces |
| 338 | + - Check for typos in property names across different files |
| 339 | + |
| 340 | + 6. **Storage Mechanism**: |
| 341 | + - For complex settings, ensure proper serialization/deserialization |
| 342 | + - Check that the setting is being correctly stored in VSCode's globalState |
| 343 | + |
| 344 | + These checks help identify and resolve common issues with settings persistence. |
0 commit comments