Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read and Write file using vs code extension

i am building an extension to parse json using vs code extension. so my need is ,it should be able able to load .json file from a particular folder and iterate through content of the file. Then it should allow user to select few keys from it make a new json file out of this and save it in any folder.

But i am not able to find any way to read and write files in "vs code extension".Could someone please help me.

like image 237
user6639252 Avatar asked Aug 05 '16 06:08

user6639252


People also ask

How do you use an extension in VS Code?

You can browse and install extensions from within VS Code. Bring up the Extensions view by clicking on the Extensions icon in the Activity Bar on the side of VS Code or the View: Extensions command (Ctrl+Shift+X). This will show you a list of the most popular VS Code extensions on the VS Code Marketplace.

What is the text editor in VS Code?

At Epicodus, we use a free text editor called Visual Studio Code. Visual Studio Code, also known as VS Code, was designed with web developers and computer programmers in mind. It includes many useful features that help write and navigate code more efficiently.


1 Answers

If you want to read the current edit state of a file you can use the following API workspace function:

vscode.workspace.openTextDocument(uri).then((document) => {
  let text = document.getText();
});

This will show you the current state of the file including unpersisted changes. document is of type TextDocument and has isDirty set to true if it has pending changes.

like image 192
Steffen Avatar answered Sep 18 '22 12:09

Steffen