Skip to content

Commit fe80018

Browse files
committed
Include associated commit message prompts in the unstaged files quick pick
- when constructing intelligent search prompt with unstaged files for commit message - we want to include as part of showing diff: prompts used to edit said file - without any prelude '[Fragment]' └── apps └── editor └── src ├── commands │ ├── apply-response-command │ │ └── utils │ │ └── preview-handler.ts │ ├── code-at-cursor-command │ │ └── code-at-cursor-commands.ts │ ├── generate-commit-message-commands │ │ ├── actions │ │ │ ├── get-prompt-data.ts │ │ │ └── run-generate-action.ts │ │ ├── generate-commit-message-commands.ts │ │ ├── index.ts │ │ └── utils │ │ ├── build-commit-message-prompt.ts │ │ ├── generate-commit-message-with-api.ts │ │ ├── get-commit-message-config.ts │ │ └── strip-wrapping-quotes.ts │ └── history-command │ └── actions │ └── restore-checkpoint.ts ├── features │ └── search-files │ ├── index.ts │ └── utils │ ├── check-matches-condition.ts │ ├── create-search-regex.ts │ ├── prompt-for-config.ts │ ├── prompt-for-intelligent-search-results.ts │ ├── prompt-for-keywords-match-mode.ts │ ├── prompt-for-keywords-target.ts │ ├── prompt-for-search-mode.ts │ ├── prompt-for-search-results.ts │ ├── prompt-for-search-term.ts │ ├── prompt-for-shrink-mode.ts │ └── show-search-results-quick-pick.ts ├── services │ └── git-discard-file-watcher.ts ├── utils │ ├── commit-message-details.ts │ ├── git-repository-utils.ts │ └── prompt-builder.ts └── views └── prompt └── backend └── message-handlers └── handle-undo.ts
1 parent 60018ea commit fe80018

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

‎apps/editor/src/utils/git-repository-utils.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { display_token_count } from '@shared/utils/display-token-count'
1111
import { WorkspaceProvider } from '@/context/providers/workspace/workspace-provider'
1212
import { WebSocketManager } from '@/services/websocket-manager'
1313
import { search_files } from '@/features/search-files'
14+
import { CommitMessageDetails } from './commit-message-details'
15+
import { normalize_path } from './normalize-path'
1416

1517
export type GitRepository = {
1618
rootUri: vscode.Uri
@@ -235,12 +237,27 @@ export const prepare_staged_changes = async (params: {
235237
params.repository.state.workingTreeChanges[0].uri.fsPath
236238
]
237239
} else {
240+
let prompts_for_repo: CommitMessageDetails.Prompt[] = []
241+
if (params.extension_context) {
242+
const all_prompts = CommitMessageDetails.load_all(
243+
params.extension_context
244+
)
245+
prompts_for_repo = all_prompts[params.repository.rootUri.fsPath] || []
246+
}
247+
238248
const items = await Promise.all(
239249
params.repository.state.workingTreeChanges.map(async (change: any) => {
240250
const relative_path = path.relative(
241251
params.repository.rootUri.fsPath,
242252
change.uri.fsPath
243253
)
254+
const normalized_path = normalize_path(relative_path)
255+
const file_prompts = prompts_for_repo.filter(
256+
(p) =>
257+
p.prompt.trim() !== '' &&
258+
(p.files.includes(normalized_path) ||
259+
p.files.includes(change.uri.fsPath))
260+
)
244261
const dir_name = path.dirname(relative_path)
245262

246263
let status: 'created' | 'deleted' | 'renamed' | 'updated' = 'updated'
@@ -324,7 +341,15 @@ export const prepare_staged_changes = async (params: {
324341
: undefined
325342
})
326343

344+
let prompts_content = ''
345+
if (file_prompts.length > 0) {
346+
prompts_content = file_prompts
347+
.map((p) => `- ${p.prompt}`)
348+
.join('\n')
349+
}
350+
327351
const file_content = [
352+
prompts_content,
328353
final_diff_content ? final_diff_content : '',
329354
!is_deleted && full_content && !is_too_large ? full_content : ''
330355
]

0 commit comments

Comments
 (0)