Skip to content

Commit 16e6d2f

Browse files
committed
Handle multiple input types for reference-in-prompt command including active editor fallback
1 parent 864a82d commit 16e6d2f

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

‎apps/editor/src/commands/reference-in-prompt-command.ts‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,29 @@ export const reference_in_prompt_command = (params: {
1111
}) => {
1212
return vscode.commands.registerCommand(
1313
'codeWebChat.referenceInPrompt',
14-
async (uri: FileItem) => {
14+
async (uri?: any) => {
1515
if (!params.panel_provider || !params.workspace_provider) {
1616
return
1717
}
1818

19-
const file_path = uri.resourceUri.fsPath
19+
let active_uri: vscode.Uri | undefined
20+
let is_directory = false
21+
let target_item = uri
22+
23+
if (uri && uri.resourceUri) {
24+
active_uri = uri.resourceUri
25+
is_directory = !!uri.isDirectory
26+
} else if (uri && uri.fsPath) {
27+
active_uri = uri
28+
target_item = { resourceUri: active_uri, isDirectory: false }
29+
} else if (vscode.window.activeTextEditor) {
30+
active_uri = vscode.window.activeTextEditor.document.uri
31+
target_item = { resourceUri: active_uri, isDirectory: false }
32+
}
33+
34+
if (!active_uri) return
35+
36+
const file_path = active_uri.fsPath
2037

2138
const workspace_root =
2239
params.workspace_provider.get_workspace_root_for_file(file_path)
@@ -33,12 +50,12 @@ export const reference_in_prompt_command = (params: {
3350
.includes(file_path)
3451

3552
const is_partially_checked =
36-
uri.isDirectory &&
53+
is_directory &&
3754
params.workspace_provider.is_partially_checked(file_path)
3855

3956
if (!is_checked && !is_partially_checked) {
4057
await params.workspace_provider.update_check_state(
41-
uri,
58+
target_item as FileItem,
4259
vscode.TreeItemCheckboxState.Checked
4360
)
4461
}

0 commit comments

Comments
 (0)