Skip to content

Commit 3a5329e

Browse files
committed
update to prompt file
1 parent 3c4ebd3 commit 3a5329e

File tree

4 files changed

+34
-10
lines changed

4 files changed

+34
-10
lines changed

core/config/load.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,10 @@ async function serializedToIntermediateConfig(
215215
promptFiles.push(...readAllGlobalPromptFiles());
216216

217217
for (const file of promptFiles) {
218-
slashCommands.push(slashCommandFromPromptFile(file.path, file.content));
218+
const slashCommand = slashCommandFromPromptFile(file.path, file.content);
219+
if (slashCommand) {
220+
slashCommands.push(slashCommand);
221+
}
219222
}
220223
}
221224

core/config/promptFile.ts

+21-6
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@ import path from "path";
33
import Handlebars from "handlebars";
44
import * as YAML from "yaml";
55

6-
import { BaseContextProvider } from "../context";
76
import { walkDir } from "../indexing/walkDir";
87
import { stripImages } from "../llm/images";
98
import { renderTemplatedString } from "../promptFiles/v1/renderTemplatedString";
109
import { getBasename } from "../util/index";
1110

12-
import type { ChatHistory, ChatHistoryItem, ChatMessage, ContextItem, ContinueSDK, IContextProvider, IDE, SlashCommand } from "..";
11+
import type {
12+
ChatMessage,
13+
ContextItem,
14+
ContinueSDK,
15+
IContextProvider,
16+
IDE,
17+
SlashCommand,
18+
} from "..";
1319

1420
export const DEFAULT_PROMPTS_FOLDER = ".prompts";
1521

@@ -93,12 +99,16 @@ export async function createNewPromptFile(
9399
export function slashCommandFromPromptFile(
94100
path: string,
95101
content: string,
96-
): SlashCommand {
97-
const { name, description, systemMessage, prompt } = parsePromptFile(
102+
): SlashCommand | null {
103+
const { name, description, systemMessage, prompt, version } = parsePromptFile(
98104
path,
99105
content,
100106
);
101107

108+
if (version !== 1) {
109+
return null;
110+
}
111+
102112
return {
103113
name,
104114
description,
@@ -134,14 +144,15 @@ function parsePromptFile(path: string, content: string) {
134144
const preamble = YAML.parse(preambleRaw) ?? {};
135145
const name = preamble.name ?? getBasename(path).split(".prompt")[0];
136146
const description = preamble.description ?? name;
147+
const version = preamble.version ?? 2;
137148

138149
let systemMessage: string | undefined = undefined;
139150
if (prompt.includes("<system>")) {
140151
systemMessage = prompt.split("<system>")[1].split("</system>")[0].trim();
141152
prompt = prompt.split("</system>")[1].trim();
142153
}
143154

144-
return { name, description, systemMessage, prompt };
155+
return { name, description, systemMessage, prompt, version };
145156
}
146157

147158
function extractUserInput(input: string, commandName: string): string {
@@ -151,7 +162,11 @@ function extractUserInput(input: string, commandName: string): string {
151162
return input;
152163
}
153164

154-
async function renderPrompt(prompt: string, context: ContinueSDK, userInput: string) {
165+
async function renderPrompt(
166+
prompt: string,
167+
context: ContinueSDK,
168+
userInput: string,
169+
) {
155170
const helpers = getContextProviderHelpers(context);
156171

157172
// A few context providers that don't need to be in config.json to work in .prompt files

extensions/vscode/package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/vscode/src/lang-server/promptFileCompletions.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ class YamlKeysCompletionItemProvider implements vscode.CompletionItemProvider {
141141
const lineText = document.lineAt(position).text;
142142
const textBeforeCursor = lineText.substring(0, position.character);
143143

144+
// 0. If no delimiter in the file, return no completions
145+
const fullContent = document.getText();
146+
if (!fullContent.includes("---")) {
147+
return undefined;
148+
}
149+
144150
// 1. Check if the cursor is in YAML section (before --- delimiter)
145151
const beforeDelimiter = isCursorBeforeDelimiter(document, position);
146152

@@ -160,7 +166,7 @@ class YamlKeysCompletionItemProvider implements vscode.CompletionItemProvider {
160166
vscode.CompletionItemKind.Property,
161167
);
162168
item.documentation = new vscode.MarkdownString(key.description);
163-
item.insertText = key + ": ";
169+
item.insertText = key.key + ": ";
164170
return item;
165171
});
166172

0 commit comments

Comments
 (0)