sgon00
sgon00

Reputation: 5777

vscode: Where stores the session data (restored opened files)? Is that possible to use relative path?

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

But there is a problem. It seems vscode is not using relative path for storing this info and does not store this info 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 have no idea where this session data stores and if it is possible to configure it to store 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.

Upvotes: 3

Views: 2772

Answers (1)

Dima Mironov
Dima Mironov

Reputation: 575

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

VSCode stores the states for all the workspaces, in its global config folder under /Code/User/workspaceStorage/. See the path to the settings.json 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 another 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 VSCode 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 no options to customize it from the settings.json.

Upvotes: 6

Related Questions