Skip to content

Commit 3ac84de

Browse files
committed
Remove silent flag from checkpoints and parse staged files directly from diff output for commit message generation
- it's been reported that suggested prompts used to edit commited files are incorrect - current branch should not be filtered out as we might want to see uncommited changes
1 parent 1ba4461 commit 3ac84de

3 files changed

Lines changed: 38 additions & 12 deletions

File tree

‎apps/editor/src/commands/apply-chat-response-command/apply-chat-response-command.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,7 @@ export const apply_chat_response_command = (params: {
211211
context: params.context,
212212
panel_provider: params.panel_provider,
213213
trigger: 'before-response-previewed',
214-
description: args?.raw_instructions,
215-
silent: true
214+
description: args?.raw_instructions
216215
})
217216
}
218217

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

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as vscode from 'vscode'
2-
import * as path from 'path'
32
import {
43
prepare_staged_changes,
54
GitRepository,
@@ -52,11 +51,44 @@ export const generate_commit_message_command = (
5251
diff,
5352
params.repository
5453
)
54+
55+
const diff_file_paths: string[] = []
56+
const file_diffs = diff.split(/^diff --git /m).filter((d) => d.trim() != '')
57+
for (const file_diff_content of file_diffs) {
58+
const full_file_diff = 'diff --git ' + file_diff_content
59+
const lines = full_file_diff.split('\n')
60+
const old_path_line = lines.find((l) => l.startsWith('--- a/'))
61+
const new_path_line = lines.find((l) => l.startsWith('+++ b/'))
62+
63+
const old_path = old_path_line
64+
? old_path_line.substring('--- a/'.length)
65+
: undefined
66+
const new_path = new_path_line
67+
? new_path_line.substring('+++ b/'.length)
68+
: undefined
69+
70+
let file_path: string | undefined
71+
if (new_path && new_path != '/dev/null') {
72+
file_path = new_path
73+
} else if (old_path && old_path != '/dev/null') {
74+
file_path = old_path
75+
} else {
76+
const match = lines[0]?.match(/^diff --git a\/(.*) b\/(.*)$/)
77+
if (match) {
78+
file_path = match[2]
79+
}
80+
}
81+
if (file_path && !diff_file_paths.includes(file_path)) {
82+
diff_file_paths.push(file_path)
83+
}
84+
}
85+
5586
return {
5687
repository: params.repository,
5788
was_empty_stage,
5889
message_prompt,
59-
is_single_change
90+
is_single_change,
91+
staged_files: diff_file_paths
6092
}
6193
}
6294

@@ -79,7 +111,7 @@ export const generate_commit_message_command = (
79111
selection_state
80112
})
81113
if (!data) return
82-
const { message_prompt, is_single_change } = data
114+
const { message_prompt, is_single_change, staged_files } = data
83115
let { was_empty_stage } = data
84116

85117
// token count for the prompt, used in the config UI
@@ -146,9 +178,6 @@ export const generate_commit_message_command = (
146178
const workspace_root = repository.rootUri.fsPath
147179
const all_prompts =
148180
PromptsForCommitMessagesUtils.load_all(context)[workspace_root] || []
149-
const staged_files = repository.state.indexChanges.map((change) =>
150-
path.relative(workspace_root, change.uri.fsPath).replace(/\\/g, '/')
151-
)
152181

153182
const select_prompts_setting = vscode.workspace
154183
.getConfiguration('codeWebChat')
@@ -286,8 +315,7 @@ export const generate_commit_message_command = (
286315
context,
287316
panel_provider,
288317
trigger: 'commit',
289-
description: subject_line,
290-
silent: true
318+
description: subject_line
291319
}).catch(() => {})
292320
} else if (was_empty_stage) {
293321
await vscode.commands.executeCommand('git.unstageAll', repository)

‎apps/editor/src/views/panel/backend/message-handlers/handle-hash-sign-quick-pick/symbols/changes-symbol.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ export const handle_changes_item = async (): Promise<
3838

3939
const branches = branches_output
4040
.split('\n')
41-
.filter((b) => !b.startsWith('* '))
42-
.map((b) => b.trim())
41+
.map((b) => b.replace(/^\*/, '').trim())
4342
.filter((b) => b.length > 0)
4443

4544
if (branches.length > 0) {

0 commit comments

Comments
 (0)