Skip to content

Commit 755b6cc

Browse files
committed
Implement a 'Thinking' progress state for code completion API calls
1 parent 04c0686 commit 755b6cc

2 files changed

Lines changed: 104 additions & 51 deletions

File tree

‎packages/vscode/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "gemini-coder",
33
"displayName": "Code Web Chat",
44
"description": "CWC connects VS Code with ChatGPT, AI Studio, DeepSeek, and 10+ other free chatbots. Saves you money and time.",
5-
"version": "1.397.0",
5+
"version": "1.398.0",
66
"scripts": {
77
"build": "npx vsce package --no-dependencies",
88
"vscode:prepublish": "rimraf out && npm run compile",

‎packages/vscode/src/commands/code-completion-commands.ts‎

Lines changed: 103 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { DEFAULT_TEMPERATURE } from '@shared/constants/api-tools'
1212
import { ToolConfig } from '@/services/model-providers-manager'
1313
import { ViewProvider } from '@/views/panel/backend/view-provider'
1414
import { dictionary } from '@shared/constants/dictionary'
15+
import { apply_reasoning_effort } from '../utils/apply-reasoning-effort'
1516

1617
// Show inline completion using Inline Completions API
1718
const show_inline_completion = async (params: {
@@ -372,73 +373,125 @@ const perform_code_completion = async (params: {
372373
}
373374
]
374375

375-
const body = {
376+
const body: { [key: string]: any } = {
376377
messages,
377378
model: code_completions_config.model,
378-
temperature: code_completions_config.temperature,
379-
reasoning_effort: code_completions_config.reasoning_effort
379+
temperature: code_completions_config.temperature
380380
}
381381

382+
apply_reasoning_effort(
383+
body,
384+
provider,
385+
code_completions_config.reasoning_effort
386+
)
387+
382388
const cursor_listener = vscode.window.onDidChangeTextEditorSelection(() => {
383389
cancel_token_source.cancel('User moved the cursor, cancelling request.')
384390
})
385391

386-
vscode.window.withProgress(
387-
{
388-
location: vscode.ProgressLocation.Notification,
389-
title: dictionary.api_call.WAITING_FOR_API_RESPONSE,
390-
cancellable: true
391-
},
392-
async (progress, token) => {
393-
token.onCancellationRequested(() => {
394-
cancel_token_source.cancel('User cancelled the operation')
395-
})
392+
let thinking_reported = false
393+
let resolve_thinking: () => void
394+
const thinking_promise = new Promise<void>((resolve) => {
395+
resolve_thinking = resolve
396+
})
396397

397-
let wait_time = 0
398-
const wait_timer = setInterval(() => {
399-
progress.report({
400-
message: `${(wait_time / 10).toFixed(1)}s`
401-
})
402-
wait_time++
403-
}, 100)
404-
405-
try {
406-
const completion_result = await make_api_request({
407-
endpoint_url,
408-
api_key: provider.api_key,
409-
body,
410-
cancellation_token: cancel_token_source.token
398+
const on_thinking_chunk = () => {
399+
if (!thinking_reported) {
400+
thinking_reported = true
401+
resolve_thinking()
402+
}
403+
}
404+
405+
const api_promise = make_api_request({
406+
endpoint_url,
407+
api_key: provider.api_key,
408+
body,
409+
cancellation_token: cancel_token_source.token,
410+
on_thinking_chunk
411+
})
412+
413+
try {
414+
await vscode.window.withProgress(
415+
{
416+
location: vscode.ProgressLocation.Notification,
417+
title: dictionary.api_call.WAITING_FOR_API_RESPONSE,
418+
cancellable: true
419+
},
420+
async (progress, token) => {
421+
token.onCancellationRequested(() => {
422+
cancel_token_source.cancel('User cancelled the operation')
411423
})
412424

413-
if (completion_result) {
414-
const match = completion_result.response.match(
415-
/<replacement>([\s\S]*?)<\/replacement>/i
416-
)
417-
if (match && match[1]) {
418-
let decoded_completion = he.decode(match[1].trim())
419-
decoded_completion = decoded_completion
420-
.replace(/<!\[CDATA\[/g, '')
421-
.replace(/\]\]>/g, '')
422-
.trim()
423-
await show_inline_completion({
424-
editor,
425-
position,
426-
completion_text: decoded_completion
425+
let wait_time = 0
426+
const wait_timer = setInterval(() => {
427+
progress.report({
428+
message: `${(wait_time / 10).toFixed(1)}s`
429+
})
430+
wait_time++
431+
}, 100)
432+
433+
await Promise.race([api_promise, thinking_promise])
434+
clearInterval(wait_timer)
435+
}
436+
)
437+
438+
if (thinking_reported) {
439+
await vscode.window.withProgress(
440+
{
441+
location: vscode.ProgressLocation.Notification,
442+
title: dictionary.api_call.THINKING,
443+
cancellable: true
444+
},
445+
async (progress, token) => {
446+
token.onCancellationRequested(() => {
447+
cancel_token_source.cancel('User cancelled the operation')
448+
})
449+
450+
let thinking_time = 0
451+
const thinking_timer = setInterval(() => {
452+
progress.report({
453+
message: `${(thinking_time / 10).toFixed(1)}s`
427454
})
455+
thinking_time++
456+
}, 100)
457+
458+
try {
459+
await api_promise
460+
} finally {
461+
clearInterval(thinking_timer)
428462
}
429463
}
430-
} catch (err: any) {
431-
Logger.error({
432-
function_name: 'perform_fim_completion',
433-
message: 'Completion error',
434-
data: err
464+
)
465+
}
466+
467+
const completion_result = await api_promise
468+
469+
if (completion_result) {
470+
const match = completion_result.response.match(
471+
/<replacement>([\s\S]*?)<\/replacement>/i
472+
)
473+
if (match && match[1]) {
474+
let decoded_completion = he.decode(match[1].trim())
475+
decoded_completion = decoded_completion
476+
.replace(/<!\[CDATA\[/g, '')
477+
.replace(/\]\]>/g, '')
478+
.trim()
479+
await show_inline_completion({
480+
editor,
481+
position,
482+
completion_text: decoded_completion
435483
})
436-
} finally {
437-
cursor_listener.dispose()
438-
clearInterval(wait_timer)
439484
}
440485
}
441-
)
486+
} catch (err: any) {
487+
Logger.error({
488+
function_name: 'perform_fim_completion',
489+
message: 'Completion error',
490+
data: err
491+
})
492+
} finally {
493+
cursor_listener.dispose()
494+
}
442495
}
443496
}
444497

0 commit comments

Comments
 (0)