Skip to content

Commit eabbc05

Browse files
committed
Add token count display and improve unstaged file selection with a quick pick UI
1 parent 81d5ec5 commit eabbc05

3 files changed

Lines changed: 31 additions & 12 deletions

File tree

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
get_git_repository,
44
prepare_staged_changes
55
} from '../../utils/git-repository-utils'
6+
import { display_token_count } from '../../utils/display-token-count'
67
import { get_commit_message_config } from './utils/get-commit-message-config'
78
import { build_commit_message_prompt } from './utils/build-commit-message-prompt'
89
import { generate_commit_message_with_api } from './utils/generate-commit-message-with-api'
@@ -122,8 +123,11 @@ export const generate_commit_message_command = (
122123
const { was_empty_stage, message_prompt } = data
123124

124125
await vscode.env.clipboard.writeText(message_prompt)
126+
const token_count = Math.floor(message_prompt.length / 4)
125127
vscode.window.showInformationMessage(
126-
'Commit message prompt copied to clipboard'
128+
`Commit message prompt of about ${display_token_count(
129+
token_count
130+
)} tokens copied to clipboard.`
127131
)
128132

129133
if (was_empty_stage) {

‎apps/editor/src/utils/git-repository-utils.ts‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,32 @@ export const prepare_staged_changes = async (
9696
staged_changes.length == 0 &&
9797
repository.state.workingTreeChanges.length > 0
9898
) {
99-
const files_to_stage = repository.state.workingTreeChanges.map(
100-
(change: any) => change.uri.fsPath
101-
)
99+
const items = repository.state.workingTreeChanges.map((change: any) => {
100+
const relative_path = path.relative(
101+
repository.rootUri.fsPath,
102+
change.uri.fsPath
103+
)
104+
const dir_name = path.dirname(relative_path)
105+
106+
return {
107+
label: path.basename(relative_path),
108+
description: dir_name == '.' ? '' : dir_name,
109+
picked: true,
110+
fsPath: change.uri.fsPath
111+
}
112+
})
113+
114+
const selected = await vscode.window.showQuickPick(items, {
115+
canPickMany: true,
116+
title: 'Unstaged Files',
117+
placeHolder: 'Select files to commit'
118+
})
119+
120+
if (!selected || selected.length == 0) {
121+
return null
122+
}
123+
124+
const files_to_stage = selected.map((item) => item.fsPath)
102125
const file_args = files_to_stage
103126
.map((file: string) => `"${file.replace(/"/g, '\\"')}"`)
104127
.join(' ')

‎packages/ui/src/components/editor/panel/PromptField/utils/format-token-count.ts‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)