I am trying to make a vscode extension and one of the things I am trying to do is create/edit a file when using a specified command. I have the command working.
when I try run the following code using "node test.js", the fs.writeFileSync() method creates the file as expected.
let fs = require('fs');
try {
fs.writeFileSync("test.txt", "Test success!");
} catch (error) {
console.log(error);
}
However when I run my custom command from my "extension.js" file (code below), I see the pop up message "Testing!", but no file is created by the fs.writeFileSync() method. I don't get any errors either. My only guess is that there is an unknown restriction in place that keeps the code from creating files. Does anybody have any ideas how I can get fs.writeFileSync() to work?
const vscode = require('vscode');
let fs = require('fs');
/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
console.log('Congratulations, your extension is now active!');
let disposable = vscode.commands.registerCommand('extension.test', () => {
vscode.window.showInformationMessage('Testing!');
try {
fs.writeFileSync("test.txt", "Test success!");
} catch (error) {
console.log(error);
}
});
context.subscriptions.push(disposable);
}
function deactivate() {}
module.exports = {
activate,
deactivate
}
Thanks in advance, Vectorjon
Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW
Comments
Post a Comment