Skip to content

Commit b712054

Browse files
committed
Refactor commit message generation flow and tree attachment logic for non-commit actions
- when prompted to generate commit message with cwc, should ask which prompts to include or whether to attach ascii tree - scenario: all files for the ascii tree are touched by commit. expected behavior: ascii tree is skipped ├── apps │ └── editor │ ├── package.nls.json │ └── src │ ├── commands │ │ └── generate-commit-message-command │ │ └── generate-commit-message-command.ts │ ├── constants │ │ ├── state-keys.ts │ │ └── values.ts │ ├── context │ │ └── providers │ │ └── workspace │ │ └── workspace-provider.ts │ ├── extension.ts │ ├── features │ │ ├── checkpoints │ │ │ └── actions │ │ │ ├── create-checkpoint.ts │ │ │ └── index.ts │ │ └── commit-messages │ │ ├── index.ts │ │ └── utils │ │ ├── build-commit-message-prompt.ts │ │ ├── generate-commit-message-with-api.ts │ │ └── get-commit-message-config.ts │ ├── i18n │ │ └── index.ts │ ├── utils │ │ ├── ascii-tree │ │ │ ├── ascii-tree.ts │ │ │ └── index.ts │ │ ├── display-token-count.ts │ │ ├── git-repository-utils.ts │ │ └── prompts-for-commit-messages-utils.ts │ └── views │ └── prompt │ └── backend │ └── prompt-view-provider.ts └── packages └── shared └── src └── utils └── simplify-prompt-symbols ├── index.ts └── simplify-prompt-symbols.ts
1 parent 1b94263 commit b712054

1 file changed

Lines changed: 26 additions & 5 deletions

File tree

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

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,17 @@ export const generate_commit_message_command = (
209209
return ''
210210
}
211211

212+
const all_files_touched = selected_files_to_attach.every((f) => {
213+
const rel_path = vscode.workspace
214+
.asRelativePath(f)
215+
.replace(/\\/g, '/')
216+
return staged_files.includes(rel_path) || staged_files.includes(f)
217+
})
218+
219+
if (all_files_touched) {
220+
return ''
221+
}
222+
212223
const attach_tree_setting = vscode.workspace
213224
.getConfiguration('codeWebChat')
214225
.get<string>('attachAsciiTreeOfContext', 'ask')
@@ -302,7 +313,11 @@ export const generate_commit_message_command = (
302313
let tree_text = ''
303314

304315
let step: 'edit_message' | 'select_prompts' | 'attach_tree' | 'finish' =
305-
params.should_commit ? 'edit_message' : 'attach_tree'
316+
params.should_commit
317+
? 'edit_message'
318+
: relevant_prompts.length > 0
319+
? 'select_prompts'
320+
: 'attach_tree'
306321
let is_cancelled = false
307322
let go_back = false
308323

@@ -433,7 +448,12 @@ export const generate_commit_message_command = (
433448
})
434449

435450
if (picked == 'back') {
436-
step = 'edit_message'
451+
if (params.should_commit) {
452+
step = 'edit_message'
453+
} else {
454+
go_back = true
455+
break
456+
}
437457
} else if (picked === undefined) {
438458
is_cancelled = true
439459
break
@@ -444,9 +464,10 @@ export const generate_commit_message_command = (
444464
} else if (step == 'attach_tree') {
445465
const result = await get_tree_text_if_applicable(selected_prompts)
446466
if (result == 'back') {
447-
if (params.should_commit) {
448-
step =
449-
relevant_prompts.length > 0 ? 'select_prompts' : 'edit_message'
467+
if (relevant_prompts.length > 0) {
468+
step = 'select_prompts'
469+
} else if (params.should_commit) {
470+
step = 'edit_message'
450471
} else {
451472
go_back = true
452473
break

0 commit comments

Comments
 (0)