Skip to content

Commit d8a07e8

Browse files
committed
Add reusable prompt snippets with #Snippet symbol, settings management, and translations alongside existing templates
- in general > prompt, create 'hidden instructions'. it uses similar conventino in settings.json keys and UI components and backend handling as 'templates' (but they're not merged in any way) - 'hidden instructions' and 'templates' should not support 'accuracy boost' symbol - instead of excluding 'commit' 'changes' etc. should say what to include (skills) - 'hidden instructions' doesn't support {variables}, therefore Templates should not use highlighting - because 'Templates' UI component is used by both 'templates' and 'hidden instructions', it should be renamed to 'PromptInstructions'. also merge settings handling of both to 'prompt instructions' [Accuracy boost] - 'key' in 'prompt instructions' messages should be an union - add support for the new 'hidden instructions' symbol (in the prompt field and quick pick use icon eye-closed) [Accuracy boost] - rename 'hidden instruction' to 'hidden instructions' - 'hidden instructions' symbol should not be interactive - 'hidden instructions' symbol should simply show it title, without 'Hidden: ' prefix - add missing translations to [Fragment] - 'hidden instructions' can include 'skill' symbols. Make sure 1) 'skill' symbols are replaced in final prompt 2) 'skill' symbols are not repeated when used in other sibling 'hidden instructions' or the main instructions. [Accuracy boost] - Rename "hidden instructions" to "Instruction snippets" across the codebase — change the symbol from `#HiddenInstruction("name")` to `#Snippet("name")`, and update all related types, message handlers, `replace-symbols.ts`/`replace-hidden-instruction-symbol.ts`/`hidden-instruction-symbol.ts`, the `#HiddenInstruction` regexes in `use-symbol-deletion.ts`/`position-mapping.ts`/`get-highlighted-text.tsx`/`reconstruct-raw-value.ts`/`handle-input-click.ts`, the `symbol--hidden-instruction` CSS class and `data-type="hidden-instruction-symbol"` attribute, the `hiddenInstructionsForAskAboutFiles`/`hiddenInstructionsForEditFiles` settings keys (with migration), the `HiddenInstructionsForm` component, the `PROMPT_INSTRUCTIONS` message shape, and all i18n strings/translations. [Accuracy boost] - rename 'instruction snippets' to 'snippets' - remove backwards compatibility for 'hiddenInstructiosFor...', leave only 'snippetsFor...' - template should support snippet symbol - [Pasted text] make include required - when no templates are found, we open settings - it's great. we want to open settings as well when no snippets are found - add translations [Fragment] ├── apps │ └── editor │ ├── package.json │ └── src │ ├── features │ │ └── agentic-search │ │ └── agentic-search.ts │ ├── i18n │ │ └── translations │ │ ├── common.ts │ │ └── views │ │ └── shared │ │ └── utils │ │ └── hash-sign-quick-pick.ts │ ├── utils │ │ └── prompt-builder.ts │ └── views │ ├── prompt │ │ ├── backend │ │ │ ├── message-handlers │ │ │ │ ├── handle-autofill.ts │ │ │ │ ├── handle-copy-prompt.ts │ │ │ │ ├── handle-hash-sign-quick-pick.ts │ │ │ │ ├── handle-make-api-call.ts │ │ │ │ ├── handle-preview-prompt.ts │ │ │ │ ├── handle-preview-web-configuration.ts │ │ │ │ ├── handle-template-quick-pick.ts │ │ │ │ └── utils │ │ │ │ ├── build-cli-prompt.ts │ │ │ │ └── build-prompt-payload.ts │ │ │ ├── prompt-view-provider.ts │ │ │ └── utils │ │ │ └── symbols │ │ │ ├── replace-symbols.ts │ │ │ ├── skill │ │ │ │ └── replace-skill-symbol.ts │ │ │ └── snippet │ │ │ └── replace-snippet-symbol.ts │ │ └── types │ │ └── messages.ts │ ├── settings │ │ ├── backend │ │ │ ├── message-handlers │ │ │ │ ├── handle-cancel-prompt-instruction-edit.ts │ │ │ │ ├── handle-create-prompt-instruction.ts │ │ │ │ ├── handle-delete-prompt-instruction.ts │ │ │ │ ├── handle-get-prompt-instructions.ts │ │ │ │ ├── handle-get-templates.ts │ │ │ │ ├── handle-hash-sign-quick-pick.ts │ │ │ │ ├── handle-update-prompt-instructions.ts │ │ │ │ ├── handle-update-templates.ts │ │ │ │ └── index.ts │ │ │ └── settings-view-provider.ts │ │ ├── frontend │ │ │ ├── Home │ │ │ │ ├── Home.tsx │ │ │ │ └── sections │ │ │ │ └── GeneralSection.tsx │ │ │ ├── Settings.tsx │ │ │ ├── forms │ │ │ │ ├── EditPromptInstructionForm │ │ │ │ │ ├── EditPromptInstructionForm.module.scss │ │ │ │ │ ├── EditPromptInstructionForm.tsx │ │ │ │ │ └── index.ts │ │ │ │ ├── SnippetsForm │ │ │ │ │ ├── SnippetsForm.tsx │ │ │ │ │ └── index.ts │ │ │ │ └── TemplatesForm │ │ │ │ ├── TemplatesForm.tsx │ │ │ │ └── index.ts │ │ │ ├── hooks │ │ │ │ ├── use-prompt-instruction-editing.ts │ │ │ │ ├── use-settings.ts │ │ │ │ └── use-template-editing.ts │ │ │ └── i18n │ │ │ ├── translations │ │ │ │ ├── actions.ts │ │ │ │ ├── common.ts │ │ │ │ ├── edit-template-form.ts │ │ │ │ ├── general.ts │ │ │ │ └── index.ts │ │ │ └── use-translation.tsx │ │ ├── helpers │ │ │ └── open-settings.ts │ │ └── types │ │ └── messages.ts │ └── shared │ └── utils │ └── hash-sign-quick-pick │ ├── hash-sign-quick-pick.ts │ ├── index.ts │ └── symbols │ ├── index.ts │ ├── skill-symbol.ts │ └── snippet-symbol.ts └── packages └── ui └── src └── components └── editor ├── common │ └── prompts │ ├── PromptField │ │ ├── PromptField.module.scss │ │ ├── PromptField.stories.tsx │ │ ├── PromptField.tsx │ │ ├── components │ │ │ ├── CompletedTasks │ │ │ │ ├── CompletedTasks.module.scss │ │ │ │ ├── CompletedTasks.tsx │ │ │ │ └── index.ts │ │ │ ├── Footer │ │ │ │ ├── Footer.module.scss │ │ │ │ ├── Footer.tsx │ │ │ │ └── index.ts │ │ │ └── Tabs │ │ │ ├── Tabs.module.scss │ │ │ ├── Tabs.tsx │ │ │ └── index.ts │ │ ├── hooks │ │ │ ├── use-drag-drop.ts │ │ │ ├── use-dropdown.ts │ │ │ ├── use-ghost-text.ts │ │ │ ├── use-handlers │ │ │ │ ├── handle-copy.ts │ │ │ │ ├── handle-cut.ts │ │ │ │ ├── handle-input-change.ts │ │ │ │ ├── handle-input-click.ts │ │ │ │ ├── handle-key-down.ts │ │ │ │ ├── handle-paste.ts │ │ │ │ ├── handle-submit.ts │ │ │ │ ├── index.ts │ │ │ │ ├── types.ts │ │ │ │ ├── use-handlers.ts │ │ │ │ └── utils.ts │ │ │ └── use-keyboard-shortcuts.ts │ │ └── index.ts │ ├── Template │ │ ├── Template.module.scss │ │ ├── Template.tsx │ │ └── index.ts │ └── shared │ ├── hooks │ │ └── use-undo-redo.ts │ └── symbols │ ├── caret.ts │ ├── get-highlighted-text.tsx │ ├── index.ts │ ├── position-mapping.ts │ ├── prompt-symbols.module.scss │ ├── reconstruct-raw-value.ts │ └── use-symbol-deletion.ts └── settings-view ├── PromptInstructions │ ├── PromptInstructions.module.scss │ ├── PromptInstructions.tsx │ └── index.ts └── SortableList ├── SortableList.module.scss ├── SortableList.tsx └── index.ts
1 parent 60d357f commit d8a07e8

46 files changed

Lines changed: 1120 additions & 438 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/editor/package.json‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,42 @@
12351235
]
12361236
}
12371237
},
1238+
"codeWebChat.snippetsForAskAboutFiles": {
1239+
"type": "array",
1240+
"scope": "resource",
1241+
"items": {
1242+
"type": "object",
1243+
"properties": {
1244+
"name": {
1245+
"type": "string"
1246+
},
1247+
"instruction": {
1248+
"type": "string"
1249+
}
1250+
},
1251+
"required": [
1252+
"instruction"
1253+
]
1254+
}
1255+
},
1256+
"codeWebChat.snippetsForEditFiles": {
1257+
"type": "array",
1258+
"scope": "resource",
1259+
"items": {
1260+
"type": "object",
1261+
"properties": {
1262+
"name": {
1263+
"type": "string"
1264+
},
1265+
"instruction": {
1266+
"type": "string"
1267+
}
1268+
},
1269+
"required": [
1270+
"instruction"
1271+
]
1272+
}
1273+
},
12381274
"codeWebChat.providers": {
12391275
"type": "array",
12401276
"scope": "application",

‎apps/editor/src/i18n/translations/views/shared/utils/hash-sign-quick-pick.ts‎

Lines changed: 105 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -332,25 +332,25 @@ export const translations = {
332332
},
333333
'views.shared.utils.hash-sign-quick-pick.quick-pick.accuracy-boost.confirm-modal.message':
334334
{
335-
en: 'Heads up! Accuracy Boost places instructions also on top of the prompt, invalidating cache whenever they change. Quotas could be drained faster or API cost be higher. Do you want to continue?',
335+
en: 'Heads up! Accuracy Boost also places instructions at the top of the prompt, invalidating the cache whenever they change. Quotas could be drained faster, or API costs could be higher. Do you want to continue?',
336336
pl: 'Uwaga! Zwiększenie dokładności umieszcza instrukcje również na górze promptu, unieważniając pamięć podręczną przy każdej ich edycji. Limity mogą wyczerpywać się szybciej lub koszty API mogą być wyższe. Czy chcesz kontynuować?',
337337
'zh-cn':
338-
'注意!提升准确度也会将说明放置在提示的顶部,每当它们更改时都会使缓存失效。配额可能会更快耗尽,或者 API 成本会更高。您想继续吗?',
339-
ja: '注意!精度向上ではプロンプトの上部にも指示が配置されるため、変更されるたびにキャッシュが無効になります。クォータの消費が早まったり、APIコストが高くなる可能性があります。続行しますか?',
338+
'注意!提升准确度也会将说明放置在提示的顶部,每当说明更改时都会使缓存失效。配额可能会消耗得更快,或者 API 成本可能会更高。您要继续吗?',
339+
ja: '注意!精度向上により、プロンプトの上部にも指示が配置されるため、変更されるたびにキャッシュが無効になります。クオータの消費が早くなったり、APIコストが高くなる可能性があります。続行しますか?',
340340
'zh-tw':
341-
'注意!提升準確度也會將說明放置在提示的頂部,每當它們更改時都會使緩存失效。配額可能會更快耗盡,或者 API 成本會更高。您想繼續嗎?',
342-
de: 'Achtung! Die Genauigkeitssteigerung platziert Anweisungen auch oben im Prompt, wodurch der Cache bei jeder Änderung ungültig wird. Quoten könnten schneller aufgebraucht werden oder API-Kosten höher sein. Möchten Sie fortfahren?',
343-
es: '¡Atención! El aumento de precisión también coloca instrucciones en la parte superior del prompt, invalidando la caché cada vez que cambian. Las cuotas podrían agotarse más rápido o el costo de la API podría ser mayor. ¿Desea continuar?',
344-
fr: "Attention ! L'augmentation de la précision place également les instructions en haut du prompt, invalidant le cache à chaque modification. Les quotas pourraient être épuisés plus rapidement ou le coût de l'API pourrait être plus élevé. Voulez-vous continuer ?",
341+
'注意!提升準確度也會將說明放置在提示的頂部,每當說明變更時都會使快取失效。配額可能會消耗得更快,或者 API 成本可能會更高。您要繼續嗎?',
342+
de: 'Achtung! Die Genauigkeitssteigerung platziert Anweisungen auch am Anfang des Prompts, wodurch der Cache bei jeder Änderung ungültig wird. Kontingente könnten schneller aufgebraucht werden oder API-Kosten könnten höher sein. Möchten Sie fortfahren?',
343+
es: '¡Atención! El aumento de precisión también coloca instrucciones en la parte superior del prompt, invalidando la caché cada vez que cambian. Las cuotas podrían agotarse más rápido o los costos de la API podrían ser mayores. ¿Desea continuar?',
344+
fr: "Attention ! L'augmentation de la précision place également des instructions en haut du prompt, invalidant le cache à chaque modification. Les quotas pourraient être épuisés plus rapidement ou les coûts de l'API pourraient être plus élevés. Voulez-vous continuer ?",
345345
'pt-br':
346-
'Atenção! O aumento de precisão também coloca as instruções na parte superior do prompt, invalidando o cache sempre que forem alteradas. As cotas podem se esgotar mais rapidamente ou o custo da API pode ser maior. Deseja continuar?',
347-
ru: 'Внимание! Повышение точности также помещает инструкции в начало промпта, делая кэш недействительным при каждом их изменении. Квоты могут исчерпаться быстрее или стоимость API может быть выше. Вы хотите продолжить?',
348-
ko: '주의! 정확도 향상은 프롬프트 상단에도 지침을 배치하여 변경될 때마다 캐시를 무효화합니다. 할당량이 더 빨리 소진되거나 API 비용이 더 높아질 수 있습니다. 계속하시겠습니까?',
349-
it: "Attenzione! L'aumento di precisione posiziona le istruzioni anche in cima al prompt, invalidando la cache ogni volta che cambiano. Le quote potrebbero esaurirsi più velocemente o il costo dell'API potrebbe essere più elevato. Vuoi continuare?",
350-
tr: 'Dikkat! Doğruluk artışı, talimatları istemcinin en üstüne de yerleştirir ve her değiştiklerinde önbelleği geçersiz kılar. Kotalar daha hızlı tükenebilir veya API maliyeti daha yüksek olabilir. Devam etmek istiyor musunuz?',
351-
cs: 'Pozor! Zvýšení přesnosti umisťuje instrukce také na začátek promptu, což zneplatní mezipaměť při každé jejich změně. Kvóty by se mohly vyčerpat rychleji nebo by mohly být vyšší náklady na API. Chcete pokračovat?',
352-
hu: 'Figyelem! A pontosságnövelés a prompt tetejére is elhelyezi az utasításokat, így minden változáskor érvényteleníti a gyorsítótárat. A kvóták gyorsabban kimerülhetnek, vagy magasabbak lehetnek az API költségek. Biztosan folytatja?',
353-
bg: 'Внимание! Повишаването на точността също така поставя инструкциите в горната част на промпта, като обезсилва кеша при всяка тяхна промяна. Квотите могат да бъдат изчерпани по-бързо или разходите за API да бъдат по-високи. Искате ли да продължите?'
346+
'Atenção! O Aumento de Precisão também coloca instruções no topo do prompt, invalidando o cache sempre que elas mudam. As cotas podem ser esgotadas mais rapidamente ou os custos da API podem ser maiores. Deseja continuar?',
347+
ru: 'Внимание! Повышение точности также помещает инструкции в начало промпта, сбрасывая кэш при каждом их изменении. Квоты могут исчерпываться быстрее, а стоимость API может возрасти. Вы хотите продолжить?',
348+
ko: '주의! 정확도 향상은 프롬프트 상단에도 지침을 배치하여 지침이 변경될 때마다 캐시를 무효화합니다. 할당량이 더 빨리 소진되거나 API 비용이 더 높아질 수 있습니다. 계속하시겠습니까?',
349+
it: 'Attenzione! Il potenziamento della precisione posiziona le istruzioni anche in cima al prompt, invalidando la cache ogni volta che cambiano. Le quote potrebbero esaurirsi più velocemente o i costi delle API potrebbero essere più alti. Vuoi continuare?',
350+
tr: 'Dikkat! Doğruluk Artışı, talimatları istemin en üstüne de yerleştirir ve her değiştiklerinde önbelleği geçersiz kılar. Kotalar daha hızlı tükenebilir veya API maliyetleri daha yüksek olabilir. Devam etmek istiyor musunuz?',
351+
cs: 'Pozor! Zvýšení přesnosti také umístí instrukce na začátek promptu, což zneplatní mezipaměť při každé jejich změně. Kvóty by se mohly vyčerpat rychleji nebo by mohly být vyšší náklady na API. Chcete pokračovat?',
352+
hu: 'Figyelem! A Pontosságnövelés a prompt tetejére is elhelyezi az utasításokat, érvénytelenítve a gyorsítótárat, amikor azok megváltoznak. A kvóták gyorsabban elfogyhatnak, vagy az API-költségek magasabbak lehetnek. Szeretné folytatni?',
353+
bg: 'Внимание! Повишаването на точността също поставя инструкции в горната част на промпта, като обезсилва кеша при всяка тяхна промяна. Квотите могат да бъдат изчерпани по-бързо или разходите за API може да са по-високи. Искате ли да продължите?'
354354
},
355355
'views.shared.utils.hash-sign-quick-pick.quick-pick.accuracy-boost.confirm-modal.confirm':
356356
{
@@ -408,6 +408,96 @@ export const translations = {
408408
hu: 'Válassza ki a beszúrandó szimbólumot',
409409
bg: 'Изберете символ за вмъкване'
410410
},
411+
'views.shared.utils.hash-sign-quick-pick.snippet-symbol.no-instructions': {
412+
en: 'No snippets found.',
413+
pl: 'Nie znaleziono fragmentów.',
414+
'zh-cn': '未找到片段。',
415+
ja: 'スニペットが見つかりません。',
416+
'zh-tw': '未找到片段。',
417+
de: 'Keine Schnipsel gefunden.',
418+
es: 'No se encontraron fragmentos.',
419+
fr: 'Aucun extrait trouvé.',
420+
'pt-br': 'Nenhum snippet encontrado.',
421+
ru: 'Фрагменты не найдены.',
422+
ko: '스니펫을 찾을 수 없습니다.',
423+
it: 'Nessuno snippet trovato.',
424+
tr: 'Parça bulunamadı.',
425+
cs: 'Nebyly nalezeny žádné fragmenty.',
426+
hu: 'Nem találhatók töredékek.',
427+
bg: 'Не са намерени фрагменти.'
428+
},
429+
'views.shared.utils.hash-sign-quick-pick.snippet-symbol.placeholder': {
430+
en: 'Select snippet',
431+
pl: 'Wybierz fragment',
432+
'zh-cn': '选择片段',
433+
ja: 'スニペットを選択',
434+
'zh-tw': '選擇片段',
435+
de: 'Schnipsel auswählen',
436+
es: 'Seleccionar fragmento',
437+
fr: "Sélectionner l'extrait",
438+
'pt-br': 'Selecionar snippet',
439+
ru: 'Выберите фрагмент',
440+
ko: '스니펫 선택',
441+
it: 'Seleziona lo snippet',
442+
tr: 'Parçayı seçin',
443+
cs: 'Vyberte fragment',
444+
hu: 'Töredék kiválasztása',
445+
bg: 'Изберете фрагмент'
446+
},
447+
'views.shared.utils.hash-sign-quick-pick.snippet-symbol.title': {
448+
en: 'Snippets',
449+
pl: 'Fragmenty',
450+
'zh-cn': '片段',
451+
ja: 'スニペット',
452+
'zh-tw': '片段',
453+
de: 'Schnipsel',
454+
es: 'Fragmentos',
455+
fr: 'Extraits',
456+
'pt-br': 'Snippets',
457+
ru: 'Фрагменты',
458+
ko: '스니펫',
459+
it: 'Snippet',
460+
tr: 'Parçalar',
461+
cs: 'Fragmenty',
462+
hu: 'Töredékek',
463+
bg: 'Фрагменти'
464+
},
465+
'views.shared.utils.hash-sign-quick-pick.quick-pick.snippets.label': {
466+
en: 'Snippets',
467+
pl: 'Fragmenty',
468+
'zh-cn': '片段',
469+
ja: 'スニペット',
470+
'zh-tw': '片段',
471+
de: 'Schnipsel',
472+
es: 'Fragmentos',
473+
fr: 'Extraits',
474+
'pt-br': 'Snippets',
475+
ru: 'Фрагменты',
476+
ko: '스니펫',
477+
it: 'Snippet',
478+
tr: 'Parçalar',
479+
cs: 'Fragmenty',
480+
hu: 'Töredékek',
481+
bg: 'Фрагменти'
482+
},
483+
'views.shared.utils.hash-sign-quick-pick.quick-pick.snippets.description': {
484+
en: 'Reusable instructions',
485+
pl: 'Instrukcje wielokrotnego użytku',
486+
'zh-cn': '可重用说明',
487+
ja: '再利用可能な指示',
488+
'zh-tw': '可重複使用說明',
489+
de: 'Wiederverwendbare Anweisungen',
490+
es: 'Instrucciones reutilizables',
491+
fr: 'Instructions réutilisables',
492+
'pt-br': 'Instruções reutilizáveis',
493+
ru: 'Многоразовые инструкции',
494+
ko: '재사용 가능한 지침',
495+
it: 'Istruzioni riutilizzabili',
496+
tr: 'Yeniden kullanılabilir talimatlar',
497+
cs: 'Znovu použitelné instrukce',
498+
hu: 'Újrafelhasználható utasítások',
499+
bg: 'Многократно използваеми инструкции'
500+
},
411501
'views.shared.utils.hash-sign-quick-pick.quick-pick.title': {
412502
en: 'Symbols',
413503
pl: 'Symbole',

‎apps/editor/src/views/prompt/backend/message-handlers/handle-hash-sign-quick-pick.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export const handle_hash_sign_quick_pick = async (
2727

2828
const replacement = await hash_sign_quick_pick({
2929
extension_context,
30-
on_insert
30+
on_insert,
31+
prompt_type: prompt_view_provider.prompt_type as 'ask' | 'edit' | undefined
3132
})
3233

3334
if (replacement) {

‎apps/editor/src/views/prompt/backend/utils/symbols/replace-symbols.ts‎

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { replace_image_symbol } from './image/replace-image-symbol'
1010
import { replace_pasted_text_symbol } from './pasted-text/replace-pasted-text-symbol'
1111
import { replace_website_symbol } from './website/replace-website-symbol'
1212
import { replace_fragment_symbol } from './fragment/replace-fragment-symbol'
13+
import { replace_snippet_symbol } from './snippet/replace-snippet-symbol'
1314
import { SymbolCacheManager } from './symbol-cache'
1415

1516
export const replace_symbols = async (params: {
@@ -19,10 +20,33 @@ export const replace_symbols = async (params: {
1920
remove_images?: boolean
2021
image_as_paths?: boolean
2122
symbols_cache?: SymbolCacheManager
22-
}): Promise<{ instructions: string[]; skill_definitions: string; accuracy_boost: boolean }> => {
23+
}): Promise<{
24+
instructions: string[]
25+
skill_definitions: string
26+
accuracy_boost: boolean
27+
}> => {
2328
let processed_instructions = [...params.instructions]
2429
let skill_definitions = ''
2530

31+
let snippet_iterations = 0
32+
let has_snippets = processed_instructions.some((i) => i.includes('#Snippet('))
33+
while (has_snippets && snippet_iterations < 10) {
34+
const result = await replace_snippet_symbol({
35+
instructions: processed_instructions
36+
})
37+
38+
const changed = result.instructions.some(
39+
(instr, idx) => instr !== processed_instructions[idx]
40+
)
41+
if (!changed) {
42+
break
43+
}
44+
45+
processed_instructions = result.instructions
46+
has_snippets = processed_instructions.some((i) => i.includes('#Snippet('))
47+
snippet_iterations++
48+
}
49+
2650
if (processed_instructions.some((i) => i.includes('#Changes('))) {
2751
const result = await replace_changes_symbol({
2852
instructions: processed_instructions,
@@ -95,7 +119,9 @@ export const replace_symbols = async (params: {
95119
})
96120
}
97121

98-
const accuracy_boost = processed_instructions.some((i) => i.includes('#AccuracyBoost'))
122+
const accuracy_boost = processed_instructions.some((i) =>
123+
i.includes('#AccuracyBoost')
124+
)
99125
if (accuracy_boost) {
100126
processed_instructions = processed_instructions.map((i) =>
101127
i
@@ -105,5 +131,9 @@ export const replace_symbols = async (params: {
105131
)
106132
}
107133

108-
return { instructions: processed_instructions, skill_definitions, accuracy_boost }
134+
return {
135+
instructions: processed_instructions,
136+
skill_definitions,
137+
accuracy_boost
138+
}
109139
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import * as vscode from 'vscode'
2+
3+
export const replace_snippet_symbol = async (params: {
4+
instructions: string[]
5+
}): Promise<{ instructions: string[] }> => {
6+
const config = vscode.workspace.getConfiguration('codeWebChat')
7+
const ask_instructions =
8+
config.get<{ name: string; instruction: string }[]>(
9+
'snippetsForAskAboutFiles'
10+
) || []
11+
const edit_instructions =
12+
config.get<{ name: string; instruction: string }[]>(
13+
'snippetsForEditFiles'
14+
) || []
15+
16+
const all_snippets = [...ask_instructions, ...edit_instructions]
17+
18+
const regex = /#Snippet\("((?:\\.|[^"\\])*)"\)/g
19+
20+
const instructions = params.instructions.map((instruction) => {
21+
return instruction.replace(regex, (match, name) => {
22+
const decoded_name = name.replace(/\\"/g, '"').replace(/\\\\/g, '\\')
23+
const found = all_snippets.find((i) => i.name === decoded_name)
24+
return found ? found.instruction : match
25+
})
26+
})
27+
28+
return { instructions }
29+
}

apps/editor/src/views/settings/backend/message-handlers/handle-cancel-template-edit.ts renamed to apps/editor/src/views/settings/backend/message-handlers/handle-cancel-prompt-instruction-edit.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
import * as vscode from 'vscode'
22
import { SettingsViewProvider } from '../settings-view-provider'
3-
import { CancelTemplateEditMessage } from '@/views/settings/types/messages'
3+
import { CancelPromptInstructionEditMessage } from '@/views/settings/types/messages'
44
import { t } from '@/i18n'
55

6-
export const handle_cancel_template_edit = async (
6+
export const handle_cancel_prompt_instruction_edit = async (
77
provider: SettingsViewProvider,
8-
_message: CancelTemplateEditMessage
8+
message: CancelPromptInstructionEditMessage
99
): Promise<void> => {
1010
const discard_button = t('common.action.discard')
11+
const is_template = message.key?.startsWith('templates')
12+
const item_name = is_template ? 'template' : 'snippet'
13+
1114
const result = await vscode.window.showWarningMessage(
1215
t('views.common.handlers.common.confirm-discard-unsaved-changes', {
13-
item_type: 'template'
16+
item_type: item_name
1417
}),
1518
{
1619
modal: true,
1720
detail: t('views.common.handlers.common.unsaved-changes-will-be-lost', {
18-
item_type: 'template'
21+
item_type: item_name
1922
})
2023
},
2124
discard_button
@@ -25,5 +28,5 @@ export const handle_cancel_template_edit = async (
2528
return
2629
}
2730

28-
provider.postMessage({ command: 'TEMPLATE_EDIT_CANCELLED' })
31+
provider.postMessage({ command: 'PROMPT_INSTRUCTION_EDIT_CANCELLED' })
2932
}

apps/editor/src/views/settings/backend/message-handlers/handle-create-template.ts renamed to apps/editor/src/views/settings/backend/message-handlers/handle-create-prompt-instruction.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import * as vscode from 'vscode'
2-
import { CreateTemplateMessage } from '@/views/settings/types/messages'
2+
import { CreatePromptInstructionMessage } from '@/views/settings/types/messages'
33
import { SettingsViewProvider } from '../settings-view-provider'
44
import { t } from '@/i18n'
55

6-
export const handle_create_template = async (
6+
export const handle_create_prompt_instruction = async (
77
provider: SettingsViewProvider,
8-
message: CreateTemplateMessage
8+
message: CreatePromptInstructionMessage
99
): Promise<void> => {
1010
let insertion_index: number | undefined = message.insertion_index
1111

@@ -66,9 +66,9 @@ export const handle_create_template = async (
6666
}
6767

6868
provider.postMessage({
69-
command: 'START_TEMPLATE_CREATION',
70-
templates_key: message.templates_key,
71-
template: { template: '' },
69+
command: 'START_PROMPT_INSTRUCTION_CREATION',
70+
key: message.key,
71+
instruction: { value: '' },
7272
insertion_index
7373
})
7474
}

0 commit comments

Comments
 (0)