fix: extension should respect blocks

This commit is contained in:
Jonathan Kelley committed 2022-04-28 23:59:20 -04:00
1 parent 201dcc144d
commit 4a54934c8e
1 file changed
+14 -9
+14 -9
View File
@@ -64,9 +64,10 @@ export function activate(context: vscode.ExtensionContext) {
// const formatOnSave: string | undefined = vscode.workspace.getConfiguration('rust').get('formatOnSave'); // const formatOnSave: string | undefined = vscode.workspace.getConfiguration('rust').get('formatOnSave');
if (document.languageId === "rust" && document.uri.scheme === "file") { if (document.languageId === "rust" && document.uri.scheme === "file") {
const editor = vscode.window.activeTextEditor;// Get the active text editor const active_editor = vscode.window.activeTextEditor;// Get the active text editor
if (editor) {
const text = editor.document.getText(); if (active_editor?.document.fileName === document.fileName) {
const text = document.getText();
console.error(text); console.error(text);
@@ -83,17 +84,20 @@ export function activate(context: vscode.ExtensionContext) {
} }
child_proc.on('close', () => { child_proc.on('close', () => {
// if (result.length > 0) {
// editor.edit(editBuilder => editBuilder.insert(new vscode.Position(0, 0), result));
// } else {
// console.error("No result");
// }
if (result.length > 0) { if (result.length > 0) {
let decoded: RsxEdit[] = JSON.parse(result); let decoded: RsxEdit[] = JSON.parse(result);
console.log("Decoded edits: ", decoded); console.log("Decoded edits: ", decoded);
editor.edit(editBuilder => { // Get the active text editor
const cur_editor = vscode.window.activeTextEditor;
// even if we build an empty edit stream, it tries to save the editor
// this makes sure the editor is actually saved
if (decoded.length > 0 && cur_editor == active_editor) {
active_editor.edit(editBuilder => {
for (let edit of decoded) { for (let edit of decoded) {
console.log("Handling Edit: ", edit); console.log("Handling Edit: ", edit);
@@ -111,6 +115,7 @@ export function activate(context: vscode.ExtensionContext) {
} }
}) })
} }
}
}); });
child_proc.on('error', (err) => { child_proc.on('error', (err) => {