-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove 'genaiscript.prompt.unbuiltin' command and add 'cmds' to setti…
…ngs.json (#710) * Remove 'genaiscript.prompt.unbuiltin' command and add 'cmds' to settings.json * samples download menu * Comment out activateSamplesCommands in extension.ts
- Loading branch information
Showing
7 changed files
with
63 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
"arrayify", | ||
"Automatable", | ||
"bitindex", | ||
"cmds", | ||
"Codespaces", | ||
"demux", | ||
"devcontainers", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import * as vscode from "vscode" | ||
import { ExtensionState } from "./state" | ||
import { registerCommand } from "./commands" | ||
import { Utils } from "vscode-uri" | ||
import { GENAI_SRC } from "../../core/src/constants" | ||
import { parsePromptScriptMeta } from "../../core/src/template" | ||
import { writeFile } from "./fs" | ||
|
||
export function activateSamplesCommands(state: ExtensionState) { | ||
const { context, host } = state | ||
|
||
registerCommand("genaiscript.samples.download", async () => { | ||
const dir = Utils.joinPath(context.extensionUri, GENAI_SRC) | ||
const files = await vscode.workspace.fs.readDirectory( | ||
Utils.joinPath(context.extensionUri, GENAI_SRC) | ||
) | ||
const utf8 = host.createUTF8Decoder() | ||
const samples = ( | ||
await Promise.all( | ||
files | ||
.map((f) => f[0]) | ||
.filter((f) => f.endsWith(".genai.mts")) | ||
.map(async (filename) => ({ | ||
filename, | ||
jsSource: utf8.decode( | ||
await vscode.workspace.fs.readFile( | ||
Utils.joinPath(dir, filename) | ||
) | ||
), | ||
})) | ||
) | ||
).map((s) => ({ ...s, meta: parsePromptScriptMeta(s.jsSource) })) | ||
|
||
const res = await vscode.window.showQuickPick< | ||
vscode.QuickPickItem & { filename: string; jsSource: string } | ||
>( | ||
samples.map((s) => ({ | ||
label: s.meta.title, | ||
detail: s.meta.description, | ||
...s, | ||
})), | ||
{ title: "Pick a sample to download" } | ||
) | ||
if (res === undefined) return | ||
|
||
const { jsSource, filename } = res | ||
await writeFile(host.toUri(GENAI_SRC), filename, jsSource, { | ||
open: true, | ||
}) | ||
await state.parseWorkspace() | ||
}) | ||
} |