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", diff --git a/src/extension.ts b/src/extension.ts index 29794fa..002d2b6 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,21 @@ 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); + .get("includeFilePath", false); + + let filePath = document.uri.path; + const workspacePath = vscode.workspace.getWorkspaceFolder(document.uri); + + // 설정이 true일 때만 파일 경로를 포함 + if (includeFilePath && workspacePath) { + filePath = path.relative(workspacePath.uri.path, document.uri.path); + } else { + filePath = document.uri.path.split("/").pop() || "Untitled"; + } + + const comment = generateFileNameComment(document.languageId, filePath); await vscode.env.clipboard.writeText(`${comment}\n${text}`);