Skip to content

Commit 7d3bfbf

Browse files
committed
Add check parent folder command to workspace context menu and quick actions
1 parent 1cb6ebd commit 7d3bfbf

4 files changed

Lines changed: 97 additions & 5 deletions

File tree

‎packages/vscode/package.json‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,12 @@
264264
},
265265
{
266266
"command": "codeWebChat.delete",
267-
"title": "Delete"
267+
"title": "Delete",
268+
"icon": "$(trash)"
269+
},
270+
{
271+
"command": "codeWebChat.checkParentFolder",
272+
"title": "Check Parent Folder"
268273
},
269274
{
270275
"command": "codeWebChat.referenceInPrompt",
@@ -358,6 +363,10 @@
358363
"command": "codeWebChat.delete",
359364
"when": "false"
360365
},
366+
{
367+
"command": "codeWebChat.checkParentFolder",
368+
"when": "false"
369+
},
361370
{
362371
"command": "codeWebChat.previewWebsite",
363372
"when": "false"
@@ -520,20 +529,25 @@
520529
"group": "1_modification@2"
521530
},
522531
{
523-
"command": "codeWebChat.referenceInPrompt",
532+
"command": "codeWebChat.checkParentFolder",
524533
"when": "view == codeWebChatViewOpenEditors && viewItem == openEditor",
525534
"group": "1_modification@3"
526535
},
527536
{
528-
"command": "codeWebChat.revealInExplorer",
537+
"command": "codeWebChat.referenceInPrompt",
529538
"when": "view == codeWebChatViewOpenEditors && viewItem == openEditor",
530539
"group": "1_modification@4"
531540
},
532541
{
533-
"command": "codeWebChat.setRange",
542+
"command": "codeWebChat.revealInExplorer",
534543
"when": "view == codeWebChatViewOpenEditors && viewItem == openEditor",
535544
"group": "1_modification@5"
536545
},
546+
{
547+
"command": "codeWebChat.setRange",
548+
"when": "view == codeWebChatViewOpenEditors && viewItem == openEditor",
549+
"group": "1_modification@6"
550+
},
537551
{
538552
"command": "codeWebChat.newFile",
539553
"when": "view == codeWebChatViewWorkspace && viewItem == directory",
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import * as vscode from 'vscode'
2+
import * as path from 'path'
3+
import {
4+
WorkspaceProvider,
5+
FileItem
6+
} from '../context/providers/workspace-provider'
7+
8+
export const check_parent_folder_command = (
9+
workspace_provider: WorkspaceProvider
10+
) => {
11+
return vscode.commands.registerCommand(
12+
'codeWebChat.checkParentFolder',
13+
async (item: FileItem) => {
14+
if (!item) return
15+
16+
const file_path = item.resourceUri.fsPath
17+
const workspace_root =
18+
workspace_provider.get_workspace_root_for_file(file_path)
19+
20+
if (!workspace_root) return
21+
22+
const folders: { label: string; full_path: string }[] = []
23+
let current_dir = path.dirname(file_path)
24+
25+
while (
26+
current_dir.startsWith(workspace_root) &&
27+
current_dir !== workspace_root
28+
) {
29+
const label = path
30+
.relative(workspace_root, current_dir)
31+
.replace(/\\/g, '/')
32+
33+
folders.push({
34+
label: label,
35+
full_path: current_dir
36+
})
37+
38+
current_dir = path.dirname(current_dir)
39+
}
40+
41+
if (folders.length === 0) {
42+
vscode.window.showInformationMessage('No parent folders found.')
43+
return
44+
}
45+
46+
const selected = await vscode.window.showQuickPick(folders, {
47+
placeHolder: 'Select a parent folder to check',
48+
title: 'Check Parent Folder'
49+
})
50+
51+
if (selected) {
52+
const is_workspace_root = selected.full_path === workspace_root
53+
const folder_item = new FileItem(
54+
path.basename(selected.full_path),
55+
vscode.Uri.file(selected.full_path),
56+
vscode.TreeItemCollapsibleState.Collapsed,
57+
true,
58+
vscode.TreeItemCheckboxState.Checked,
59+
false,
60+
false,
61+
undefined,
62+
undefined,
63+
undefined,
64+
is_workspace_root,
65+
undefined
66+
)
67+
68+
await workspace_provider.update_check_state(
69+
folder_item,
70+
vscode.TreeItemCheckboxState.Checked
71+
)
72+
}
73+
}
74+
)
75+
}

‎packages/vscode/src/commands/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ export * from './save-context-command'
1919
export * from './apply-context-command'
2020
export * from './find-paths-in-clipboard-command'
2121
export * from './set-range-command'
22+
export * from './check-parent-folder-command'

‎packages/vscode/src/extension.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ import {
2727
reference_in_prompt_command,
2828
open_url_command,
2929
generate_commit_message_command,
30-
set_range_command
30+
set_range_command,
31+
check_parent_folder_command
3132
} from './commands'
3233
import {
3334
get_checkpoints,
@@ -117,6 +118,7 @@ export async function activate(context: vscode.ExtensionContext) {
117118
add_file_to_context_command(workspace_provider),
118119
remove_file_from_context_command(workspace_provider),
119120
set_range_command(workspace_provider, context),
121+
check_parent_folder_command(workspace_provider),
120122
find_paths_in_clipboard_command(workspace_provider),
121123
duplicate_workspace_command(workspace_provider, websites_provider, context),
122124
open_url_command({

0 commit comments

Comments
 (0)