Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/core/prompts/instructions/create-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import * as path from "path"
import * as vscode from "vscode"

import { GlobalFileNames } from "../../../shared/globalFileNames"
import { getSettingsDirectoryPath } from "../../../utils/storage"

export async function createModeInstructions(context: vscode.ExtensionContext | undefined): Promise<string> {
if (!context) throw new Error("Missing VSCode Extension Context")

const settingsDir = path.join(context.globalStorageUri.fsPath, "settings")
const settingsDir = await getSettingsDirectoryPath(context.globalStorageUri.fsPath)
const customModesPath = path.join(settingsDir, GlobalFileNames.customModes)

return `
Expand Down
7 changes: 3 additions & 4 deletions src/core/prompts/sections/modes.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import * as path from "path"
import * as vscode from "vscode"
import { promises as fs } from "fs"

import type { ModeConfig } from "@roo-code/types"

import { getAllModesWithPrompts } from "../../../shared/modes"
import { ensureSettingsDirectoryExists } from "../../../utils/globalContext"

export async function getModesSection(context: vscode.ExtensionContext): Promise<string> {
const settingsDir = path.join(context.globalStorageUri.fsPath, "settings")
await fs.mkdir(settingsDir, { recursive: true })
// Make sure path gets created
await ensureSettingsDirectoryExists(context)

// Get all modes with their overrides from extension state
const allModes = await getAllModesWithPrompts(context)
Expand Down
12 changes: 3 additions & 9 deletions src/utils/globalContext.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import { mkdir } from "fs/promises"
import { join } from "path"
import { ExtensionContext } from "vscode"

export async function getGlobalFsPath(context: ExtensionContext): Promise<string> {
return context.globalStorageUri.fsPath
}
import { getSettingsDirectoryPath } from "./storage"

export async function ensureSettingsDirectoryExists(context: ExtensionContext): Promise<string> {
const settingsDir = join(context.globalStorageUri.fsPath, "settings")
await mkdir(settingsDir, { recursive: true })
return settingsDir
// getSettingsDirectoryPath already handles the custom storage path setting
return await getSettingsDirectoryPath(context.globalStorageUri.fsPath)
}
3 changes: 2 additions & 1 deletion src/utils/migrateSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as path from "path"
import * as fs from "fs/promises"
import { fileExistsAtPath } from "./fs"
import { GlobalFileNames } from "../shared/globalFileNames"
import { getSettingsDirectoryPath } from "./storage"
import * as yaml from "yaml"

const deprecatedCustomModesJSONFilename = "custom_modes.json"
Expand All @@ -26,7 +27,7 @@ export async function migrateSettings(
]

try {
const settingsDir = path.join(context.globalStorageUri.fsPath, "settings")
const settingsDir = await getSettingsDirectoryPath(context.globalStorageUri.fsPath)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Using getSettingsDirectoryPath() here will create the settings directory before the existence check below. That makes the early-return branch ("No settings directory found, no migrations necessary") unreachable. Consider removing the existence check/log or computing the path without side effects before checking, so logs reflect actual conditions.


// Check if settings directory exists first
if (!(await fileExistsAtPath(settingsDir))) {
Expand Down