MVP of a base64-encode command

This commit is contained in:
nyanotech 2022-03-23 10:24:16 +00:00
parent f08e230058
commit 20e5eb7456
Signed by: nyanotech
GPG Key ID: D2D0A9E8F160472B
2 changed files with 20 additions and 23 deletions

View File

@ -10,14 +10,14 @@
"Other" "Other"
], ],
"activationEvents": [ "activationEvents": [
"onCommand:recombobulator.helloWorld" "onCommand:recombobulator.base64"
], ],
"main": "./dist/extension.js", "main": "./dist/extension.js",
"contributes": { "contributes": {
"commands": [ "commands": [
{ {
"command": "recombobulator.helloWorld", "command": "recombobulator.base64",
"title": "Hello World" "title": "base64 encode"
} }
] ]
}, },

View File

@ -1,26 +1,23 @@
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode'; import * as vscode from 'vscode';
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) { export function activate(context: vscode.ExtensionContext) {
console.log('Recombobulator is activated!');
// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
console.log('Congratulations, your extension "recombobulator" is now active!');
// The command has been defined in the package.json file context.subscriptions.push(vscode.commands.registerCommand('recombobulator.base64', () => {
// Now provide the implementation of the command with registerCommand const editor = vscode.window.activeTextEditor;
// The commandId parameter must match the command field in package.json
let disposable = vscode.commands.registerCommand('recombobulator.helloWorld', () => {
// The code you place here will be executed every time your command is executed
// Display a message box to the user
vscode.window.showInformationMessage('Hello World from recombobulator!');
});
context.subscriptions.push(disposable); if (editor) {
const document = editor.document;
const selection = editor.selection;
const text = document.getText(selection);
const processed = Buffer.from(text).toString('base64'); // TODO - handle different character encodings
editor.edit(editBuilder => {
editBuilder.replace(selection, processed);
});
}
vscode.window.showInformationMessage('base64-encoded the selection!');
}));
} }
// this method is called when your extension is deactivated
export function deactivate() {}