Skip to content

Commit bb68a75

Browse files
committed
Bump version to 1.852.0 and enhance file selection UI with token count display
1 parent 3b3fbc8 commit bb68a75

3 files changed

Lines changed: 103 additions & 47 deletions

File tree

apps/editor/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": "The fastest way to code with AI (CWC)",
5-
"version": "1.851.0",
5+
"version": "1.852.0",
66
"scripts": {
77
"build": "npx vsce package --no-dependencies",
88
"vscode:prepublish": "rimraf out && npm run compile",

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

Lines changed: 76 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from './utils/clipboard-parser'
1212
import { create_safe_path } from '@/utils/path-sanitizer'
1313
import { dictionary } from '@shared/constants/dictionary'
14+
import { display_token_count } from '../../utils/display-token-count'
1415
import { Logger } from '@shared/utils/logger'
1516
import { apply_git_patch } from './handlers/diff-handler'
1617
import { apply_file_relocations } from './utils/file-operations'
@@ -110,14 +111,8 @@ export const process_chat_response = async (
110111
relevant_files_item.file_paths.map((p) => p.replace(/\\/g, '/'))
111112
)
112113

113-
const quick_pick_items: {
114-
label: string
115-
picked: boolean
116-
description?: string
117-
}[] = relevant_files_item.file_paths.map((path) => ({
118-
label: path,
119-
picked: true
120-
}))
114+
const workspace_roots = workspace_provider.get_workspace_roots()
115+
const all_paths_to_process = new Set<string>(relevant_files_item.file_paths)
121116

122117
for (const file_path of current_checked_files) {
123118
const workspace_root =
@@ -126,47 +121,102 @@ export const process_chat_response = async (
126121
const relative_path = path
127122
.relative(workspace_root, file_path)
128123
.replace(/\\/g, '/')
129-
if (!relevant_paths_normalized.has(relative_path)) {
130-
if (!quick_pick_items.some((item) => item.label == relative_path)) {
131-
quick_pick_items.push({
132-
label: relative_path,
133-
picked: false
134-
})
135-
}
136-
}
124+
all_paths_to_process.add(relative_path)
137125
}
138126
}
139127

140-
quick_pick_items.sort((a, b) => natural_sort(a.label, b.label))
128+
const open_file_button = {
129+
iconPath: new vscode.ThemeIcon('go-to-file'),
130+
tooltip: t('common.go-to-file')
131+
}
132+
133+
const quick_pick_items = await Promise.all(
134+
Array.from(all_paths_to_process).map(async (rel_path) => {
135+
let absolute_path: string | undefined
136+
for (const root of workspace_roots) {
137+
const potential = path.join(root, rel_path)
138+
if (fs.existsSync(potential)) {
139+
absolute_path = potential
140+
break
141+
}
142+
}
143+
144+
let token_info = ''
145+
if (absolute_path) {
146+
const count =
147+
await workspace_provider.calculate_file_tokens(absolute_path)
148+
token_info = display_token_count(count.total)
149+
}
141150

142-
const quick_pick = vscode.window.createQuickPick()
151+
const dir_name = path.dirname(rel_path)
152+
const display_dir = dir_name === '.' ? '' : dir_name
153+
154+
return {
155+
label: path.basename(rel_path),
156+
description: display_dir
157+
? `${token_info} · ${display_dir}`
158+
: token_info,
159+
picked: relevant_paths_normalized.has(rel_path),
160+
file_path: absolute_path,
161+
relative_path: rel_path,
162+
buttons: [open_file_button]
163+
}
164+
})
165+
)
166+
167+
quick_pick_items.sort((a, b) =>
168+
natural_sort(a.relative_path, b.relative_path)
169+
)
170+
171+
const quick_pick =
172+
vscode.window.createQuickPick<(typeof quick_pick_items)[0]>()
143173
quick_pick.items = quick_pick_items
144174
quick_pick.selectedItems = quick_pick_items.filter((i) => i.picked)
145175
quick_pick.canSelectMany = true
146176
quick_pick.title = t('command.apply-chat-response.context-pruning.title')
147177
quick_pick.placeholder = t(
148178
'command.apply-chat-response.context-pruning.placeholder'
149179
)
150-
quick_pick.buttons = [
151-
{ iconPath: new vscode.ThemeIcon('close'), tooltip: t('common.close') }
152-
]
180+
quick_pick.ignoreFocusOut = true
181+
182+
const close_button = {
183+
iconPath: new vscode.ThemeIcon('close'),
184+
tooltip: t('common.close')
185+
}
186+
quick_pick.buttons = [close_button]
153187

154188
const selected_items = await new Promise<
155-
readonly vscode.QuickPickItem[] | undefined
189+
readonly (typeof quick_pick_items)[0][] | undefined
156190
>((resolve) => {
157191
let is_accepted = false
158192
const disposables: vscode.Disposable[] = []
159193

160194
disposables.push(
161195
quick_pick.onDidTriggerButton((button) => {
162-
if (button.tooltip == 'Close') {
196+
if (button === close_button) {
163197
quick_pick.hide()
164198
resolve(undefined)
165199
}
166200
}),
201+
quick_pick.onDidTriggerItemButton(async (e) => {
202+
if (e.button === open_file_button && e.item.file_path) {
203+
try {
204+
const doc = await vscode.workspace.openTextDocument(
205+
e.item.file_path
206+
)
207+
await vscode.window.showTextDocument(doc, { preview: true })
208+
} catch (error) {
209+
vscode.window.showErrorMessage(
210+
t('command.context.check-references.error-opening', {
211+
error: String(error)
212+
})
213+
)
214+
}
215+
}
216+
}),
167217
quick_pick.onDidAccept(() => {
168218
is_accepted = true
169-
resolve(quick_pick.selectedItems)
219+
resolve([...quick_pick.selectedItems])
170220
quick_pick.hide()
171221
}),
172222
quick_pick.onDidHide(() => {
@@ -181,16 +231,11 @@ export const process_chat_response = async (
181231
})
182232

183233
if (selected_items && selected_items.length > 0) {
184-
const workspace_roots = workspace_provider.get_workspace_roots()
185234
const files_to_check: string[] = []
186235

187236
for (const selection of selected_items) {
188-
for (const root of workspace_roots) {
189-
const potential_path = path.join(root, selection.label)
190-
if (fs.existsSync(potential_path)) {
191-
files_to_check.push(potential_path)
192-
break
193-
}
237+
if (selection.file_path) {
238+
files_to_check.push(selection.file_path)
194239
}
195240
}
196241

apps/editor/src/commands/search-files-for-context-command.ts

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
LAST_CONTEXT_MERGE_REPLACE_OPTION_STATE_KEY,
88
LAST_SEARCH_FILES_FOR_CONTEXT_QUERY_STATE_KEY
99
} from '../constants/state-keys'
10+
import { display_token_count } from '../utils/display-token-count'
1011
import { dictionary } from '@shared/constants/dictionary'
1112
import { t } from '../i18n'
1213

@@ -131,21 +132,31 @@ export const search_files_for_context_commands = (
131132

132133
const currently_checked = workspace_provider.get_checked_files()
133134

134-
const quick_pick_items = matched_files.map((file_path) => {
135-
const workspace_root =
136-
workspace_provider.get_workspace_root_for_file(file_path)
137-
const relative_path = workspace_root
138-
? path.relative(workspace_root, file_path)
139-
: file_path
140-
141-
const dir_name = path.dirname(relative_path)
142-
return {
143-
label: path.basename(file_path),
144-
description: dir_name == '.' ? '' : dir_name,
145-
file_path,
146-
buttons: [open_file_button]
147-
}
148-
})
135+
const quick_pick_items = await Promise.all(
136+
matched_files.map(async (file_path) => {
137+
const workspace_root =
138+
workspace_provider.get_workspace_root_for_file(file_path)
139+
const relative_path = workspace_root
140+
? path.relative(workspace_root, file_path)
141+
: file_path
142+
143+
const dir_name = path.dirname(relative_path)
144+
const display_dir = dir_name == '.' ? '' : dir_name
145+
146+
const token_count =
147+
await workspace_provider.calculate_file_tokens(file_path)
148+
const formatted_token_count = display_token_count(token_count.total)
149+
150+
return {
151+
label: path.basename(file_path),
152+
description: display_dir
153+
? `${formatted_token_count} · ${display_dir}`
154+
: formatted_token_count,
155+
file_path,
156+
buttons: [open_file_button]
157+
}
158+
})
159+
)
149160

150161
const quick_pick = vscode.window.createQuickPick<
151162
vscode.QuickPickItem & { file_path: string }

0 commit comments

Comments
 (0)