Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode Extension write and open file

My requirement is actually pretty simple, I want to write a file and open it in vscode. But I can't get this to work:

var content = rec[rt.fields[field]];
var filePath = path.join(vscode.workspace.rootPath, selected.label + '.' + field);
fs.writeFileSync(filePath, content, 'utf8');

var openPath = vscode.Uri.parse(filePath);
vscode.workspace.openTextDocument(openPath).then(doc => {
  vscode.window.showTextDocument(doc);
});

I get the following error message and have no idea what that should mean:

cannot open c:%5CUsers%5Cmak%5C.sneditor%5Csoftpointdev1.service-now.com%5CRMCostPlanHelper.js. Detail: No model with uri 'c:%5CUsers%5Cmak%5C.sneditor%5Csoftpointdev1.service-now.com%5CRMCostPlanHelper.js' nor a resolver for the scheme 'c'.

like image 814
makim Avatar asked Dec 13 '16 16:12

makim


1 Answers

I also encountered a similar problem. You can also solve your problem by doing the following:

var content = rec[rt.fields[field]];
var filePath = path.join(vscode.workspace.rootPath, selected.label + '.' + field);
fs.writeFileSync(filePath, content, 'utf8');

var openPath = vscode.Uri.parse("file:///" + filePath); //A request file path
vscode.workspace.openTextDocument(openPath).then(doc => {
  vscode.window.showTextDocument(doc);
});
like image 185
linjing jia Avatar answered Oct 10 '22 06:10

linjing jia