|
|
@@ -1,4 +1,3 @@
|
|
|
-import * as path from 'path';
|
|
|
import * as vscode from 'vscode';
|
|
|
|
|
|
/**
|
|
|
@@ -72,39 +71,28 @@ export async function copyActiveFile(): Promise<void> {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Select files from the workspace and copy their contents.
|
|
|
+ * Copy a single file/folder path to clipboard with AI-friendly formatting.
|
|
|
+ * Output: [src/utils] or [src/file.ts]
|
|
|
*/
|
|
|
-export async function copyWorkspaceFiles(): Promise<void> {
|
|
|
- const workspaceFolders = vscode.workspace.workspaceFolders;
|
|
|
- if (!workspaceFolders || workspaceFolders.length === 0) return;
|
|
|
-
|
|
|
- const uris = await vscode.window.showOpenDialog({
|
|
|
- canSelectFiles: true,
|
|
|
- canSelectFolders: false,
|
|
|
- canSelectMany: true,
|
|
|
- openLabel: 'Select files to copy as context',
|
|
|
- });
|
|
|
-
|
|
|
- if (!uris || uris.length === 0) return;
|
|
|
-
|
|
|
- await copyFilesFromUris(uris);
|
|
|
+export async function copySingleItem(itemUri: vscode.Uri): Promise<void> {
|
|
|
+ const itemPath = vscode.workspace.asRelativePath(itemUri);
|
|
|
+ const result = `[${itemPath}]`;
|
|
|
+ await vscode.env.clipboard.writeText(result);
|
|
|
+ showStatus(`$(clippy) Copied: ${itemPath}`);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Copy a single folder path to clipboard with AI-friendly formatting.
|
|
|
- * Output: [src/utils]
|
|
|
+ * Copy files selected in the explorer context menu.
|
|
|
*/
|
|
|
-export async function copyFolderPath(folderUri: vscode.Uri): Promise<void> {
|
|
|
- const folderPath = vscode.workspace.asRelativePath(folderUri);
|
|
|
- const result = `[${folderPath}]`;
|
|
|
- await vscode.env.clipboard.writeText(result);
|
|
|
- showStatus(`$(clippy) Copied folder: ${folderPath}`);
|
|
|
+export async function copySelectedFiles(selectedUris: vscode.Uri[]): Promise<void> {
|
|
|
+ if (!selectedUris || selectedUris.length === 0) return;
|
|
|
+ await copyFilesFromUris(selectedUris);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Copy files selected in the explorer context menu.
|
|
|
+ * Copy multiple selected files from explorer multi-selection.
|
|
|
*/
|
|
|
-export async function copySelectedFiles(selectedUris: vscode.Uri[]): Promise<void> {
|
|
|
+export async function copyMultiFiles(selectedUris: vscode.Uri[]): Promise<void> {
|
|
|
if (!selectedUris || selectedUris.length === 0) return;
|
|
|
await copyFilesFromUris(selectedUris);
|
|
|
}
|
|
|
@@ -128,45 +116,26 @@ async function collectFilesRecursively(dirUri: vscode.Uri): Promise<vscode.Uri[]
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
-
|
|
|
/**
|
|
|
- * Expand a mixed list of file/directory URIs into a flat list of file URIs.
|
|
|
+ * Read and format multiple files, then copy to clipboard.
|
|
|
*/
|
|
|
-async function expandUris(uris: vscode.Uri[]): Promise<vscode.Uri[]> {
|
|
|
- const result: vscode.Uri[] = [];
|
|
|
+async function copyFilesFromUris(uris: vscode.Uri[]): Promise<void> {
|
|
|
+ const entries: { filePath: string }[] = [];
|
|
|
|
|
|
for (const uri of uris) {
|
|
|
+ let fileUris: vscode.Uri[] = [uri];
|
|
|
+
|
|
|
try {
|
|
|
const stat = await vscode.workspace.fs.stat(uri);
|
|
|
if (stat.type === vscode.FileType.Directory) {
|
|
|
- const children = await collectFilesRecursively(uri);
|
|
|
- result.push(...children);
|
|
|
- } else if (stat.type === vscode.FileType.File) {
|
|
|
- result.push(uri);
|
|
|
+ fileUris = await collectFilesRecursively(uri);
|
|
|
}
|
|
|
} catch {
|
|
|
- // skip inaccessible paths
|
|
|
+ // stat failed, use the uri as-is
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- return result;
|
|
|
-}
|
|
|
|
|
|
-/**
|
|
|
- * Read and format multiple files, then copy to clipboard.
|
|
|
- */
|
|
|
-async function copyFilesFromUris(uris: vscode.Uri[]): Promise<void> {
|
|
|
- const fileUris = await expandUris(uris);
|
|
|
-
|
|
|
- const entries: { filePath: string }[] = [];
|
|
|
-
|
|
|
- for (const uri of fileUris) {
|
|
|
- try {
|
|
|
- await vscode.workspace.openTextDocument(uri);
|
|
|
- const filePath = vscode.workspace.asRelativePath(uri);
|
|
|
- entries.push({ filePath });
|
|
|
- } catch {
|
|
|
- // skip binary or unreadable files
|
|
|
+ for (const fu of fileUris) {
|
|
|
+ entries.push({ filePath: vscode.workspace.asRelativePath(fu) });
|
|
|
}
|
|
|
}
|
|
|
|