Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where VS Code stores the list of open files?

Tags:

I'm trying to have synced VS Code instances at work and at home, including the list of open files. I know there are extensions to sync settings, but they do not cover Open Files AFAIK. I do not expect live syncing, under running instance, but if I, say, reboot both machines and start Code on them, I want them identical.

Currently, I have a portable installation of Code on my OneDrive, and I've tried to move AppData\Roaming\Code to OneDrive as well, replacing the actual directories with the symbolic links to this copy.

But still, when I open editor at home it has its own set of Open Files.

I tried to use ProcMon to get an idea where it comes from, I tried to read sources a bit. It seems asking may be easier :-)

Btw, I'm opening in Code git folder of my project. And this folder is located at the same path on both PCs.

like image 206
skaurus Avatar asked Dec 28 '17 20:12

skaurus


People also ask

Where does VS Code store files?

Note: A VS Code "workspace" is usually just your project root folder. Workspace settings as well as debugging and task configurations are stored at the root in a . vscode folder.

How can I see what files are open in VS Code?

Quick file navigation# VS Code provides two powerful commands to navigate in and across files with easy-to-use key bindings. Hold Ctrl and press Tab to view a list of all files open in an editor group.

How do I view recently opened files in Visual Studio?

In Visual Studio 2017 version 15.8 and later, use Go To Recent File to see a list of recently visited files in a solution. Select Edit > Go To > Go To Recent File, or press Ctrl+1, Ctrl+

How do I search all files in VS Code?

VS Code allows you to quickly search over all files in the currently opened folder. Press Ctrl+Shift+F and enter your search term. Search results are grouped into files containing the search term, with an indication of the hits in each file and its location.


2 Answers

I'm pretty sure you're right with AppData\Roaming\Code being the location in question. Specifically:

  • AppData\Roaming\Code\storage.json and in that the windowsState section.
  • AppData\Roaming\Code\Backups\workspaces.json

These files (or at least storage.json) do not get updated until you exit Code (File > Exit). If you are leaving Code open on your work machine and not seeing the changes when you get to your home machine, that might be why you're not seeing the expected.

Code / Atom also stores state information in sqlite3 databases and lots of state information is stored in there:

  • AppData\Roaming\Code\Local Storage\file__0.localstorage

Use an SQLite browser tool such as http://sqlitebrowser.org/ to open it up. You'll see lots of familiar path references in the table ItemTable. The column value shows as "BLOB" (binary) but you can click on any row and export the data to a file. Do this and open up it up in a text editor (e.g. Code! :)) and you'll see it's just a JSON string.

(As VS Code is based on GitHub's Atom editor, searching for issues using "Atom" rather than "Code" often digs up information you might not otherwise find.)

like image 159
Jonathan Avatar answered Oct 22 '22 08:10

Jonathan


I'm totally agree with @Jonathan and want to add a bit more.

For the question, the opened files was stored in file__0.localstorage which is a sqlite file. And I just write a bit of code for extract the list of opened files. Hope it helps.

import sqlite3 import pandas as pd import json  fn = r"C:\Users\HelloWorld\AppData\Roaming\Code\Local Storage\file__0.localstorage" conn = sqlite3.connect(fn) df = pd.read_sql("select key, value as _value from ItemTable", conn) df["v"] = df.pop("_value").map(lambda x: x.decode("utf-16"))  # should be choosen carefully known_file_opened = "numpy" known_file_closed = "aws"  df_check = df[     df.v.str.contains(known_file_opened)     &(~df.v.str.contains(known_file_closed)) ] assert len(df_check) == 1  js = json.loads(df_check.v.iloc[0]) editors = js["groups"][0]["editors"] print("Found %d editors" %(len(editors)))  paths = [] for editor in editors:     js_ = json.loads(editor["value"])     path = js_["resourceJSON"]["fsPath"]     paths.append(path)  print("Found opened file list:\n%s" %(paths)) 
like image 32
kingbase Avatar answered Oct 22 '22 08:10

kingbase