Skip to content

Commit c9199ae

Browse files
committed
Display file token counts in the referencing files command quick pick items
- in `apps/editor/src/commands/check-referencing-files-for-context-command.ts` show token counts
1 parent f7e63b2 commit c9199ae

1 file changed

Lines changed: 27 additions & 16 deletions

File tree

‎apps/editor/src/commands/check-referencing-files-for-context-command.ts‎

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as vscode from 'vscode'
22
import * as path from 'path'
33
import { WorkspaceProvider } from '../context/providers/workspace/workspace-provider'
44
import { Logger } from '@shared/utils/logger'
5+
import { display_token_count } from '../utils/display-token-count'
56
import { t } from '../i18n'
67

78
export const check_referencing_files_for_context_command = (
@@ -64,22 +65,32 @@ export const check_referencing_files_for_context_command = (
6465

6566
const currently_checked = workspace_provider.get_checked_files()
6667

67-
const quick_pick_items = matched_files.map(({ file_path, range }) => {
68-
const workspace_root =
69-
workspace_provider.get_workspace_root_for_file(file_path)
70-
const relative_path = workspace_root
71-
? path.relative(workspace_root, file_path)
72-
: file_path
73-
74-
const dir_name = path.dirname(relative_path)
75-
return {
76-
label: path.basename(file_path),
77-
description: dir_name == '.' ? '' : dir_name,
78-
file_path,
79-
range,
80-
buttons: [open_file_button]
81-
}
82-
})
68+
const quick_pick_items = await Promise.all(
69+
matched_files.map(async ({ file_path, range }) => {
70+
const workspace_root =
71+
workspace_provider.get_workspace_root_for_file(file_path)
72+
const relative_path = workspace_root
73+
? path.relative(workspace_root, file_path)
74+
: file_path
75+
76+
const dir_name = path.dirname(relative_path)
77+
const display_dir = dir_name == '.' ? '' : dir_name
78+
79+
const token_count =
80+
await workspace_provider.calculate_file_tokens(file_path)
81+
const formatted_token_count = display_token_count(token_count.total)
82+
83+
return {
84+
label: path.basename(file_path),
85+
description: display_dir
86+
? `${formatted_token_count} · ${display_dir}`
87+
: formatted_token_count,
88+
file_path,
89+
range,
90+
buttons: [open_file_button]
91+
}
92+
})
93+
)
8394

8495
const quick_pick = vscode.window.createQuickPick<
8596
vscode.QuickPickItem & { file_path: string; range: vscode.Range }

0 commit comments

Comments
 (0)