Skip to content

Commit

Permalink
Merge pull request #48 from YOCOING/feat/add-relative-path-option
Browse files Browse the repository at this point in the history
[feat] add relative path option
  • Loading branch information
fliklab authored May 11, 2024
2 parents c346e81 + 370dfc5 commit 3d93544
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 27 deletions.
26 changes: 8 additions & 18 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 14 additions & 9 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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<boolean>("includeFilePaths", false);
const fileIdentifier = includeFilePath
? document.uri.path
: document.uri.path.split("/").pop() || "Untitled";
const comment = generateFileNameComment(document.languageId, fileIdentifier);
.get<boolean>("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}`);

Expand Down

0 comments on commit 3d93544

Please sign in to comment.