Skip to content

Commit 3969d3e

Browse files
committed
refactor: enhance markdown output and template handling ✨
1 parent be6a3d1 commit 3969d3e

File tree

1 file changed

+33
-18
lines changed

1 file changed

+33
-18
lines changed

packages/vscode/src/chatparticipant.ts

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,30 +51,42 @@ export async function activateChatParticipant(state: ExtensionState) {
5151
if (token.isCancellationRequested) return
5252

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

5757
const { project } = state
5858
const { templates } = project
59-
const mdEmpty = () =>
59+
const mdHelp = () =>
6060
md(
61-
`$(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/).`
61+
`\n\n[Docs](https://microsoft.github.io/genaiscript/reference/vscode/github-copilot-chat/) | [Samples](https://microsoft.github.io/genaiscript/samples/)\n`
6262
)
63-
const mdTemplateList = () =>
63+
const mdEmpty = () =>
6464
md(
65-
state.project.templates
66-
.filter((s) => !s.system && !s.unlisted)
67-
.map(
68-
(s) =>
69-
`- [${[s.id]}](${vscode.workspace.asRelativePath(s.filename)}): ${s.title}`
70-
)
71-
.join("\n")
65+
`$(error) Oops, I could not find any genaiscript. Try **GenAIScript: Create new script...** to create one.\n`
7266
)
67+
const mdTemplateList = () => {
68+
templates
69+
.filter((s) => !s.system && !s.unlisted)
70+
.sort((a, b) => a.id.localeCompare(b.id))
71+
.forEach((s) => {
72+
response.markdown("- ")
73+
if (s.filename)
74+
response.anchor(vscode.Uri.file(s.filename), s.id)
75+
else response.markdown(`\`${s.id}\``)
76+
response.markdown(`: ${s.title}\n`)
77+
})
78+
}
7379
if (command === "list") {
74-
if (state.project.templates.length) {
75-
md("Use `@genaiscript /run ...` with one of these scripts:")
80+
if (templates.length) {
81+
md(
82+
"Use `@genaiscript /run ...` with one of these scripts:\n"
83+
)
7684
mdTemplateList()
77-
} else mdEmpty()
85+
mdHelp()
86+
} else {
87+
mdEmpty()
88+
mdHelp()
89+
}
7890
return
7991
}
8092

@@ -84,22 +96,25 @@ export async function activateChatParticipant(state: ExtensionState) {
8496
prompt = prompt.slice(scriptid.length).trim()
8597
template = templates.find((t) => t.id === scriptid)
8698
if (!template) {
87-
if (state.project.templates.length === 0) {
99+
if (templates.length === 0) {
88100
mdEmpty()
89101
} else {
90102
if (scriptid === "")
91-
md(`$(error) Please specify a genaiscript to run.`)
103+
md(
104+
`$(error) Please specify a genaiscript to run.\n`
105+
)
92106
else
93107
md(
94-
`$(error) Oops, I could not find any genaiscript matching \`${scriptid}\`.`
108+
`$(error) Oops, I could not find any genaiscript matching \`${scriptid}\`.\n`
95109
)
96110
md(`Try one of the following:\n`)
97111
mdTemplateList()
112+
mdHelp()
98113
}
99114
return
100115
}
101116
} else {
102-
template = state.project.templates.find(
117+
template = templates.find(
103118
(t) => t.id === COPILOT_CHAT_PARTICIPANT_SCRIPT_ID
104119
)
105120
if (!template) {

0 commit comments

Comments
 (0)