Skip to content

Commit f74f8c9

Browse files
committed
Add support for previewing saved context symbols on click
- enable previewing 'saved context' symbol by showing those files in a way they're later attached to prompt (markdown preview) ├── README.md ├── apps │ └── editor │ └── src │ ├── commands │ │ └── generate-commit-message-commands │ │ └── utils │ │ └── build-commit-message-prompt.ts │ ├── context │ │ └── providers │ │ └── workspace │ │ └── modules │ │ └── token-calculator.ts │ ├── features │ │ ├── context-restoration │ │ │ ├── index.ts │ │ │ └── utils │ │ │ ├── context-file-utils.ts │ │ │ ├── create-context-description.ts │ │ │ ├── file-contexts.ts │ │ │ ├── global-storage-utils.ts │ │ │ ├── resolve-context-paths.ts │ │ │ ├── resolve-paths.ts │ │ │ └── select-context-paths.ts │ │ └── search-files │ │ ├── search-modes │ │ │ └── perform-intelligent-search-mode.ts │ │ └── utils │ │ └── search-files-by-intelligent.ts │ ├── types │ │ └── context.ts │ ├── utils │ │ ├── files-collector.ts │ │ └── prompt-builder.ts │ └── views │ ├── prompt │ │ ├── backend │ │ │ ├── message-handlers │ │ │ │ ├── handle-patch-repair.ts │ │ │ │ ├── handle-preview-saved-context-symbol.ts │ │ │ │ ├── handle-preview-skill-symbol.ts │ │ │ │ ├── handle-voice-input.ts │ │ │ │ ├── index.ts │ │ │ │ └── utils │ │ │ │ ├── build-prompt-payload.ts │ │ │ │ └── patch-repair-utils.ts │ │ │ ├── prompt-view-provider.ts │ │ │ └── utils │ │ │ └── symbols │ │ │ ├── git │ │ │ │ └── replace-git-symbols.ts │ │ │ ├── replace-symbols.ts │ │ │ ├── saved-context │ │ │ │ └── replace-saved-context-symbol.ts │ │ │ └── skill │ │ │ └── replace-skill-symbol.ts │ │ ├── frontend │ │ │ └── Main │ │ │ └── MainView │ │ │ ├── MainView.tsx │ │ │ └── components │ │ │ └── PromptAttachments │ │ │ └── PromptAttachments.tsx │ │ └── types │ │ └── messages.ts │ ├── settings │ │ ├── backend │ │ │ ├── message-handlers │ │ │ │ └── handle-hash-sign-quick-pick.ts │ │ │ └── settings-view-provider.ts │ │ ├── frontend │ │ │ ├── Home │ │ │ │ └── sections │ │ │ │ └── GeneralSection.tsx │ │ │ ├── Settings.tsx │ │ │ └── forms │ │ │ └── EditTemplateForm │ │ │ ├── EditTemplateForm.module.scss │ │ │ ├── EditTemplateForm.tsx │ │ │ └── index.ts │ │ └── types │ │ └── messages.ts │ └── shared │ └── utils │ └── hash-sign-quick-pick │ ├── hash-sign-quick-pick.ts │ └── symbols │ ├── index.ts │ └── saved-context-symbol.ts └── packages ├── shared │ └── src │ └── utils │ └── simplify-prompt-symbols │ └── simplify-prompt-symbols.ts └── ui └── src └── components └── editor ├── common │ └── prompts │ ├── PromptField │ │ ├── PromptField.tsx │ │ ├── components │ │ │ └── Footer │ │ │ └── Footer.tsx │ │ └── hooks │ │ └── use-handlers │ │ ├── handle-input-click.ts │ │ └── use-handlers.ts │ ├── Template │ │ ├── Template.module.scss │ │ └── Template.tsx │ └── shared │ └── 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 └── Templates └── Templates.tsx
1 parent 6dd4b62 commit f74f8c9

9 files changed

Lines changed: 92 additions & 1 deletion

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import * as vscode from 'vscode'
2+
import { replace_saved_context_symbol } from '../utils/symbols/saved-context/replace-saved-context-symbol'
3+
import { preview_text_in_temp_file } from '../utils/preview-text-in-temp-file'
4+
import { PromptViewProvider } from '../prompt-view-provider'
5+
6+
export const handle_preview_saved_context_symbol = async (params: {
7+
prompt_view_provider: PromptViewProvider
8+
message: { context_type: string; context_name: string }
9+
}) => {
10+
try {
11+
const instruction = `#SavedContext(${params.message.context_type} "${params.message.context_name}")`
12+
const { context_definitions } = await replace_saved_context_symbol({
13+
instructions: [instruction],
14+
extension_context: params.prompt_view_provider.extension_context,
15+
workspace_provider: params.prompt_view_provider.workspace_provider
16+
})
17+
18+
if (context_definitions) {
19+
await preview_text_in_temp_file({
20+
prefix: 'cwc-context',
21+
content: context_definitions.trim(),
22+
extension: '.md'
23+
})
24+
} else {
25+
vscode.window.showInformationMessage(
26+
'Failed to generate context preview.'
27+
)
28+
}
29+
} catch (error) {
30+
vscode.window.showErrorMessage(`Failed to preview context: ${error}`)
31+
}
32+
}

‎apps/editor/src/views/prompt/backend/message-handlers/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export * from './handle-install-browser-extension'
5757
export * from './handle-preview-changes-symbol'
5858
export * from './handle-preview-commit-symbol'
5959
export * from './handle-preview-skill-symbol'
60+
export * from './handle-preview-saved-context-symbol'
6061
export * from './configurations'
6162
export * from './handle-pick-agent'
6263
export * from './handle-get-completed-tasks'

‎apps/editor/src/views/prompt/backend/prompt-view-provider.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ import {
101101
handle_clear_completed_tasks
102102
} from './message-handlers'
103103
import { handle_agentic_search } from './message-handlers/handle-agentic-search'
104+
import { handle_preview_saved_context_symbol } from './message-handlers/handle-preview-saved-context-symbol'
104105
import { SelectionState } from '../types/messages'
105106
import {
106107
EDIT_FORMAT_STATE_KEY,
@@ -895,6 +896,11 @@ export class PromptViewProvider implements vscode.WebviewViewProvider {
895896
await handle_preview_commit_symbol(message)
896897
} else if (message.command == 'PREVIEW_SKILL_SYMBOL') {
897898
await handle_preview_skill_symbol(message)
899+
} else if (message.command == 'PREVIEW_SAVED_CONTEXT_SYMBOL') {
900+
await handle_preview_saved_context_symbol({
901+
prompt_view_provider: this,
902+
message
903+
})
898904
} else if (message.command == 'AGENTIC_SEARCH') {
899905
await handle_agentic_search(this)
900906
} else if (message.command == 'GET_CLI_CONFIGURATIONS') {

‎apps/editor/src/views/prompt/frontend/Main/Main.tsx‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ type Props = {
9292
}
9393

9494
export const Main: React.FC<Props> = (props) => {
95+
const { vscode } = props
9596
const [web_configurations, set_web_configurations] =
9697
useState<WebConfiguration[]>()
9798
const [
@@ -719,7 +720,21 @@ export const Main: React.FC<Props> = (props) => {
719720
on_preview_prompt={props.on_preview_prompt}
720721
on_changes_click={props.on_changes_click}
721722
on_commit_click={props.on_commit_click}
722-
on_skill_click={props.on_skill_click}
723+
on_skill_click={(agent, repo, skill_name) => {
724+
post_message(vscode, {
725+
command: 'PREVIEW_SKILL_SYMBOL',
726+
agent,
727+
repo,
728+
skill_name
729+
})
730+
}}
731+
on_saved_context_click={(context_type, context_name) => {
732+
post_message(vscode, {
733+
command: 'PREVIEW_SAVED_CONTEXT_SYMBOL',
734+
context_type,
735+
context_name
736+
})
737+
}}
723738
on_install_browser_extension={handle_install_browser_extension}
724739
on_agentic_search={props.on_agentic_search}
725740
on_clear_context={handle_clear_context}

‎apps/editor/src/views/prompt/frontend/Main/MainView/MainView.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ type Props = {
145145
commit_message?: string
146146
) => void
147147
on_skill_click?: (agent: string, repo: string, skill_name: string) => void
148+
on_saved_context_click?: (context_type: string, context_name: string) => void
148149
on_install_browser_extension: () => void
149150
on_agentic_search: () => void
150151
on_clear_context: () => void
@@ -506,6 +507,7 @@ export const MainView: React.FC<Props> = (props) => {
506507
on_clear_context={props.on_clear_context}
507508
on_commit_click={props.on_commit_click}
508509
on_skill_click={props.on_skill_click}
510+
on_saved_context_click={props.on_saved_context_click}
509511
on_preview_prompt={props.on_preview_prompt}
510512
is_recording={props.is_recording}
511513
on_recording_started={props.on_recording_started}

‎apps/editor/src/views/prompt/types/messages.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,12 @@ export interface PreviewSkillSymbolMessage extends BaseMessage {
591591
skill_name: string
592592
}
593593

594+
export interface PreviewSavedContextSymbolMessage extends BaseMessage {
595+
command: 'PREVIEW_SAVED_CONTEXT_SYMBOL'
596+
context_type: string
597+
context_name: string
598+
}
599+
594600
export interface AgenticSearchMessage extends BaseMessage {
595601
command: 'AGENTIC_SEARCH'
596602
}
@@ -712,6 +718,7 @@ export type FrontendMessage =
712718
| PreviewChangesSymbolMessage
713719
| PreviewCommitSymbolMessage
714720
| PreviewSkillSymbolMessage
721+
| PreviewSavedContextSymbolMessage
715722
| AgenticSearchMessage
716723
| GetAgentConfigurationsMessage
717724
| ReorderAgentConfigurationsMessage

‎packages/ui/src/components/editor/common/prompts/PromptField/PromptField.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ export namespace PromptField {
7575
commit_message?: string
7676
) => void
7777
on_skill_click?: (agent: string, repo: string, skill_name: string) => void
78+
on_saved_context_click?: (
79+
context_type: string,
80+
context_name: string
81+
) => void
7882
on_preview_prompt?: () => void
7983
is_recording: boolean
8084
on_recording_started: () => void

‎packages/ui/src/components/editor/common/prompts/PromptField/hooks/use-handlers/handle-input-click.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ export const create_handle_input_click = ({
7575
}
7676
}
7777

78+
const saved_context_symbol_element = text_element.closest<HTMLElement>(
79+
'[data-type="saved-context-symbol"]'
80+
)
81+
if (saved_context_symbol_element) {
82+
const context_type = saved_context_symbol_element.dataset.contextType
83+
const context_name = saved_context_symbol_element.dataset.contextName
84+
85+
if (context_type && context_name) {
86+
props.on_saved_context_click?.(context_type, context_name)
87+
}
88+
}
89+
7890
const image_symbol_element = text_element.closest<HTMLElement>(
7991
'[data-type="image-symbol"]'
8092
)

‎packages/ui/src/components/editor/common/prompts/shared/symbols/prompt-symbols.module.scss‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,18 @@
170170
content: '\eab3';
171171
}
172172

173+
&--saved-context &__text {
174+
cursor: pointer;
175+
176+
&:hover {
177+
background-color: color-mix(
178+
in srgb,
179+
var(--vscode-charts-blue) 30%,
180+
transparent
181+
);
182+
}
183+
}
184+
173185
&--pasted-lines &__icon::before {
174186
content: '\eac0';
175187
}

0 commit comments

Comments
 (0)