fix(hashline-edit): scope formatter cache by directory

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-03-24 20:30:16 +09:00
parent cea8769a7f
commit 6da4d2dae0
2 changed files with 132 additions and 5 deletions
+15 -5
View File
@@ -25,15 +25,24 @@ export interface FormatterClient {
}
}
let cachedFormatters: Map<string, Array<{ command: string[]; environment: Record<string, string> }>> | null = null
type FormatterDefinition = { command: string[]; environment: Record<string, string> }
type FormatterMap = Map<string, FormatterDefinition[]>
const cachedFormattersByDirectory = new Map<string, FormatterMap>()
function getFormatterCacheKey(directory: string): string {
return path.resolve(directory)
}
export async function resolveFormatters(
client: FormatterClient,
directory: string,
): Promise<Map<string, Array<{ command: string[]; environment: Record<string, string> }>>> {
): Promise<FormatterMap> {
const cacheKey = getFormatterCacheKey(directory)
const cachedFormatters = cachedFormattersByDirectory.get(cacheKey)
if (cachedFormatters) return cachedFormatters
const result = new Map<string, Array<{ command: string[]; environment: Record<string, string> }>>()
const result = new Map<string, FormatterDefinition[]>()
try {
const response = await client.config.get({ query: { directory } })
@@ -68,11 +77,12 @@ export async function resolveFormatters(
result.set(normalizedExt, existing)
}
}
cachedFormattersByDirectory.set(cacheKey, result)
} catch (error) {
log("[formatter-trigger] Failed to fetch formatter config", { error })
}
cachedFormatters = result
return result
}
@@ -118,5 +128,5 @@ export async function runFormattersForFile(
}
export function clearFormatterCache(): void {
cachedFormatters = null
cachedFormattersByDirectory.clear()
}