From 2f73749125592eed700c9aebf4a9776a449f4215 Mon Sep 17 00:00:00 2001 From: Flik Jeong Date: Thu, 9 May 2024 14:09:19 +0900 Subject: [PATCH 1/3] [feat] add relative path when copying text --- src/extension.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 29794fa..6c43e85 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,9 +1,8 @@ +import * as path from "path"; import * as vscode from "vscode"; import { generateFileNameComment } from "./utils/generateFileNameComment"; export function activate(context: vscode.ExtensionContext) { - // YOCO.copyTextWithFilePath - // 가장 상단에 `// ${fileName}` 형식의 주석을 추가한 형태로 텍스트를 복사한다. const disposable = vscode.commands.registerCommand("YOCO.copyTextWithFilePath", async () => { const editor = vscode.window.activeTextEditor; if (!editor) { @@ -13,15 +12,22 @@ export function activate(context: vscode.ExtensionContext) { const document = editor.document; const selection = editor.selection; const text = document.getText(selection); - - // settings의 YOCO.includeFilePath가 true일 경우에만 실행 const includeFilePath = vscode.workspace .getConfiguration("YOCO") .get("includeFilePaths", false); - const fileIdentifier = includeFilePath - ? document.uri.path - : document.uri.path.split("/").pop() || "Untitled"; - const comment = generateFileNameComment(document.languageId, fileIdentifier); + + let filePath = document.uri.path; + const workspacePath = vscode.workspace.getWorkspaceFolder(document.uri); + + // 설정이 true일 때만 파일 경로를 포함 + if (includeFilePath && workspacePath) { + const relativePath = path.relative(workspacePath.uri.path, document.uri.fsPath); + filePath = relativePath; + } else { + filePath = document.uri.path.split("/").pop() || "Untitled"; + } + + const comment = generateFileNameComment(document.languageId, filePath); await vscode.env.clipboard.writeText(`${comment}\n${text}`); From f32a799a359f1079af6c71c43b1a3c655bc59ef7 Mon Sep 17 00:00:00 2001 From: Flik Jeong Date: Sat, 11 May 2024 11:05:54 +0900 Subject: [PATCH 2/3] [chore] add 'Run Extension' back to launch.json configuration --- .vscode/launch.json | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index d57a11e..617dc28 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -2,27 +2,17 @@ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 -// { -// "version": "0.2.0", -// "configurations": [ -// { -// "name": "Run Extension", -// "type": "extensionHost", -// "request": "launch", -// "args": [ -// "--extensionDevelopmentPath=${workspaceFolder}" -// ], -// "outFiles": [ -// "${workspaceFolder}/out/**/*.js" -// ], -// "preLaunchTask": "${defaultBuildTask}" -// } -// ] -// } - { "version": "0.2.0", "configurations": [ + { + "name": "Run Extension", + "type": "extensionHost", + "request": "launch", + "args": ["--extensionDevelopmentPath=${workspaceFolder}"], + "outFiles": ["${workspaceFolder}/out/**/*.js"], + "preLaunchTask": "${defaultBuildTask}" + }, { "name": "Extension Tests", "type": "extensionHost", From 370dfc58c2f62c48bc59481a380bf54b0924ee13 Mon Sep 17 00:00:00 2001 From: Flik Jeong Date: Sat, 11 May 2024 15:41:22 +0900 Subject: [PATCH 3/3] [fix] fix wrong cofiguration name --- src/extension.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 6c43e85..002d2b6 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -14,15 +14,14 @@ export function activate(context: vscode.ExtensionContext) { const text = document.getText(selection); const includeFilePath = vscode.workspace .getConfiguration("YOCO") - .get("includeFilePaths", false); + .get("includeFilePath", false); let filePath = document.uri.path; const workspacePath = vscode.workspace.getWorkspaceFolder(document.uri); // 설정이 true일 때만 파일 경로를 포함 if (includeFilePath && workspacePath) { - const relativePath = path.relative(workspacePath.uri.path, document.uri.fsPath); - filePath = relativePath; + filePath = path.relative(workspacePath.uri.path, document.uri.path); } else { filePath = document.uri.path.split("/").pop() || "Untitled"; }