Skip to content

Commit 5c32b20

Browse files
committed
Refactor and simplify API request progress notifications to report server, thinking, and receiving states
1 parent 78073a5 commit 5c32b20

2 files changed

Lines changed: 29 additions & 48 deletions

File tree

‎apps/editor/src/commands/code-at-cursor-commands.ts‎

Lines changed: 17 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -415,62 +415,35 @@ const perform_code_at_cursor = async (params: {
415415
cancel_token_source.cancel('User moved the cursor, cancelling request.')
416416
})
417417

418-
let thinking_reported = false
419-
let resolve_thinking: () => void
420-
const thinking_promise = new Promise<void>((resolve) => {
421-
resolve_thinking = resolve
422-
})
423-
424-
const on_thinking_chunk = () => {
425-
if (!thinking_reported) {
426-
thinking_reported = true
427-
resolve_thinking()
428-
}
429-
}
430-
431-
const api_promise = make_api_request({
432-
endpoint_url,
433-
api_key: provider.api_key,
434-
body,
435-
cancellation_token: cancel_token_source.token,
436-
on_thinking_chunk
437-
})
438-
439418
try {
440-
await vscode.window.withProgress(
419+
const completion_result = await vscode.window.withProgress(
441420
{
442421
location: vscode.ProgressLocation.Notification,
443-
title: dictionary.api_call.WAITING_FOR_RESPONSE,
422+
title: 'Requested code at cursor',
444423
cancellable: true
445424
},
446-
async (_, token) => {
425+
async (progress, token) => {
447426
token.onCancellationRequested(() => {
448427
cancel_token_source.cancel('User cancelled the operation')
449428
})
450429

451-
await Promise.race([api_promise, thinking_promise])
430+
progress.report({ message: 'waiting for server...' })
431+
432+
return await make_api_request({
433+
endpoint_url,
434+
api_key: provider.api_key,
435+
body,
436+
cancellation_token: cancel_token_source.token,
437+
on_chunk: () => {
438+
progress.report({ message: 'receiving...' })
439+
},
440+
on_thinking_chunk: () => {
441+
progress.report({ message: 'thinking...' })
442+
}
443+
})
452444
}
453445
)
454446

455-
if (thinking_reported) {
456-
await vscode.window.withProgress(
457-
{
458-
location: vscode.ProgressLocation.Notification,
459-
title: dictionary.api_call.THINKING,
460-
cancellable: true
461-
},
462-
async (progress, token) => {
463-
token.onCancellationRequested(() => {
464-
cancel_token_source.cancel('User cancelled the operation')
465-
})
466-
467-
await api_promise
468-
}
469-
)
470-
}
471-
472-
const completion_result = await api_promise
473-
474447
if (completion_result) {
475448
const match = completion_result.response.match(
476449
/<replacement>([\s\S]*?)<\/replacement>/i

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const generate_commit_message_with_api = async (params: {
2424
messages,
2525
model: params.config.model,
2626
temperature: params.config.temperature
27-
} as any
27+
}
2828

2929
apply_reasoning_effort(body, params.provider, params.config.reasoning_effort)
3030

@@ -33,20 +33,28 @@ export const generate_commit_message_with_api = async (params: {
3333
return await vscode.window.withProgress(
3434
{
3535
location: vscode.ProgressLocation.Notification,
36-
title: dictionary.api_call.WAITING_FOR_RESPONSE,
36+
title: 'Requested commit message',
3737
cancellable: true
3838
},
39-
async (_, token) => {
39+
async (progress, token) => {
4040
token.onCancellationRequested(() => {
4141
cancel_token_source.cancel('Operation cancelled by user')
4242
})
4343

44+
progress.report({ message: 'waiting for server...' })
45+
4446
try {
4547
const response_result = await make_api_request({
4648
endpoint_url: params.endpoint_url,
4749
api_key: params.provider.api_key,
4850
body,
49-
cancellation_token: cancel_token_source.token
51+
cancellation_token: cancel_token_source.token,
52+
on_chunk: () => {
53+
progress.report({ message: 'receiving...' })
54+
},
55+
on_thinking_chunk: () => {
56+
progress.report({ message: 'thinking...' })
57+
}
5058
})
5159

5260
if (!response_result) {

0 commit comments

Comments
 (0)