Skip to content

Commit

Permalink
refactor: enhance markdown output and template handling ✨
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Nov 21, 2024
1 parent be6a3d1 commit 3969d3e
Showing 1 changed file with 33 additions and 18 deletions.
51 changes: 33 additions & 18 deletions packages/vscode/src/chatparticipant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,42 @@ export async function activateChatParticipant(state: ExtensionState) {
if (token.isCancellationRequested) return

const md = (t: string) => {
response.markdown(new vscode.MarkdownString(t, true))
response.markdown(new vscode.MarkdownString(t + "\n", true))
}

const { project } = state
const { templates } = project
const mdEmpty = () =>
const mdHelp = () =>
md(
`$(error) Oops, I could not find any genaiscript. Try **GenAIScript: Create new script...** to create one or checkout [samples](https://microsoft.github.io/genaiscript/reference/vscode/github-copilot-chat/).`
`\n\n[Docs](https://microsoft.github.io/genaiscript/reference/vscode/github-copilot-chat/) | [Samples](https://microsoft.github.io/genaiscript/samples/)\n`
)
const mdTemplateList = () =>
const mdEmpty = () =>
md(
state.project.templates
.filter((s) => !s.system && !s.unlisted)
.map(
(s) =>
`- [${[s.id]}](${vscode.workspace.asRelativePath(s.filename)}): ${s.title}`
)
.join("\n")
`$(error) Oops, I could not find any genaiscript. Try **GenAIScript: Create new script...** to create one.\n`
)
const mdTemplateList = () => {
templates
.filter((s) => !s.system && !s.unlisted)
.sort((a, b) => a.id.localeCompare(b.id))
.forEach((s) => {
response.markdown("- ")
if (s.filename)
response.anchor(vscode.Uri.file(s.filename), s.id)
else response.markdown(`\`${s.id}\``)
response.markdown(`: ${s.title}\n`)
})
}
if (command === "list") {
if (state.project.templates.length) {
md("Use `@genaiscript /run ...` with one of these scripts:")
if (templates.length) {
md(
"Use `@genaiscript /run ...` with one of these scripts:\n"
)
mdTemplateList()
} else mdEmpty()
mdHelp()
} else {
mdEmpty()
mdHelp()
}
return
}

Expand All @@ -84,22 +96,25 @@ export async function activateChatParticipant(state: ExtensionState) {
prompt = prompt.slice(scriptid.length).trim()
template = templates.find((t) => t.id === scriptid)
if (!template) {
if (state.project.templates.length === 0) {
if (templates.length === 0) {
mdEmpty()
} else {
if (scriptid === "")
md(`$(error) Please specify a genaiscript to run.`)
md(
`$(error) Please specify a genaiscript to run.\n`
)
else
md(
`$(error) Oops, I could not find any genaiscript matching \`${scriptid}\`.`
`$(error) Oops, I could not find any genaiscript matching \`${scriptid}\`.\n`
)
md(`Try one of the following:\n`)
mdTemplateList()
mdHelp()
}
return
}
} else {
template = state.project.templates.find(
template = templates.find(
(t) => t.id === COPILOT_CHAT_PARTICIPANT_SCRIPT_ID
)
if (!template) {
Expand Down

0 comments on commit 3969d3e

Please sign in to comment.