From 640674197bbbb50cda41c0ec3c1b72465baebab8 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Mon, 9 Jun 2025 13:16:34 -0700 Subject: [PATCH] incorporate dallins feedback --- core/config/workspace/workspaceBlocks.test.ts | 29 +--------- core/config/workspace/workspaceBlocks.ts | 55 +++++-------------- 2 files changed, 15 insertions(+), 69 deletions(-) diff --git a/core/config/workspace/workspaceBlocks.test.ts b/core/config/workspace/workspaceBlocks.test.ts index ba93bb19e..75c50cabd 100644 --- a/core/config/workspace/workspaceBlocks.test.ts +++ b/core/config/workspace/workspaceBlocks.test.ts @@ -1,34 +1,7 @@ import { BlockType } from "@continuedev/config-yaml"; import { describe, expect, test } from "@jest/globals"; import { RULE_FILE_EXTENSION } from "../markdown"; -import { - blockTypeToFilename, - blockTypeToSingular, - findAvailableFilename, - getFileContent, -} from "./workspaceBlocks"; - -describe("blockTypeToSingular", () => { - test("converts block types to singular form correctly", () => { - expect(blockTypeToSingular("models")).toBe("model"); - expect(blockTypeToSingular("context")).toBe("context"); - expect(blockTypeToSingular("rules")).toBe("rule"); - expect(blockTypeToSingular("docs")).toBe("doc"); - expect(blockTypeToSingular("prompts")).toBe("prompt"); - expect(blockTypeToSingular("mcpServers")).toBe("MCP server"); - }); -}); - -describe("blockTypeToFilename", () => { - test("converts block types to filename-safe singular form correctly", () => { - expect(blockTypeToFilename("models")).toBe("model"); - expect(blockTypeToFilename("context")).toBe("context"); - expect(blockTypeToFilename("rules")).toBe("rule"); - expect(blockTypeToFilename("docs")).toBe("doc"); - expect(blockTypeToFilename("prompts")).toBe("prompt"); - expect(blockTypeToFilename("mcpServers")).toBe("mcp-server"); - }); -}); +import { findAvailableFilename, getFileContent } from "./workspaceBlocks"; describe("getFileContent", () => { test("returns markdown content for rules block type", () => { diff --git a/core/config/workspace/workspaceBlocks.ts b/core/config/workspace/workspaceBlocks.ts index d54d2c823..322d8a99e 100644 --- a/core/config/workspace/workspaceBlocks.ts +++ b/core/config/workspace/workspaceBlocks.ts @@ -4,49 +4,22 @@ import { IDE } from "../.."; import { joinPathsToUri } from "../../util/uri"; import { RULE_FILE_EXTENSION, createRuleMarkdown } from "../markdown"; -export function blockTypeToSingular(blockType: BlockType): string { - switch (blockType) { - case "context": - return "context"; - case "models": - return "model"; - case "rules": - return "rule"; - case "docs": - return "doc"; - case "prompts": - return "prompt"; - case "mcpServers": - return "MCP server"; - default: - // Fallback to slice approach for any new block types - return blockType.slice(0, -1); - } -} - -export function blockTypeToFilename(blockType: BlockType): string { - switch (blockType) { - case "context": - return "context"; - case "models": - return "model"; - case "rules": - return "rule"; - case "docs": - return "doc"; - case "prompts": - return "prompt"; - case "mcpServers": - return "mcp-server"; - default: - // Fallback to slice approach for any new block types - return blockType.slice(0, -1); - } -} +const BLOCK_TYPE_CONFIG: Record< + BlockType, + { singular: string; filename: string } +> = { + context: { singular: "context", filename: "context" }, + models: { singular: "model", filename: "model" }, + rules: { singular: "rule", filename: "rule" }, + docs: { singular: "doc", filename: "doc" }, + prompts: { singular: "prompt", filename: "prompt" }, + mcpServers: { singular: "MCP server", filename: "mcp-server" }, + data: { singular: "data", filename: "data" }, +}; function getContentsForNewBlock(blockType: BlockType): ConfigYaml { const configYaml: ConfigYaml = { - name: `New ${blockTypeToSingular(blockType)}`, + name: `New ${BLOCK_TYPE_CONFIG[blockType]?.singular}`, version: "0.0.1", schema: "v1", }; @@ -125,7 +98,7 @@ export async function findAvailableFilename( fileExists: (uri: string) => Promise, extension?: string, ): Promise { - const baseFilename = `new-${blockTypeToFilename(blockType)}`; + const baseFilename = `new-${BLOCK_TYPE_CONFIG[blockType]?.filename}`; const fileExtension = extension ?? getFileExtension(blockType); let counter = 0; let fileUri: string;