Skip to content

Commit 0895b39

Browse files
committed
Move prompt symbol simplification to commit message details storage and handle non-breaking spaces
- prompts saved to commit-message-details.json should be already simplified - suggest if `apps/editor/src/commands/generate-commit-message-command/actions/run-generate-action.ts` should not use simplify_prompt_symbols if it is alerady used by `apps/editor/src/utils/commit-message-details.ts` ├── apps │ └── editor │ └── src │ ├── commands │ │ ├── apply-response-command │ │ │ └── utils │ │ │ └── preview-handler.ts │ │ ├── code-at-cursor-command │ │ │ └── code-at-cursor-commands.ts │ │ └── generate-commit-message-command │ │ └── actions │ │ └── run-generate-action.ts │ ├── features │ │ └── checkpoints │ │ └── actions │ │ └── restore-checkpoint.ts │ ├── services │ │ └── git-discard-file-watcher.ts │ └── utils │ └── commit-message-details.ts └── packages ├── shared │ └── src │ └── utils │ └── simplify-prompt-symbols │ ├── simplify-prompt-symbols.spec.ts │ └── simplify-prompt-symbols.ts └── ui └── src └── components └── editor └── prompt ├── ResponsePreview │ └── ResponsePreview.tsx └── Responses └── Responses.tsx
1 parent 2180dba commit 0895b39

4 files changed

Lines changed: 20 additions & 13 deletions

File tree

‎apps/editor/src/commands/generate-commit-message-command/actions/run-generate-action.ts‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { MAX_PROMPT_CHARS_IN_COMMIT_MESSAGE } from '@/constants/values'
1111
import { PromptViewProvider } from '@/views/prompt/backend/prompt-view-provider'
1212
import { WorkspaceProvider } from '@/context/providers/workspace/workspace-provider'
1313
import { create_checkpoint } from '@/features/checkpoints/actions'
14-
import { simplify_prompt_symbols } from '@shared/utils/simplify-prompt-symbols'
1514
import { AsciiTree } from '../../../utils/ascii-tree'
1615
import { LAST_ATTACH_ASCII_TREE_STATE_KEY } from '@/constants/state-keys'
1716
import { get_prompt_data } from './get-prompt-data'
@@ -330,7 +329,7 @@ export const run_generate_action = async (params: {
330329
vscode.QuickPickItem & { prompt: (typeof relevant_prompts)[0] }
331330
>()
332331
quick_pick.items = relevant_prompts.map((p) => ({
333-
label: simplify_prompt_symbols({ prompt: p.prompt }),
332+
label: p.prompt,
334333
prompt: p
335334
}))
336335
quick_pick.selectedItems = quick_pick.items.filter((i) =>
@@ -421,10 +420,7 @@ export const run_generate_action = async (params: {
421420
selected_prompts.length > 0
422421
? '\n\n' +
423422
selected_prompts
424-
.map(
425-
(p) =>
426-
`- ${truncate_prompt(simplify_prompt_symbols({ prompt: p.prompt }))}`
427-
)
423+
.map((p) => `- ${truncate_prompt(p.prompt)}`)
428424
.join('\n')
429425
: ''
430426

@@ -452,10 +448,7 @@ export const run_generate_action = async (params: {
452448
selected_prompts.length > 0
453449
? '\n\n' +
454450
selected_prompts
455-
.map(
456-
(p) =>
457-
`- ${truncate_prompt(simplify_prompt_symbols({ prompt: p.prompt }))}`
458-
)
451+
.map((p) => `- ${truncate_prompt(p.prompt)}`)
459452
.join('\n')
460453
: ''
461454
repository.inputBox.value =

‎apps/editor/src/utils/commit-message-details.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as vscode from 'vscode'
22
import * as fs from 'fs'
33
import * as path from 'path'
4+
import { simplify_prompt_symbols } from '@shared/utils/simplify-prompt-symbols'
45

56
export namespace CommitMessageDetails {
67
const COMMIT_MESSAGE_DETAILS_FILENAME = 'commit-message-details.json'
@@ -76,8 +77,10 @@ export namespace CommitMessageDetails {
7677
all_prompts[params.workspace_root] = []
7778
}
7879

80+
const simplified_prompt = simplify_prompt_symbols({ prompt: params.prompt })
81+
7982
const existing = all_prompts[params.workspace_root].find(
80-
(p) => p.prompt == params.prompt
83+
(p) => p.prompt == simplified_prompt
8184
)
8285

8386
if (existing) {
@@ -88,7 +91,7 @@ export namespace CommitMessageDetails {
8891
} else {
8992
const new_prompt: Prompt = {
9093
files: params.files,
91-
prompt: params.prompt,
94+
prompt: simplified_prompt,
9295
selected_files: params.selected_files
9396
}
9497
all_prompts[params.workspace_root].push(new_prompt)
@@ -106,11 +109,12 @@ export namespace CommitMessageDetails {
106109
}) => {
107110
const all_prompts = load_all(params.extension_context)
108111
let changed = false
112+
const simplified_prompt = simplify_prompt_symbols({ prompt: params.prompt })
109113

110114
for (const root in all_prompts) {
111115
const initial_count = all_prompts[root].length
112116
all_prompts[root] = all_prompts[root].filter(
113-
(p) => p.prompt != params.prompt
117+
(p) => p.prompt != simplified_prompt
114118
)
115119

116120
if (all_prompts[root].length != initial_count) {

‎packages/shared/src/utils/simplify-prompt-symbols/simplify-prompt-symbols.spec.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,12 @@ describe('simplify_prompt_symbols', () => {
7171
'[Selection] and [Fragment] with [Changes]'
7272
)
7373
})
74+
75+
it('should replace non-breaking spaces with regular spaces', () => {
76+
const prompt =
77+
'remove semi key\u00a0<fragment path="a.ts">code</fragment>\u00a0#Commit(repo:hash "message")'
78+
expect(simplify_prompt_symbols({ prompt })).toBe(
79+
'remove semi key [Fragment] [Commit]'
80+
)
81+
})
7482
})

‎packages/shared/src/utils/simplify-prompt-symbols/simplify-prompt-symbols.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,7 @@ export const simplify_prompt_symbols = (params: { prompt: string }): string => {
2525
)
2626
simplified = simplified.replace(/#Website\([^)]+\)/g, '[Website]')
2727

28+
simplified = simplified.replace(/\u00a0/g, ' ')
29+
2830
return simplified
2931
}

0 commit comments

Comments
 (0)