|
|
@@ -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
|
|
|
}
|