Skip to content

Commit 8f28e7b

Browse files
committed
Refactor quick pick labels into named constants and correct the context filtering logic for code completions
1 parent 62078b6 commit 8f28e7b

1 file changed

Lines changed: 17 additions & 13 deletions

File tree

‎packages/vscode/src/views/panel/backend/utils/hash-sign-quick-pick.ts‎

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,35 @@ import * as vscode from 'vscode'
22
import { execSync } from 'child_process'
33
import * as path from 'path'
44
import * as fs from 'fs'
5-
import { SAVED_CONTEXTS_STATE_KEY } from '../../../../constants/state-keys'
6-
import { SavedContext } from '../../../../types/context'
75
import { dictionary } from '@shared/constants/dictionary'
6+
import { SAVED_CONTEXTS_STATE_KEY } from '@/constants/state-keys'
7+
import { SavedContext } from '@/types/context'
88

99
export async function hash_sign_quick_pick(params: {
1010
context: vscode.ExtensionContext
1111
is_for_code_completions: boolean
1212
}): Promise<string | undefined> {
13+
const selection_label = '$(list-flat) Selection'
14+
const changes_label = '$(git-pull-request-draft) Changes'
15+
const saved_context_label = '$(checklist) Saved context'
16+
1317
let items = [
1418
{
15-
label: '$(list-flat) Selection',
19+
label: selection_label,
1620
description: 'Text selection from the active editor'
1721
},
1822
{
19-
label: '$(git-pull-request-draft) Changes',
20-
description: 'Diff of changes between the selected branch'
23+
label: changes_label,
24+
description: 'Diff with the selected branch'
2125
},
2226
{
23-
label: '$(checklist) Saved context',
24-
description: 'Include files from the saved context'
27+
label: saved_context_label,
28+
description: 'XML-formatted files'
2529
}
2630
]
2731

2832
if (params.is_for_code_completions) {
29-
items = items.filter((item) => item.label == '#SavedContext')
33+
items = items.filter((item) => item.label == saved_context_label)
3034
}
3135

3236
// eslint-disable-next-line no-constant-condition
@@ -40,11 +44,11 @@ export async function hash_sign_quick_pick(params: {
4044
return
4145
}
4246

43-
if (selected.label == '$(list-flat) Selection') {
47+
if (selected.label == selection_label) {
4448
return '#Selection '
4549
}
4650

47-
if (selected.label == '$(git-pull-request-draft) Changes') {
51+
if (selected.label == changes_label) {
4852
try {
4953
const workspace_folders = vscode.workspace.workspaceFolders
5054
if (!workspace_folders || workspace_folders.length == 0) {
@@ -131,7 +135,7 @@ export async function hash_sign_quick_pick(params: {
131135
continue
132136
}
133137

134-
if (selected.label == '$(checklist) Saved context') {
138+
if (selected.label == saved_context_label) {
135139
const workspace_root = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath
136140
if (!workspace_root) {
137141
vscode.window.showErrorMessage(
@@ -184,13 +188,13 @@ export async function hash_sign_quick_pick(params: {
184188
source_options.push({
185189
label: 'JSON File (.vscode/contexts.json)',
186190
description: `${file_contexts.length} context${
187-
file_contexts.length === 1 ? '' : 's'
191+
file_contexts.length == 1 ? '' : 's'
188192
}`,
189193
value: 'JSON'
190194
})
191195
}
192196

193-
if (source_options.length === 0) {
197+
if (source_options.length == 0) {
194198
vscode.window.showInformationMessage(
195199
dictionary.information_message.NO_SAVED_CONTEXTS_FOUND
196200
)

0 commit comments

Comments
 (0)