|
|
@@ -0,0 +1,193 @@
|
|
|
+"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 getLanguage(filePath) {
|
|
|
+ const ext = filePath.split(".").pop() ?? "";
|
|
|
+ const langMap = {
|
|
|
+ ts: "typescript",
|
|
|
+ tsx: "typescriptreact",
|
|
|
+ js: "javascript",
|
|
|
+ jsx: "javascriptreact",
|
|
|
+ json: "json",
|
|
|
+ md: "markdown",
|
|
|
+ css: "css",
|
|
|
+ html: "html",
|
|
|
+ py: "python",
|
|
|
+ rs: "rust",
|
|
|
+ go: "go",
|
|
|
+ java: "java",
|
|
|
+ rb: "ruby",
|
|
|
+ php: "php",
|
|
|
+ yml: "yaml",
|
|
|
+ yaml: "yaml",
|
|
|
+ sh: "bash",
|
|
|
+ bash: "bash",
|
|
|
+ sql: "sql",
|
|
|
+ vue: "vue",
|
|
|
+ svelte: "svelte"
|
|
|
+ };
|
|
|
+ return langMap[ext] ?? ext;
|
|
|
+}
|
|
|
+function formatFileContent(filePath, content) {
|
|
|
+ const lang = getLanguage(filePath);
|
|
|
+ return [
|
|
|
+ `[${filePath}]`,
|
|
|
+ "```" + lang,
|
|
|
+ content,
|
|
|
+ "```",
|
|
|
+ ""
|
|
|
+ ].join("\n");
|
|
|
+}
|
|
|
+function formatFileSelection(filePath, content, startLine, startCol, endLine, endCol) {
|
|
|
+ const lang = getLanguage(filePath);
|
|
|
+ const header = `${filePath} L${startLine}C${startCol}-L${endLine}C${endCol}`;
|
|
|
+ return [
|
|
|
+ `[${header}]`,
|
|
|
+ "```" + lang,
|
|
|
+ content,
|
|
|
+ "```",
|
|
|
+ ""
|
|
|
+ ].join("\n");
|
|
|
+}
|
|
|
+function formatMultiFile(entries) {
|
|
|
+ return entries.map((e) => formatFileContent(e.filePath, e.content)).join("\n");
|
|
|
+}
|
|
|
+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 text = document.getText(selection);
|
|
|
+ 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, text, 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 content = document.getText();
|
|
|
+ const result = formatFileContent(filePath, content);
|
|
|
+ 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 {
|
|
|
+ const doc = await vscode.workspace.openTextDocument(uri);
|
|
|
+ const filePath = vscode.workspace.asRelativePath(uri);
|
|
|
+ entries.push({ filePath, content: doc.getText() });
|
|
|
+ } 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
|