extension.js 3.0 KB

1
  1. "use strict";var F=Object.create;var d=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,C=Object.prototype.hasOwnProperty;var S=(e,t)=>{for(var o in t)d(e,o,{get:t[o],enumerable:!0})},m=(e,t,o,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of $(t))!C.call(e,s)&&s!==o&&d(e,s,{get:()=>t[s],enumerable:!(c=P(t,s))||c.enumerable});return e};var y=(e,t,o)=>(o=e!=null?F(b(e)):{},m(t||!e||!e.__esModule?d(o,"default",{value:e,enumerable:!0}):o,e)),T=e=>m(d({},"__esModule",{value:!0}),e);var L={};S(L,{activate:()=>R,deactivate:()=>A});module.exports=T(L);var r=y(require("vscode"));var i=y(require("vscode"));function w(e){return`[${e}]`}function E(e,t,o,c,s){return`[${`${e} L${t}C${o}-L${c}C${s}`}]`}function k(e){return e.map(t=>w(t.filePath)).join("")}async function u(){let e=i.window.activeTextEditor;if(!e)return;let t=e.selection;if(t.isEmpty)return;let o=e.document,c=i.workspace.asRelativePath(o.uri),s=t.start.line+1,n=t.start.character+1,a=t.end.line+1,x=t.end.character+1,g=E(c,s,n,a,x);await i.env.clipboard.writeText(g),p(`$(clippy) Copied ${c}:${s}-${a}`)}async function l(){let e=i.window.activeTextEditor;if(!e)return;let t=e.document,o=i.workspace.asRelativePath(t.uri),c=w(o);await i.env.clipboard.writeText(c),p(`$(clippy) Copied file: ${o}`)}async function v(e){let t=i.workspace.asRelativePath(e),o=`[${t}]`;await i.env.clipboard.writeText(o),p(`$(clippy) Copied: ${t}`)}async function f(e){!e||e.length===0||await U(e)}async function h(e){let t=[],o=await i.workspace.fs.readDirectory(e);for(let[c,s]of o){let n=i.Uri.joinPath(e,c);if(s===i.FileType.Directory){let a=await h(n);t.push(...a)}else s===i.FileType.File&&t.push(n)}return t}async function U(e){let t=[];for(let c of e){let s=[c];try{(await i.workspace.fs.stat(c)).type===i.FileType.Directory&&(s=await h(c))}catch{}for(let n of s)t.push({filePath:i.workspace.asRelativePath(n)})}if(t.length===0)return;let o=k(t);await i.env.clipboard.writeText(o),p(`$(clippy) Copied ${t.length} file(s)`)}function p(e){i.window.setStatusBarMessage(e,3e3)}function M(){let e=r.window.activeTextEditor;if(e&&!e.selection.isEmpty){u();return}if(e){l();return}r.window.activeTextEditor&&l()}function R(e){console.log("[copy-ai-ctx] activating..."),e.subscriptions.push(r.commands.registerCommand("copy-ai-ctx.copySelection",()=>{u()})),e.subscriptions.push(r.commands.registerCommand("copy-ai-ctx.copyFile",()=>{l()})),e.subscriptions.push(r.commands.registerCommand("copy-ai-ctx.copySmart",()=>{M()})),e.subscriptions.push(r.commands.registerCommand("copy-ai-ctx.copySelectedFiles",t=>{if(!t){let o=r.window.activeTextEditor;if(!o)return;v(o.document.uri);return}v(t)})),e.subscriptions.push(r.commands.registerCommand("copy-ai-ctx.copyMultiFiles",(...t)=>{if(t.length<2){let c=r.window.activeTextEditor;if(!c)return;f([c.document.uri]);return}let o=Array.isArray(t[1])?t[1]:t.slice(1);o.length!==0&&f(o)})),console.log("[copy-ai-ctx] activated")}function A(){}0&&(module.exports={activate,deactivate});