MCPcopy
hub / github.com/continuedev/continue / findAvailableFilename

Function findAvailableFilename

core/config/workspace/workspaceBlocks.ts:114–155  ·  view source on GitHub ↗
(
  baseDirUri: string,
  blockType: BlockType,
  fileExists: (uri: string) => Promise<boolean>,
  extension?: string,
  isGlobal?: boolean,
  baseFilenameOverride?: string,
)

Source from the content-addressed store, hash-verified

112}
113
114export async function findAvailableFilename(
115 baseDirUri: string,
116 blockType: BlockType,
117 fileExists: (uri: string) => Promise<boolean>,
118 extension?: string,
119 isGlobal?: boolean,
120 baseFilenameOverride?: string,
121): Promise<string> {
122 const fileExtension = extension ?? getFileExtension(blockType);
123 let baseFilename = "";
124
125 const trimmedOverride = baseFilenameOverride?.trim();
126 if (trimmedOverride) {
127 if (blockType === "rules") {
128 const withoutExtension = trimmedOverride.replace(/\.[^./\\]+$/, "");
129 const sanitized = sanitizeRuleName(withoutExtension);
130 baseFilename = sanitized;
131 } else {
132 baseFilename = trimmedOverride;
133 }
134 }
135 if (!baseFilename) {
136 baseFilename =
137 blockType === "rules" && isGlobal
138 ? "global-rule"
139 : `new-${BLOCK_TYPE_CONFIG[blockType]?.filename}`;
140 }
141
142 let counter = 0;
143 let fileUri: string;
144
145 do {
146 const suffix = counter === 0 ? "" : `-${counter}`;
147 fileUri = joinPathsToUri(
148 baseDirUri,
149 `${baseFilename}${suffix}.${fileExtension}`,
150 );
151 counter++;
152 } while (await fileExists(fileUri));
153
154 return fileUri;
155}
156
157export async function createNewWorkspaceBlockFile(
158 ide: IDE,

Callers 3

createNewGlobalRuleFileFunction · 0.85

Calls 4

sanitizeRuleNameFunction · 0.90
joinPathsToUriFunction · 0.90
getFileExtensionFunction · 0.85
replaceMethod · 0.45

Tested by

no test coverage detected