feat: add vscode extension
This commit is contained in:
1 parent
07efeda124
commit
92c08f41f0
7 files changed
+3201
No files matched your search
@@ -0,0 +1,57 @@
|
||||
'use strict';
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import { spawn } from "child_process";
|
||||
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
const htmlToPureRsx = vscode.commands.registerCommand('extension.htmlToRsx', function () {
|
||||
// Get the active text editor
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
|
||||
if (editor) {
|
||||
const document = editor.document;
|
||||
const selection = editor.selection;
|
||||
const word = document.getText(selection);
|
||||
|
||||
const child_proc = spawn("dioxus", ["translate", "-t", word]);
|
||||
|
||||
let result = '';
|
||||
child_proc.stdout?.on('data', data => result += data);
|
||||
|
||||
child_proc.on('close', () => {
|
||||
editor.edit(editBuilder => {
|
||||
if (result != '') {
|
||||
editBuilder.replace(selection, result)
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const htmlToComponent = vscode.commands.registerCommand('extension.htmlToComponent', function () {
|
||||
// Get the active text editor
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
|
||||
if (editor) {
|
||||
const document = editor.document;
|
||||
const selection = editor.selection;
|
||||
const word = document.getText(selection);
|
||||
|
||||
const child_proc = spawn("dioxus", ["translate", "-c", "-t", word]);
|
||||
|
||||
let result = '';
|
||||
child_proc.stdout?.on('data', data => result += data);
|
||||
|
||||
child_proc.on('close', () => {
|
||||
editor.edit(editBuilder => {
|
||||
if (result != '') {
|
||||
editBuilder.replace(selection, result)
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
context.subscriptions.push(htmlToPureRsx);
|
||||
context.subscriptions.push(htmlToComponent);
|
||||
}
|
||||
Reference in new issue
Block a user