File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 277277 "command" : " codeWebChat.settings" ,
278278 "title" : " Settings" ,
279279 "category" : " Code Web Chat"
280+ },
281+ {
282+ "command" : " codeWebChat.generateCommitMessage" ,
283+ "title" : " Generate Commit Message with CWC" ,
284+ "category" : " Code Web Chat" ,
285+ "icon" : " $(sparkle)"
280286 }
281287 ],
282288 "menus" : {
459465 "group" : " navigation@1"
460466 }
461467 ],
468+ "scm/title" : [
469+ {
470+ "command" : " codeWebChat.generateCommitMessage" ,
471+ "group" : " navigation" ,
472+ "when" : " scmProvider == git"
473+ }
474+ ],
462475 "view/item/context" : [
463476 {
464477 "command" : " codeWebChat.closeEditor" ,
Original file line number Diff line number Diff line change 11import * as vscode from 'vscode'
22import { context_initialization } from './context/context-initialization'
3+ import {
4+ get_git_repository ,
5+ prepare_staged_changes
6+ } from './utils/git-repository-utils'
7+ import { generate_commit_message_from_diff } from './views/panel/backend/message-handlers/handle-commit-changes/utils'
38import { PanelProvider } from './views/panel/backend/panel-provider'
49import { WebSocketManager } from './services/websocket-manager'
510import {
@@ -107,4 +112,27 @@ export async function activate(context: vscode.ExtensionContext) {
107112 }
108113 )
109114 )
115+
116+ context . subscriptions . push (
117+ vscode . commands . registerCommand (
118+ 'codeWebChat.generateCommitMessage' ,
119+ async ( source_control ?: vscode . SourceControl ) => {
120+ const repository = get_git_repository ( source_control )
121+ if ( ! repository ) return
122+
123+ const diff = await prepare_staged_changes ( repository )
124+
125+ if ( ! diff ) return
126+
127+ const commit_message = await generate_commit_message_from_diff ( {
128+ context,
129+ repository,
130+ diff
131+ } )
132+ if ( commit_message ) {
133+ repository . inputBox . value = commit_message
134+ }
135+ }
136+ )
137+ )
110138}
Original file line number Diff line number Diff line change @@ -63,11 +63,19 @@ export function get_git_repository(
6363export async function prepare_staged_changes (
6464 repository : GitRepository
6565) : Promise < string | null > {
66+ await repository . status ( )
6667 const staged_changes = repository . state . indexChanges || [ ]
6768
68- if ( staged_changes . length === 0 ) {
69- await repository . add ( [ ] )
69+ if (
70+ staged_changes . length === 0 &&
71+ repository . state . workingTreeChanges . length > 0
72+ ) {
73+ const uris_to_stage = repository . state . workingTreeChanges . map (
74+ ( change : any ) => change . uri . fsPath
75+ )
76+ await repository . add ( uris_to_stage )
7077 await new Promise ( ( resolve ) => setTimeout ( resolve , 500 ) )
78+ await repository . status ( )
7179 }
7280
7381 const diff = execSync ( 'git diff --staged' , {
You can’t perform that action at this time.
0 commit comments