Переглянути джерело

refactor: output only reference headers, no code content

Developer 1 місяць тому
батько
коміт
58caf1fa7a
2 змінених файлів з 25 додано та 46 видалено
  1. 9 19
      dist/extension.js
  2. 16 27
      src/copyContext.ts

+ 9 - 19
dist/extension.js

@@ -38,23 +38,15 @@ var vscode2 = __toESM(require("vscode"));
 
 // src/copyContext.ts
 var vscode = __toESM(require("vscode"));
-function formatFileContent(filePath, content) {
-  return [
-    `[${filePath}]`,
-    content,
-    ""
-  ].join("\n");
+function formatFileContent(filePath) {
+  return `[${filePath}]`;
 }
-function formatFileSelection(filePath, content, startLine, startCol, endLine, endCol) {
+function formatFileSelection(filePath, startLine, startCol, endLine, endCol) {
   const header = `${filePath} L${startLine}C${startCol}-L${endLine}C${endCol}`;
-  return [
-    `[${header}]`,
-    content,
-    ""
-  ].join("\n");
+  return `[${header}]`;
 }
 function formatMultiFile(entries) {
-  return entries.map((e) => formatFileContent(e.filePath, e.content)).join(" ");
+  return entries.map((e) => formatFileContent(e.filePath)).join("");
 }
 async function copySelection() {
   const editor = vscode.window.activeTextEditor;
@@ -65,12 +57,11 @@ async function copySelection() {
     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);
+  const result = formatFileSelection(filePath, startLine, startCol, endLine, endCol);
   await vscode.env.clipboard.writeText(result);
   showStatus(`$(clippy) Copied ${filePath}:${startLine}-${endLine}`);
 }
@@ -80,8 +71,7 @@ async function copyActiveFile() {
     return;
   const document = editor.document;
   const filePath = vscode.workspace.asRelativePath(document.uri);
-  const content = document.getText();
-  const result = formatFileContent(filePath, content);
+  const result = formatFileContent(filePath);
   await vscode.env.clipboard.writeText(result);
   showStatus(`$(clippy) Copied file: ${filePath}`);
 }
@@ -108,9 +98,9 @@ async function copyFilesFromUris(uris) {
   const entries = [];
   for (const uri of uris) {
     try {
-      const doc = await vscode.workspace.openTextDocument(uri);
+      await vscode.workspace.openTextDocument(uri);
       const filePath = vscode.workspace.asRelativePath(uri);
-      entries.push({ filePath, content: doc.getText() });
+      entries.push({ filePath });
     } catch {
     }
   }

+ 16 - 27
src/copyContext.ts

@@ -1,42 +1,34 @@
 import * as vscode from 'vscode';
 
 /**
- * Format a single file's content as AI context.
- * Output: [path/to/file.ts]\ncontent\n
+ * Format a single file's reference header.
+ * Output: [path/to/file.ts]
  */
-export function formatFileContent(filePath: string, content: string): string {
-  return [
-    `[${filePath}]`,
-    content,
-    '',
-  ].join('\n');
+export function formatFileContent(filePath: string): string {
+  return `[${filePath}]`;
 }
 
 /**
- * Format a selection within a file as AI context.
- * Output: [path/to/file.ts LnCn-LnCn]\ncontent\n
+ * Format a selection's reference header with line/column info.
+ * Output: [path/to/file.ts LnCn-LnCn]
  */
 export function formatFileSelection(
   filePath: string,
-  content: string,
   startLine: number,
   startCol: number,
   endLine: number,
   endCol: number,
 ): string {
   const header = `${filePath} L${startLine}C${startCol}-L${endLine}C${endCol}`;
-  return [
-    `[${header}]`,
-    content,
-    '',
-  ].join('\n');
+  return `[${header}]`;
 }
 
 /**
- * Format multiple file contents, joining with spaces (no newline between files).
+ * Format multiple file references, concatenated without separator.
+ * Output: [file1][file2]...
  */
-export function formatMultiFile(entries: { filePath: string; content: string }[]): string {
-  return entries.map(e => formatFileContent(e.filePath, e.content)).join(' ');
+export function formatMultiFile(entries: { filePath: string }[]): string {
+  return entries.map(e => formatFileContent(e.filePath)).join('');
 }
 
 /**
@@ -51,15 +43,13 @@ export async function copySelection(): Promise<void> {
 
   const document = editor.document;
   const filePath = vscode.workspace.asRelativePath(document.uri);
-  const text = document.getText(selection);
-
   // VS Code selections are 0-indexed for lines, columns are 0-indexed UTF-16 code units
   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);
+  const result = formatFileSelection(filePath, startLine, startCol, endLine, endCol);
 
   await vscode.env.clipboard.writeText(result);
   showStatus(`$(clippy) Copied ${filePath}:${startLine}-${endLine}`);
@@ -74,8 +64,7 @@ export async function copyActiveFile(): Promise<void> {
 
   const document = editor.document;
   const filePath = vscode.workspace.asRelativePath(document.uri);
-  const content = document.getText();
-  const result = formatFileContent(filePath, content);
+  const result = formatFileContent(filePath);
 
   await vscode.env.clipboard.writeText(result);
   showStatus(`$(clippy) Copied file: ${filePath}`);
@@ -112,13 +101,13 @@ export async function copySelectedFiles(selectedUris: vscode.Uri[]): Promise<voi
  * Read and format multiple files, then copy to clipboard.
  */
 async function copyFilesFromUris(uris: vscode.Uri[]): Promise<void> {
-  const entries: { filePath: string; content: string }[] = [];
+  const entries: { filePath: string }[] = [];
 
   for (const uri of uris) {
     try {
-      const doc = await vscode.workspace.openTextDocument(uri);
+      await vscode.workspace.openTextDocument(uri);
       const filePath = vscode.workspace.asRelativePath(uri);
-      entries.push({ filePath, content: doc.getText() });
+      entries.push({ filePath });
     } catch {
       // skip binary or unreadable files
     }