Skip to content

Commit fc4a32f

Browse files
committed
Add command to copy XML-formatted edit format instructions to the clipboard
1 parent bb1f88f commit fc4a32f

5 files changed

Lines changed: 80 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ CWC includes useful API tools. Bring Your Own Key (BYOK) for a model provider of
184184
- `Search Files for Context` - Search and add files containing specific keywords to the context.
185185
- `Copy Context` - Copy XML-formatted checked files from the Workspace view to the clipboard.
186186
- `Copy Context of Open Editors` - Copy XML-formatted checked files from the Open Editors view to the clipboard.
187+
- `Copy Edit Format Instructions` - Copy XML-formatted edit format instructions to the clipboard.
187188

188189
### Commit messages
189190

apps/editor/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,12 @@
310310
"title": "%codeWebChat.generateCommitMessageAndCommit.title%",
311311
"category": "Code Web Chat"
312312
},
313+
{
314+
"command": "codeWebChat.copyEditFormatInstructions",
315+
"title": "Copy Edit Format Instructions",
316+
"icon": "$(copy)",
317+
"category": "Code Web Chat"
318+
},
313319
{
314320
"command": "codeWebChat.setRanges",
315321
"title": "%codeWebChat.setRanges.title%",
@@ -512,6 +518,9 @@
512518
"command": "codeWebChat.copyCommitMessagePrompt",
513519
"when": "false"
514520
},
521+
{
522+
"command": "codeWebChat.copyEditFormatInstructions"
523+
},
515524
{
516525
"command": "codeWebChat.searchFilesForContextFromDirectory",
517526
"when": "false"
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import * as vscode from 'vscode'
2+
import {
3+
EDIT_FORMAT_INSTRUCTIONS_BEFORE_AFTER,
4+
EDIT_FORMAT_INSTRUCTIONS_DIFF,
5+
EDIT_FORMAT_INSTRUCTIONS_TRUNCATED,
6+
EDIT_FORMAT_INSTRUCTIONS_WHOLE
7+
} from '../constants/edit-format-instructions'
8+
9+
export const copy_edit_format_instructions_command = () => {
10+
return vscode.commands.registerCommand(
11+
'codeWebChat.copyEditFormatInstructions',
12+
async () => {
13+
const config = vscode.workspace.getConfiguration('codeWebChat')
14+
15+
const items: vscode.QuickPickItem[] = [
16+
{ label: 'Whole', description: 'Print entire files' },
17+
{ label: 'Truncated', description: 'Truncate unchanged parts' },
18+
{
19+
label: 'Before and After',
20+
description: 'Git-style merge conflict markers'
21+
},
22+
{ label: 'Diff', description: 'Unified diffs' }
23+
]
24+
25+
const selected = await vscode.window.showQuickPick(items, {
26+
title: 'Copy Edit Format Instructions',
27+
placeHolder: 'Select edit format'
28+
})
29+
30+
if (!selected) {
31+
return
32+
}
33+
34+
let instructions = ''
35+
switch (selected.label) {
36+
case 'Whole':
37+
instructions =
38+
config.get<string>('editFormatInstructionsWhole') ||
39+
EDIT_FORMAT_INSTRUCTIONS_WHOLE
40+
break
41+
case 'Truncated':
42+
instructions =
43+
config.get<string>('editFormatInstructionsTruncated') ||
44+
EDIT_FORMAT_INSTRUCTIONS_TRUNCATED
45+
break
46+
case 'Diff':
47+
instructions =
48+
config.get<string>('editFormatInstructionsDiff') ||
49+
EDIT_FORMAT_INSTRUCTIONS_DIFF
50+
break
51+
case 'Before/After':
52+
instructions =
53+
config.get<string>('editFormatInstructionsBeforeAfter') ||
54+
EDIT_FORMAT_INSTRUCTIONS_BEFORE_AFTER
55+
break
56+
}
57+
58+
const xml = `<system>\n${instructions}\n</system>`
59+
await vscode.env.clipboard.writeText(xml)
60+
61+
vscode.window.showInformationMessage(
62+
'Edit format instructions copied to clipboard'
63+
)
64+
}
65+
)
66+
}

apps/editor/src/commands/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ export * from './check-referencing-files-for-context-command'
2222
export * from './check-definition-file-for-context-command'
2323
export * from './find-relevant-files-command'
2424
export * from './select-imported-files-command'
25+
export * from './copy-edit-format-instructions-command'

apps/editor/src/extension.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ import {
3535
search_files_for_context_commands,
3636
check_referencing_files_for_context_command,
3737
check_definition_file_for_context_command,
38-
find_relevant_files_command
38+
find_relevant_files_command,
39+
copy_edit_format_instructions_command
3940
} from './commands'
4041
import { setup_git_discard_file_watcher } from './services/git-discard-file-watcher'
4142
import { select_imported_files_command } from './commands/select-imported-files-command'
@@ -136,6 +137,7 @@ export const activate = async (context: vscode.ExtensionContext) => {
136137
duplicate_workspace_command(workspace_provider, context),
137138
check_referencing_files_for_context_command(workspace_provider),
138139
...search_files_for_context_commands(workspace_provider, context),
140+
copy_edit_format_instructions_command(),
139141
find_relevant_files_command(workspace_provider, context),
140142
check_definition_file_for_context_command(workspace_provider),
141143
open_url_command({

0 commit comments

Comments
 (0)