Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does Visual Studio Code store the session data (restored opened files)? Is it possible to use a relative path?

If I use Visual Studio Code to open a directory and then open some files and quit, Visual Studio Code will reopen all the files at the next time when it launches.

But there is a problem. It seems Visual Studio Code is not using the relative path for storing this information and does not store this information inside the project directory.

So if I move the directory or rename it, and then open the directory again, for example code projectNewName/, my previous session (opened files/opened editors) are lost. I don't have any idea where this session data is stored and if it is possible to configure it to store a relative path and save the session file inside the project directory, for example, project/.vscode or project/.vscode/session.

If the opened editors session is stored inside a project directory, it will be restored regardless where the directory is and what the directory name is.

like image 535
sgon00 Avatar asked Nov 04 '25 06:11

sgon00


1 Answers

TL;DR: currently, configuration of this path is not supported.

Visual Studio Code stores the states for all the workspaces in its global configuration folder under Code/User/workspaceStorage/. See the path to the settings.json file in this help paragraph for your OS and then just replace the end of the path. For Windows, for example, the settings path is %APPDATA%\Code\User\settings.json, so the state storage is

%APPDATA%/Code/User/workspaceStorage/

In this directory, there are many subdirectories with some hex names. Please, refer to my other answer for a Python script to browse it. Each folder contains a workspace.json with mostly data only referring to the path of the workspace. There are also state.vscdb files in these directories. These are SQLite databases with only one table:

CREATE TABLE ItemTable (key TEXT UNIQUE ON CONFLICT REPLACE, value BLOB);

It is used as a key-value storage for all the state variables like:

workbench.panel.output
{"workbench.panel.output":{"collapsed":false,"isHidden":true}}

As far as I see from Visual Studio Code source, currently only a global path from the environment is used to locate this file:

this.environmentService.workspaceStorageHome
this.environmentService.globalStorageHome

which resolves to

get workspaceStorageHome(): URI {
    return URI.joinPath(this.appSettingsHome, 'workspaceStorage');
}
get globalStorageHome(): URI {
    return URI.joinPath(this.appSettingsHome, 'globalStorage');
}

So, it seems there are currently aren't any options to customize it from the settings.json file.

like image 179
Dima Mironov Avatar answered Nov 07 '25 05:11

Dima Mironov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!