| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- "use strict";
- var __create = Object.create;
- var __defProp = Object.defineProperty;
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
- var __getOwnPropNames = Object.getOwnPropertyNames;
- var __getProtoOf = Object.getPrototypeOf;
- var __hasOwnProp = Object.prototype.hasOwnProperty;
- var __export = (target, all) => {
- for (var name in all)
- __defProp(target, name, { get: all[name], enumerable: true });
- };
- var __copyProps = (to, from, except, desc) => {
- if (from && typeof from === "object" || typeof from === "function") {
- for (let key of __getOwnPropNames(from))
- if (!__hasOwnProp.call(to, key) && key !== except)
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
- }
- return to;
- };
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
- // If the importer is in node compatibility mode or this is not an ESM
- // file that has been converted to a CommonJS file using a Babel-
- // compatible transform (i.e. "__esModule" has not been set), then set
- // "default" to the CommonJS "module.exports" for node compatibility.
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
- mod
- ));
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
- // src/extension.ts
- var extension_exports = {};
- __export(extension_exports, {
- activate: () => activate,
- deactivate: () => deactivate
- });
- module.exports = __toCommonJS(extension_exports);
- var vscode2 = __toESM(require("vscode"));
- // src/copyContext.ts
- var vscode = __toESM(require("vscode"));
- function formatFileContent(filePath) {
- return `[${filePath}]`;
- }
- function formatFileSelection(filePath, startLine, startCol, endLine, endCol) {
- const header = `${filePath} L${startLine}C${startCol}-L${endLine}C${endCol}`;
- return `[${header}]`;
- }
- function formatMultiFile(entries) {
- return entries.map((e) => formatFileContent(e.filePath)).join("");
- }
- async function copySelection() {
- const editor = vscode.window.activeTextEditor;
- if (!editor)
- return;
- const selection = editor.selection;
- if (selection.isEmpty)
- return;
- const document = editor.document;
- const filePath = vscode.workspace.asRelativePath(document.uri);
- const startLine = selection.start.line + 1;
- const startCol = selection.start.character + 1;
- const endLine = selection.end.line + 1;
- const endCol = selection.end.character + 1;
- const result = formatFileSelection(filePath, startLine, startCol, endLine, endCol);
- await vscode.env.clipboard.writeText(result);
- showStatus(`$(clippy) Copied ${filePath}:${startLine}-${endLine}`);
- }
- async function copyActiveFile() {
- const editor = vscode.window.activeTextEditor;
- if (!editor)
- return;
- const document = editor.document;
- const filePath = vscode.workspace.asRelativePath(document.uri);
- const result = formatFileContent(filePath);
- await vscode.env.clipboard.writeText(result);
- showStatus(`$(clippy) Copied file: ${filePath}`);
- }
- async function copyWorkspaceFiles() {
- 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);
- }
- async function copySelectedFiles(selectedUris) {
- if (!selectedUris || selectedUris.length === 0)
- return;
- await copyFilesFromUris(selectedUris);
- }
- async function copyFilesFromUris(uris) {
- const entries = [];
- for (const uri of uris) {
- try {
- await vscode.workspace.openTextDocument(uri);
- const filePath = vscode.workspace.asRelativePath(uri);
- entries.push({ filePath });
- } catch {
- }
- }
- if (entries.length === 0)
- return;
- const result = formatMultiFile(entries);
- await vscode.env.clipboard.writeText(result);
- showStatus(`$(clippy) Copied ${entries.length} file(s)`);
- }
- function showStatus(message) {
- vscode.window.setStatusBarMessage(message, 3e3);
- }
- // src/extension.ts
- function activate(context) {
- console.log("[vsix-cp-ai-ctx] activating...");
- context.subscriptions.push(
- vscode2.commands.registerCommand("vsix-cp-ai-ctx.copySelection", () => {
- copySelection();
- })
- );
- context.subscriptions.push(
- vscode2.commands.registerCommand("vsix-cp-ai-ctx.copyFile", () => {
- copyActiveFile();
- })
- );
- context.subscriptions.push(
- vscode2.commands.registerCommand("vsix-cp-ai-ctx.copyWorkspaceFiles", () => {
- copyWorkspaceFiles();
- })
- );
- context.subscriptions.push(
- vscode2.commands.registerCommand("vsix-cp-ai-ctx.copySelectedFiles", (args) => {
- const selectedResources = args?.selectedResources || [];
- copySelectedFiles(selectedResources);
- })
- );
- console.log("[vsix-cp-ai-ctx] activated");
- }
- function deactivate() {
- }
- // Annotate the CommonJS export names for ESM import in node:
- 0 && (module.exports = {
- activate,
- deactivate
- });
- //# sourceMappingURL=extension.js.map
|