Skip to content

Commit

Permalink
refactor: simplify error handling in chat participant 💡
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Nov 21, 2024
1 parent b792d4d commit b30814d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/vscode/src/chatparticipant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export async function activateChatParticipant(state: ExtensionState) {

const { project } = state
const { templates } = project
const mdEmpty = () =>
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/).`
)
const mdTemplateList = () =>
md(
state.project.templates
Expand All @@ -64,8 +68,10 @@ export async function activateChatParticipant(state: ExtensionState) {
.join("\n")
)
if (command === "list") {
md("Use `@genaiscript /run ...` with one of these scripts:")
mdTemplateList()
if (state.project.templates.length) {
md("Use `@genaiscript /run ...` with one of these scripts:")
mdTemplateList()
} else mdEmpty()
return
}

Expand All @@ -76,9 +82,7 @@ export async function activateChatParticipant(state: ExtensionState) {
template = templates.find((t) => t.id === scriptid)
if (!template) {
if (state.project.templates.length === 0) {
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/).`
)
mdEmpty()
} else {
if (scriptid === "")
md(`$(error) Please specify a genaiscript to run.`)
Expand Down

0 comments on commit b30814d

Please sign in to comment.