@@ -5,6 +5,7 @@ import { CustomModesSettingsSchema } from "./CustomModesSchema"
5
5
import { ModeConfig } from "../../shared/modes"
6
6
import { fileExistsAtPath } from "../../utils/fs"
7
7
import { arePathsEqual } from "../../utils/path"
8
+ import { logger } from "../../utils/logging"
8
9
9
10
const ROOMODES_FILENAME = ".roomodes"
10
11
@@ -214,14 +215,26 @@ export class CustomModesManager {
214
215
await this . context . globalState . update ( "customModes" , mergedModes )
215
216
return mergedModes
216
217
}
217
-
218
218
async updateCustomMode ( slug : string , config : ModeConfig ) : Promise < void > {
219
219
try {
220
220
const isProjectMode = config . source === "project"
221
- const targetPath = isProjectMode ? await this . getWorkspaceRoomodes ( ) : await this . getCustomModesFilePath ( )
221
+ let targetPath : string
222
222
223
- if ( isProjectMode && ! targetPath ) {
224
- throw new Error ( "No workspace folder found for project-specific mode" )
223
+ if ( isProjectMode ) {
224
+ const workspaceFolders = vscode . workspace . workspaceFolders
225
+ if ( ! workspaceFolders || workspaceFolders . length === 0 ) {
226
+ logger . error ( "Failed to update project mode: No workspace folder found" , { slug } )
227
+ throw new Error ( "No workspace folder found for project-specific mode" )
228
+ }
229
+ const workspaceRoot = workspaceFolders [ 0 ] . uri . fsPath
230
+ targetPath = path . join ( workspaceRoot , ROOMODES_FILENAME )
231
+ const exists = await fileExistsAtPath ( targetPath )
232
+ logger . info ( `${ exists ? "Updating" : "Creating" } project mode in ${ ROOMODES_FILENAME } ` , {
233
+ slug,
234
+ workspace : workspaceRoot ,
235
+ } )
236
+ } else {
237
+ targetPath = await this . getCustomModesFilePath ( )
225
238
}
226
239
227
240
await this . queueWrite ( async ( ) => {
@@ -231,7 +244,7 @@ export class CustomModesManager {
231
244
source : isProjectMode ? ( "project" as const ) : ( "global" as const ) ,
232
245
}
233
246
234
- await this . updateModesInFile ( targetPath ! , ( modes ) => {
247
+ await this . updateModesInFile ( targetPath , ( modes ) => {
235
248
const updatedModes = modes . filter ( ( m ) => m . slug !== slug )
236
249
updatedModes . push ( modeWithSource )
237
250
return updatedModes
@@ -240,9 +253,9 @@ export class CustomModesManager {
240
253
await this . refreshMergedState ( )
241
254
} )
242
255
} catch ( error ) {
243
- vscode . window . showErrorMessage (
244
- ` Failed to update custom mode: ${ error instanceof Error ? error . message : String ( error ) } ` ,
245
- )
256
+ const errorMessage = error instanceof Error ? error . message : String ( error )
257
+ logger . error ( " Failed to update custom mode" , { slug , error : errorMessage } )
258
+ vscode . window . showErrorMessage ( `Failed to update custom mode: ${ errorMessage } ` )
246
259
}
247
260
}
248
261
private async updateModesInFile ( filePath : string , operation : ( modes : ModeConfig [ ] ) => ModeConfig [ ] ) : Promise < void > {
0 commit comments