Skip to content

Commit

Permalink
Add Generate All and Clean All commands to go deep in folders. (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSouther authored May 27, 2024
1 parent 3c761ea commit 3071b17
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 12 deletions.
1 change: 1 addition & 0 deletions core/src/content/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ export async function loadContent(
meta: ContentMeta = {},
depth: number = Number.MAX_SAFE_INTEGER
): Promise<Record<string, Content>> {
if (depth < 0) throw new Error("Depth in loadContent cannot be negative");
if (depth < 1) return {};
LOGGER.debug(`Loading content from ${fs.cwd()}`);
[system, meta] = await loadAillyRc(fs, system, meta);
Expand Down
18 changes: 18 additions & 0 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,20 @@
"command": "ailly.generate",
"title": "Ailly: Run"
},
{
"command": "ailly.generate.all",
"title": "Ailly: Run All",
"enablement": "explorerViewletFocus"
},
{
"command": "ailly.clean",
"title": "Ailly: Clean"
},
{
"command": "ailly.clean.all",
"title": "Ailly: Clean",
"enablement": "explorerViewletFocus"
},
{
"command": "ailly.edit",
"title": "Ailly: Edit"
Expand All @@ -39,9 +49,17 @@
"command": "ailly.generate",
"group": "3_generate"
},
{
"command": "ailly.generate.all",
"group": "3_generate"
},
{
"command": "ailly.clean",
"group": "3_generate"
},
{
"command": "ailly.clean.all",
"group": "3_generate"
}
]
},
Expand Down
28 changes: 24 additions & 4 deletions extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ export function activate(context: vscode.ExtensionContext) {
});

registerGenerateCommand(context, {
name: "edit",
name: "generate.all",
manager: statusManager,
gerund: "editing",
pastpart: "edited",
edit: true,
gerund: "running all in",
pastpart: "ran all in",
infinitive: "run all in",
deep: true,
});

registerGenerateCommand(context, {
Expand All @@ -42,6 +43,23 @@ export function activate(context: vscode.ExtensionContext) {
clean: true,
});

registerGenerateCommand(context, {
name: "clean.all",
manager: statusManager,
gerund: "cleaning all in",
pastpart: "cleaned all in",
clean: true,
deep: true,
});

registerGenerateCommand(context, {
name: "edit",
manager: statusManager,
gerund: "editing",
pastpart: "edited",
edit: true,
});

context.subscriptions.push(
vscode.commands.registerCommand("ailly.set-engine", async () => {
vscode.window.showInformationMessage(`Ailly setting engine`);
Expand All @@ -65,6 +83,7 @@ export function registerGenerateCommand(
manager,
edit = false,
clean = false,
deep = false,
gerund,
pastpart,
infinitive = name,
Expand All @@ -73,6 +92,7 @@ export function registerGenerateCommand(
manager: StatusManager;
clean?: boolean;
edit?: boolean;
deep?: boolean;
gerund: string;
pastpart: string;
infinitive?: string;
Expand Down
15 changes: 7 additions & 8 deletions extension/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ export async function generate(
extensionEdit,
manager,
clean = false,
depth = 1,
}: {
extensionEdit?: ExtensionEdit;
manager: StatusManager;
clean?: boolean;
depth?: number;
}
) {
resetLogger();
Expand Down Expand Up @@ -66,6 +68,7 @@ export async function generate(
path,
extensionEdit,
settings,
depth,
});

if (content.length === 0) {
Expand Down Expand Up @@ -149,13 +152,15 @@ async function loadContentParts({
path,
extensionEdit,
settings,
depth = 1,
}: {
fs: FileSystem;
path: string;
extensionEdit?: ExtensionEdit;
extensionEdit: ExtensionEdit | undefined;
settings: PipelineSettings;
depth: number;
}): Promise<[Content[], Record<string, Content>]> {
const context = await loadContent(fs, [], settings, 1);
const context = await loadContent(fs, [], settings, depth);
const content: Content[] = Object.values(context).filter((c) =>
c.path.startsWith(path)
);
Expand Down Expand Up @@ -191,9 +196,3 @@ async function loadContentParts({

return [content, context];
}

export const TEST_ONLY = {
loadContentParts,
executeEdit,
executeStreaming,
};

0 comments on commit 3071b17

Please sign in to comment.