Search code examples
visual-studio-code

Where VS Code stores the list of open files?


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.


Solution

  • 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))