Skip to content

Commit b09e367

Browse files
committed
Add CommitDiff symbol type to reference commit diffs without commit messages
- revert all those lint fixes [Changes] - 'commit' symbol has 2 variants. add third: 'commit diff' - where it only shows diffs [Accuracy boost] - missing translations in 'commit symbol' ├── apps │ └── editor │ └── src │ ├── commands │ │ ├── apply-response-command │ │ │ ├── response-processor │ │ │ │ ├── handlers │ │ │ │ │ ├── patch-repair-handler.ts │ │ │ │ │ └── search-replace-handler.ts │ │ │ │ └── response-processor.ts │ │ │ └── utils │ │ │ ├── file-operations │ │ │ │ ├── prepare-rename-operation.ts │ │ │ │ └── read-rename-source-file.ts │ │ │ └── preview │ │ │ ├── build-history-files.ts │ │ │ ├── file-preparer.ts │ │ │ └── vscode-ui.ts │ │ ├── copy-merge-commit-details-command.ts │ │ ├── generate-commit-message-commands │ │ │ └── utils │ │ │ └── build-commit-message-prompt.ts │ │ ├── new-folder-command.ts │ │ ├── search-files-commands │ │ │ └── utils │ │ │ └── get-target-folder-path.ts │ │ ├── select-files-of-commit-command.ts │ │ └── set-ranges-command.ts │ ├── features │ │ └── search-files │ │ └── utils │ │ └── analyze-files.ts │ ├── i18n │ │ ├── index.ts │ │ └── translations │ │ └── views │ │ ├── index.ts │ │ └── shared │ │ ├── index.ts │ │ └── utils │ │ ├── hash-sign-quick-pick.ts │ │ └── index.ts │ ├── services │ │ └── websocket-manager.ts │ ├── utils │ │ ├── agentic-cli-invocation │ │ │ ├── invoke-agentic-cli.ts │ │ │ └── utils │ │ │ └── check-command-exists.ts │ │ ├── git-repository-utils.ts │ │ └── path-sanitizer.ts │ └── views │ ├── prompt │ │ ├── backend │ │ │ ├── message-handlers │ │ │ │ ├── handle-paste-url.ts │ │ │ │ ├── handle-preview-commit-symbol.ts │ │ │ │ ├── handle-preview-generated-code.ts │ │ │ │ └── utils │ │ │ │ └── build-cli-prompt.ts │ │ │ ├── prompt-view-provider.ts │ │ │ └── utils │ │ │ ├── persistent-text-storage.ts │ │ │ ├── preview-text-in-temp-file.ts │ │ │ ├── symbols │ │ │ │ ├── fragment │ │ │ │ │ └── replace-fragment-symbol.ts │ │ │ │ ├── git │ │ │ │ │ └── replace-git-symbols.ts │ │ │ │ ├── image │ │ │ │ │ └── replace-image-symbol.ts │ │ │ │ ├── pasted-text │ │ │ │ │ └── replace-pasted-text-symbol.ts │ │ │ │ ├── replace-symbols.ts │ │ │ │ └── website │ │ │ │ └── replace-website-symbol.ts │ │ │ └── website-fetcher.ts │ │ ├── frontend │ │ │ ├── Main │ │ │ │ ├── Main.tsx │ │ │ │ └── MainView │ │ │ │ └── MainView.tsx │ │ │ ├── Prompt.tsx │ │ │ └── hooks │ │ │ └── use-prompt │ │ │ └── use-prompt.ts │ │ └── types │ │ └── messages.ts │ ├── settings │ │ └── backend │ │ └── message-handlers │ │ ├── add-provider │ │ │ └── pick-extended-provider.ts │ │ ├── handle-open-allow-patterns-settings.ts │ │ └── handle-open-ignore-patterns-settings.ts │ └── shared │ └── utils │ └── hash-sign-quick-pick │ ├── hash-sign-quick-pick.ts │ ├── index.ts │ └── symbols │ ├── changes-symbol.ts │ ├── commit-symbol.ts │ ├── index.ts │ └── saved-context-symbol.ts └── packages ├── shared │ └── src │ └── utils │ └── simplify-prompt-symbols │ ├── simplify-prompt-symbols.spec.ts │ └── simplify-prompt-symbols.ts └── ui └── src └── components └── editor └── common └── prompts ├── PromptField │ ├── PromptField.tsx │ └── hooks │ └── use-handlers │ ├── handle-input-click.ts │ └── utils.ts └── shared └── symbols ├── get-highlighted-text.tsx ├── position-mapping.ts ├── prompt-symbols.module.scss ├── reconstruct-raw-value.ts └── use-symbol-deletion.ts
1 parent 4d9917d commit b09e367

19 files changed

Lines changed: 267 additions & 39 deletions

File tree

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

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,169 @@ export const translations = {
5757
hu: 'Nem sikerült lekérni a git commitokat. Kérjük, ellenőrizze, hogy a git telepítve van-e.',
5858
bg: 'Неуспешно получаване на git къмити. Моля, уверете се, че git е инсталиран.'
5959
},
60+
'views.shared.utils.hash-sign-quick-pick.commit-symbol.select-repository': {
61+
en: 'Select a repository',
62+
pl: 'Wybierz repozytorium',
63+
'zh-cn': '选择一个存储库',
64+
ja: 'リポジトリを選択',
65+
'zh-tw': '選擇一個儲存庫',
66+
de: 'Wählen Sie ein Repository aus',
67+
es: 'Seleccione un repositorio',
68+
fr: 'Sélectionner un dépôt',
69+
'pt-br': 'Selecione um repositório',
70+
ru: 'Выберите репозиторий',
71+
ko: '저장소 선택',
72+
it: 'Seleziona un repository',
73+
tr: 'Bir depo seçin',
74+
cs: 'Vyberte repozitář',
75+
hu: 'Válasszon egy tárolót',
76+
bg: 'Изберете хранилище'
77+
},
78+
'views.shared.utils.hash-sign-quick-pick.commit-symbol.repositories': {
79+
en: 'Repositories',
80+
pl: 'Repozytoria',
81+
'zh-cn': '存储库',
82+
ja: 'リポジトリ',
83+
'zh-tw': '儲存庫',
84+
de: 'Repositories',
85+
es: 'Repositorios',
86+
fr: 'Dépôts',
87+
'pt-br': 'Repositórios',
88+
ru: 'Репозитории',
89+
ko: '저장소',
90+
it: 'Repository',
91+
tr: 'Depolar',
92+
cs: 'Repozitáře',
93+
hu: 'Tárolók',
94+
bg: 'Хранилища'
95+
},
96+
'views.shared.utils.hash-sign-quick-pick.commit-symbol.select-commit': {
97+
en: 'Select a commit to reference',
98+
pl: 'Wybierz commit do odniesienia',
99+
'zh-cn': '选择要引用的提交',
100+
ja: '参照するコミットを選択',
101+
'zh-tw': '選擇要引用的提交',
102+
de: 'Wählen Sie einen Commit als Referenz aus',
103+
es: 'Seleccione un commit para referenciar',
104+
fr: 'Sélectionnez un commit à référencer',
105+
'pt-br': 'Selecione um commit para referenciar',
106+
ru: 'Выберите коммит для ссылки',
107+
ko: '참조할 커밋 선택',
108+
it: 'Seleziona un commit da referenziare',
109+
tr: 'Başvurulacak bir işleme seçin',
110+
cs: 'Vyberte odevzdání k odkazu',
111+
hu: 'Válasszon ki egy hivatkozandó commitot',
112+
bg: 'Изберете къмит за справка'
113+
},
114+
'views.shared.utils.hash-sign-quick-pick.commit-symbol.commits': {
115+
en: 'Commits',
116+
pl: 'Commity',
117+
'zh-cn': '提交',
118+
ja: 'コミット',
119+
'zh-tw': '提交',
120+
de: 'Commits',
121+
es: 'Commits',
122+
fr: 'Commits',
123+
'pt-br': 'Commits',
124+
ru: 'Коммиты',
125+
ko: '커밋',
126+
it: 'Commit',
127+
tr: 'İşlemeler',
128+
cs: 'Odevzdání',
129+
hu: 'Commitok',
130+
bg: 'Къмити'
131+
},
132+
'views.shared.utils.hash-sign-quick-pick.commit-symbol.diff-with-message': {
133+
en: 'Diff with commit message',
134+
pl: 'Różnica z wiadomością commita',
135+
'zh-cn': '包含提交消息的差异',
136+
ja: 'コミットメッセージ付きの差分',
137+
'zh-tw': '包含提交訊息的差異',
138+
de: 'Diff mit Commit-Nachricht',
139+
es: 'Diff con mensaje de commit',
140+
fr: 'Différence avec le message de commit',
141+
'pt-br': 'Diff com mensagem de commit',
142+
ru: 'Различия с сообщением коммита',
143+
ko: '커밋 메시지가 포함된 차이점',
144+
it: 'Diff con messaggio di commit',
145+
tr: 'İşleme mesajı ile fark',
146+
cs: 'Rozdíl s popisem odevzdání',
147+
hu: 'Különbség commit üzenettel',
148+
bg: 'Разлика със съобщение за къмит'
149+
},
150+
'views.shared.utils.hash-sign-quick-pick.commit-symbol.message-only': {
151+
en: 'Commit message only',
152+
pl: 'Tylko wiadomość commita',
153+
'zh-cn': '仅提交消息',
154+
ja: 'コミットメッセージのみ',
155+
'zh-tw': '僅提交訊息',
156+
de: 'Nur Commit-Nachricht',
157+
es: 'Solo mensaje de commit',
158+
fr: 'Message de commit uniquement',
159+
'pt-br': 'Apenas mensagem de commit',
160+
ru: 'Только сообщение коммита',
161+
ko: '커밋 메시지만',
162+
it: 'Solo messaggio di commit',
163+
tr: 'Sadece işleme mesajı',
164+
cs: 'Pouze popis odevzdání',
165+
hu: 'Csak commit üzenet',
166+
bg: 'Само съобщение за къмит'
167+
},
168+
'views.shared.utils.hash-sign-quick-pick.commit-symbol.diff-only': {
169+
en: 'Diff only',
170+
pl: 'Tylko różnica',
171+
'zh-cn': '仅差异',
172+
ja: '差分のみ',
173+
'zh-tw': '僅差異',
174+
de: 'Nur Diff',
175+
es: 'Solo diff',
176+
fr: 'Différence uniquement',
177+
'pt-br': 'Apenas diff',
178+
ru: 'Только различия',
179+
ko: '차이점만',
180+
it: 'Solo diff',
181+
tr: 'Sadece fark',
182+
cs: 'Pouze rozdíl',
183+
hu: 'Csak különbség',
184+
bg: 'Само разлика'
185+
},
186+
'views.shared.utils.hash-sign-quick-pick.commit-symbol.select-what-to-include':
187+
{
188+
en: 'Select what to include',
189+
pl: 'Wybierz, co chcesz dołączyć',
190+
'zh-cn': '选择要包含的内容',
191+
ja: '含めるものを選択',
192+
'zh-tw': '選擇要包含的內容',
193+
de: 'Wählen Sie aus, was einbezogen werden soll',
194+
es: 'Seleccione qué incluir',
195+
fr: 'Sélectionnez ce à inclure',
196+
'pt-br': 'Selecione o que incluir',
197+
ru: 'Выберите, что включить',
198+
ko: '포함할 항목 선택',
199+
it: 'Seleziona cosa includere',
200+
tr: 'Neyin dahil edileceğini seçin',
201+
cs: 'Vyberte, co zahrnout',
202+
hu: 'Válassza ki, mit szeretne belefoglalni',
203+
bg: 'Изберете какво да включите'
204+
},
205+
'views.shared.utils.hash-sign-quick-pick.commit-symbol.options': {
206+
en: 'Commit Reference Options',
207+
pl: 'Opcje odniesienia do commita',
208+
'zh-cn': '提交引用选项',
209+
ja: 'コミット参照オプション',
210+
'zh-tw': '提交引用選項',
211+
de: 'Commit-Referenzoptionen',
212+
es: 'Opciones de referencia de commit',
213+
fr: 'Options de référence de commit',
214+
'pt-br': 'Opções de referência de commit',
215+
ru: 'Опции ссылки на коммит',
216+
ko: '커밋 참조 옵션',
217+
it: 'Opzioni di riferimento commit',
218+
tr: 'İşleme Başvurusu Seçenekleri',
219+
cs: 'Možnosti odkazu na odevzdání',
220+
hu: 'Commit hivatkozási lehetőségek',
221+
bg: 'Опции за справка за къмит'
222+
},
60223
'views.shared.utils.hash-sign-quick-pick.saved-context-symbol.failed-to-load':
61224
{
62225
en: 'Failed to load saved contexts. Please check your configuration.',

‎apps/editor/src/views/prompt/backend/message-handlers/handle-preview-commit-symbol.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const handle_preview_commit_symbol = async (message: {
66
repo_name: string
77
commit_hash: string
88
commit_message?: string
9-
type: 'Commit' | 'CommitMessage'
9+
type: 'Commit' | 'CommitMessage' | 'CommitDiff'
1010
}) => {
1111
try {
1212
const message_escaped = message.commit_message

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ export const replace_commit_symbol = async (params: {
583583
symbols_cache?: SymbolCacheManager
584584
}): Promise<{ instructions: string[]; commit_definitions: string }> => {
585585
const regex =
586-
/#(Commit|CommitMessage)\(([^:]+):([a-fA-F0-9]+)\s*(?:"((?:[^"\\]|\\.)*)")?\)/g
586+
/#(Commit|CommitMessage|CommitDiff)\(([^:]+):([a-fA-F0-9]+)\s*(?:"((?:[^"\\]|\\.)*)")?\)/g
587587

588588
const result_instructions = [...params.instructions]
589589
let commit_definitions = ''
@@ -670,7 +670,7 @@ export const replace_commit_symbol = async (params: {
670670
.replace(/[^a-z0-9]+/g, '-')
671671
.replace(/^-|-$/g, '')
672672

673-
if (symbol_type === 'Commit') {
673+
if (symbol_type === 'Commit' || symbol_type === 'CommitDiff') {
674674
const diff = execFileSync('git', ['show', commit_hash], {
675675
cwd: target_folder.uri.fsPath,
676676
encoding: 'utf-8'
@@ -697,15 +697,15 @@ export const replace_commit_symbol = async (params: {
697697
diff,
698698
commit_hash,
699699
path_prefix: workspace_folders.length > 1 ? folder_name : undefined,
700-
commit_message: commit_message_body
700+
commit_message: symbol_type === 'CommitDiff' ? undefined : commit_message_body
701701
})
702702
} else {
703703
if (commit_message_body) {
704704
replacement_text = `---\n\n${commit_message_body}\n\n---\n\n`
705705
}
706706
}
707707

708-
if (symbol_type === 'Commit') {
708+
if (symbol_type === 'Commit' || symbol_type === 'CommitDiff') {
709709
const replacement = ` [${title_text}](#${link_hash}) `
710710
if (params.symbols_cache) {
711711
params.symbols_cache.set(full_match, replacement, replacement_text)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export const replace_symbols = async (params: {
5858

5959
if (
6060
processed_instructions.some(
61-
(i) => i.includes('#Commit(') || i.includes('#CommitMessage(')
61+
(i) => i.includes('#Commit(') || i.includes('#CommitMessage(') || i.includes('#CommitDiff(')
6262
)
6363
) {
6464
const result = await replace_commit_symbol({

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ type Props = {
8585
on_commit_click?: (
8686
repo_name: string,
8787
commit_hash: string,
88-
type: 'Commit' | 'CommitMessage',
88+
type: 'Commit' | 'CommitMessage' | 'CommitDiff',
8989
commit_message?: string
9090
) => void
9191
on_skill_click?: (agent: string, repo: string, skill_name: string) => void

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ type Props = {
142142
on_commit_click?: (
143143
repo_name: string,
144144
commit_hash: string,
145-
type: 'Commit' | 'CommitMessage',
145+
type: 'Commit' | 'CommitMessage' | 'CommitDiff',
146146
commit_message?: string
147147
) => void
148148
on_skill_click?: (agent: string, repo: string, skill_name: string) => void

‎apps/editor/src/views/prompt/frontend/hooks/use-prompt/use-prompt.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export const use_prompt = (vscode: any) => {
117117
const handle_commit_click = (
118118
repo_name: string,
119119
commit_hash: string,
120-
type: 'Commit' | 'CommitMessage',
120+
type: 'Commit' | 'CommitMessage' | 'CommitDiff',
121121
commit_message?: string
122122
) => {
123123
post_message(vscode, {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ export interface PreviewCommitSymbolMessage extends BaseMessage {
591591
repo_name: string
592592
commit_hash: string
593593
commit_message?: string
594-
type: 'Commit' | 'CommitMessage'
594+
type: 'Commit' | 'CommitMessage' | 'CommitDiff'
595595
}
596596

597597
export interface PreviewSkillSymbolMessage extends BaseMessage {

‎apps/editor/src/views/shared/utils/hash-sign-quick-pick/symbols/commit-symbol.ts‎

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@ export const handle_commit_item = async (
5454
}))
5555
const quick_pick = vscode.window.createQuickPick()
5656
quick_pick.items = folder_items
57-
quick_pick.placeholder = 'Select a repository'
58-
quick_pick.title = 'Repositories'
57+
quick_pick.placeholder = t(
58+
'views.shared.utils.hash-sign-quick-pick.commit-symbol.select-repository'
59+
)
60+
quick_pick.title = t(
61+
'views.shared.utils.hash-sign-quick-pick.commit-symbol.repositories'
62+
)
5963
quick_pick.buttons = [vscode.QuickInputButtons.Back]
6064

6165
const last_repo = extension_context.workspaceState.get<string>(
@@ -155,8 +159,12 @@ export const handle_commit_item = async (
155159
while (true) {
156160
const quick_pick = vscode.window.createQuickPick()
157161
quick_pick.items = commit_items
158-
quick_pick.placeholder = 'Select a commit to reference'
159-
quick_pick.title = 'Commits'
162+
quick_pick.placeholder = t(
163+
'views.shared.utils.hash-sign-quick-pick.commit-symbol.select-commit'
164+
)
165+
quick_pick.title = t(
166+
'views.shared.utils.hash-sign-quick-pick.commit-symbol.commits'
167+
)
160168
quick_pick.buttons = [vscode.QuickInputButtons.Back]
161169
quick_pick.matchOnDetail = true
162170

@@ -211,6 +219,7 @@ export const handle_commit_item = async (
211219
last_selected_commit = selected_commit
212220
const commit_hash = selected_commit.label
213221
let diff_token_count = 0
222+
let diff_only_token_count = 0
214223
let msg_token_count = 0
215224

216225
try {
@@ -236,38 +245,69 @@ export const handle_commit_item = async (
236245
encoding: 'utf-8'
237246
}).toString()
238247

239-
const replacement_text = build_commit_changes_markdown({
248+
const replacement_text_with_msg = build_commit_changes_markdown({
240249
diff,
241250
commit_hash,
242251
path_prefix:
243252
workspace_folders.length > 1 ? selected_folder.name : undefined,
244253
commit_message
245254
})
246-
diff_token_count = Math.ceil(replacement_text.length / 4)
255+
diff_token_count = Math.ceil(replacement_text_with_msg.length / 4)
256+
257+
const replacement_text_only_diff = build_commit_changes_markdown({
258+
diff,
259+
commit_hash,
260+
path_prefix:
261+
workspace_folders.length > 1 ? selected_folder.name : undefined
262+
})
263+
diff_only_token_count = Math.ceil(
264+
replacement_text_only_diff.length / 4
265+
)
247266
} catch {
248267
// ignore
249268
}
250269

251270
const action_quick_pick = vscode.window.createQuickPick()
271+
const diff_with_message_label = t(
272+
'views.shared.utils.hash-sign-quick-pick.commit-symbol.diff-with-message'
273+
)
274+
const message_only_label = t(
275+
'views.shared.utils.hash-sign-quick-pick.commit-symbol.message-only'
276+
)
277+
const diff_only_label = t(
278+
'views.shared.utils.hash-sign-quick-pick.commit-symbol.diff-only'
279+
)
280+
252281
const action_items = [
253282
{
254-
label: 'Diff with commit message',
283+
label: diff_with_message_label,
255284
description:
256285
diff_token_count > 0
257286
? display_token_count(diff_token_count)
258287
: undefined
259288
},
260289
{
261-
label: 'Commit message only',
290+
label: message_only_label,
262291
description:
263292
msg_token_count > 0
264293
? display_token_count(msg_token_count)
265294
: undefined
295+
},
296+
{
297+
label: diff_only_label,
298+
description:
299+
diff_only_token_count > 0
300+
? display_token_count(diff_only_token_count)
301+
: undefined
266302
}
267303
]
268304
action_quick_pick.items = action_items
269-
action_quick_pick.placeholder = 'Select what to include'
270-
action_quick_pick.title = 'Commit Reference Options'
305+
action_quick_pick.placeholder = t(
306+
'views.shared.utils.hash-sign-quick-pick.commit-symbol.select-what-to-include'
307+
)
308+
action_quick_pick.title = t(
309+
'views.shared.utils.hash-sign-quick-pick.commit-symbol.options'
310+
)
271311
action_quick_pick.buttons = [vscode.QuickInputButtons.Back]
272312

273313
const last_action = extension_context.workspaceState.get<string>(
@@ -319,9 +359,11 @@ export const handle_commit_item = async (
319359
)
320360

321361
const symbol =
322-
selected_action.label === 'Commit message only'
362+
selected_action.label === message_only_label
323363
? 'CommitMessage'
324-
: 'Commit'
364+
: selected_action.label === diff_only_label
365+
? 'CommitDiff'
366+
: 'Commit'
325367
const message = (selected_commit.detail || '').replace(/"/g, '\\"')
326368

327369
on_insert(

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ describe('simplify_prompt_symbols', () => {
3333
expect(simplify_prompt_symbols({ prompt })).toBe('Check [Commit]')
3434
})
3535

36+
it('should replace #CommitDiff', () => {
37+
const prompt = 'Check #CommitDiff(repo:hash "message")'
38+
expect(simplify_prompt_symbols({ prompt })).toBe('Check [Commit]')
39+
})
40+
3641
it('should replace #Skill', () => {
3742
const prompt = 'Run #Skill(agent:repo:skill)'
3843
expect(simplify_prompt_symbols({ prompt })).toBe('Run [Skill]')

0 commit comments

Comments
 (0)