Skip to content

Commit

Permalink
refactor: optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
chouchouji committed Nov 22, 2024
1 parent eca342e commit c21c891
Showing 1 changed file with 3 additions and 27 deletions.
30 changes: 3 additions & 27 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,23 @@
import * as vscode from 'vscode';
import fs from 'node:fs';
import path from 'node:path';

export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(
vscode.commands.registerCommand('copy-filename-pro.copyFileNameWithExtension', (uri: vscode.Uri) => {
const fsPath = uri.fsPath;
fs.stat(fsPath, (err: NodeJS.ErrnoException | null) => {
if (err) {
vscode.window.showErrorMessage(err.message);
return;
}

vscode.env.clipboard.writeText(path.basename(fsPath));
});
vscode.env.clipboard.writeText(path.basename(uri.fsPath));
}),
);

context.subscriptions.push(
vscode.commands.registerCommand('copy-filename-pro.copyFileNameWithoutExtension', (uri: vscode.Uri) => {
const fsPath = uri.fsPath;
fs.stat(fsPath, (err: NodeJS.ErrnoException | null) => {
if (err) {
vscode.window.showErrorMessage(err.message);
return;
}

vscode.env.clipboard.writeText(path.basename(fsPath, path.extname(fsPath)));
});
vscode.env.clipboard.writeText(path.basename(fsPath, path.extname(fsPath)));
}),
);

context.subscriptions.push(
vscode.commands.registerCommand('copy-filename-pro.copyDirectory', (uri: vscode.Uri) => {
const fsPath = uri.fsPath;
fs.stat(fsPath, (err: NodeJS.ErrnoException | null) => {
if (err) {
vscode.window.showErrorMessage(err.message);
return;
}

vscode.env.clipboard.writeText(path.basename(fsPath));
});
vscode.env.clipboard.writeText(path.basename(uri.fsPath));
}),
);
}
Expand Down

0 comments on commit c21c891

Please sign in to comment.