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

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.

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.

Related

Get file path starting inside workspace folder - vscode

I'm trying to figure out how to get the relative file path starting from the workspace folder. So for example if the workspace folder is called My App and the file path is to the current folder is
file:///c%3A/Users/Bob/Documents/My%20App/backend/connections/server.js
Then I want to be able to store in a variable only backend/connections/server.js so it would exclude the workspace folder with the %20 in it. Currently
vscode.window.activeTextEditor.document.uri;
outputs
file:///c%3A/Users/Bob/Documents/My%20App/backend/connections/server.js.
Is there a method I can call that I'm not using or an easy way to do this without having to do some regex expression?
The short answer: no
Visual Studio Code will does not pass any awareness of itself into the code it hosts. While you can access the $workspaceFolder variable inside Code's launch.json and tasks.json, your code itself doesn't have access to those variables.
And even if it could, as soon as you would move your code outside of your development environment, it would break, as that $workspaceFolder would no longer be there.
If you want to make provisions for doing special stuff while in a dev environment, you'll have to define what you consider the workspace folder to be - there is no way for you to get that dynamically.

File selected in WindowsExplorer with Preview Pane locks the file so powershell cannot output to that file

I have a scheduled script that outputs bunch of HTML files with static names to a remote location. I noticed, that if I have one of those files selected in Windows Explorer so that its contents are shown in Preview Pane, then Powershell cannot overwrite that file and skips updating it.
This only happens if output files are in remote location. Works just fine if files are local.
How do I force PowerShell to overwrite remote files in this situation? Lots of users work with those reports and if one of them leaves Windows Explorer window with one of those files highlighted overnight when the script runs, the file is not going to be updated.
Move HTML files to webserver. You will solve your problem entirely. IIS Setup on windows server is Next, Next, Next. You can leave link to a new file location (https://....) in old place, so users can easily navigate to a new place. Possibly this link can be automated (not sure because of modern security standards)
Try [System.IO.File]::Delete($path) just before writing this file. This removes file entry from filesystem, but leaves file open for those who have it open for now. This makes your script to write to a new file with the same name. Old file exists without name (deleted) but leaves open until everyone close it. Check it actually deleted with resresh!
Try [System.IO.File]::Move($path, $someTrashFullName) just before writing this file. $someTrashFullName probably must be on same drive. Same as Delete, but renames file. Some self-updating software use this strategy. File is renamed, but it's still kept open under new name.
Try replace file with shortcut to some file. You can generate files with different names and change shortcut programmatically
HTML files that change location using js ? They read nearby JSON (generated by export script) and lookup there for a new filename. So user opens static unchanged A.html, JS inside lookups at A.json for new name and redirects user to A-2020-08-11.html. I'm not sure browsers allow reading JSON files from JS for files that opened from network drive.
Only way left is to stop network share or\and close open files server-side.
Maybe some fun with to disable preview in this folder \ completely?
Try with -Force. But to me, it seems to be more a permission issue.
Remove-Item -Path '\\server\share\file' -Force

VS Code don't load the user-data

My problem is that the portable version of visual studio code don't load my settings I had copied from the folder %APPDATA%/code/user.
I loaded the .zip data and extracted the folder. I added a data folder into the extracted folder of VS Code. It's in Visual Studio Code\data. In there i copied the folder "user" from %APPDATA%/code/ and renamed the user folder into "user-data". Then I started code and the usersettings are not loaded.
The command .\code.exe --user-directory .\data\user-data won't work.
Is this a bug or did I do something wrong?
In portable mode, the --user-directory command linte option is ignored.
From the documentation:
--user-data-dir <dir>
Specifies the directory that user data is kept in, useful when running as root. Has no effect in Portable Mode.
Instead, use the default location of user data for a portable install and copy your user data to that directory (from a previous comment it seems like you've already done so successfuly).
For anyone wishing to use a different user data directory when in portable mode, symlink-ing the user data folder should be a viable option if on a linux-like platform.
(Trivia: this was at first reported as bug, after which the documentation was updated, rather making it a feature.)
You can simply create a folder called data in the root folder with
VS Code.
After the startup, the files with standard settings will be
created in the data folder.
Then you can just copy the settings from the folder %AppData%\Code\User to the folder data\user-data\User.
To migrate already installed extensions, copy the contents of the %HomePath%\.vscode\extensions folder to the data\extensions folder.

Change .vscode folder location

I'm programming a client side applications using SharePoint Designer 2013.
I want to change to VSCODE since it supports a lot of extensions for some Javascript library like angular, jQuery. And because of the Chrome/Node.js debugger extension.
But when I try to start any Debugger, I got the error:
Unable to create 'launch.json' file inside the '.vscode' folder (Error: UNKNOWN: unknown error, mkdir '\\servername\DavWWWRoot\sitename\Style Library\.vscode').
I get this error because it's impossible to create a folder in SharePoint where the name starts with dot.
So there's a possibility to change the name of this folder or the file location to any directory in my local computer?
No, it's not possible to move/rename that folder. VS code is a tool that bases project management on folder content. So it is essential that the project settings reside in the folder being managed.
You can move the "extensions" folder, but unfortunately not the argv.json (so the ".vscode" will, at least be recreated on vscode launch)
https://github.com/microsoft/vscode/issues/17691#issuecomment-559234574
I hope that'll finally change sometime .
https://github.com/microsoft/vscode/issues/3884
https://github.com/OmniSharp/omnisharp-roslyn/issues/953

is there an autosave function/plugin for notepad++?

After an unplanned system restart, all of my Notepad++ temp (and unsaved) tabs are gone.
How can I avoid this in future?
I don't want to have to save explicitly every single temp file with a file name.
Is there a plugin for NP++, which saves my session every time I'm editing an active tab or every X minutes?
Or is there an equivalent (and comfortable) editor to NP++, which autostores it's session automatically?
You can find a Notepad++ plugin called AutoSave for autosaving your files here: https://github.com/francostellari/NppPlugins/tree/main/AutoSave
(Used to link to https://sites.google.com/site/fstellari/nppplugins but that's no longer online, cached version is still available here)
It autosaves every minute, but it's configurable, and allows you to choose to save only the current document or all open documents.
From Notepad++ 6.6 or later there are in core and don't need any plugin.
Via menu => Settings => Preferences => Backup => Enable session snapshot and periodic backup
To date, there are two AutoSave plugins available.
To download, click on the Plugins menu and select Plugin Manager (or Plugins Admin). It will pop-up a window with a list of plugins.
Autosave by Franco-stellari —
This autosaves files. Option available to configure timing after autosave, or autosave when npp loses focus.
Autosave2 by www.scout-soft.com - This autosaves files by creating copy of the file. This is useful in case you retain previous saves, such as for incremental development.
Select either of the two AutoSave plugin available and click on Install. If the plugins are not listed, use the links above, and save the .dll to npp's plugins folder according to instructions on the sites.
Update:
in the newest version of Notepad++:
save the plugin's .DLL in Notepad++'s plugins\[plugin name] folder,
go Settings→Import→Import Plugin(s)... and select the .DLL you just saved,
Restart N++. The plugin should appear in the "Plugins" menu.
UPDATE 2022
For those who look for answear on similar question, I`ll try to give detailed description.
I`m personnaly use integrated backup/autosave for Notepad++ which, I think cover any needs for this functionality and better option can be only files versioning tools like git/hg etc.
So...
Go to:
Settings / Preferences / Backup
This will open settings which containe two section:
Session snapshot and periodic backup
Backup on save
First option in first section is Remember current session for next launch:
After enable this, on restart NP++ will be open all session related instances, like opened files, project in projects panel etc, from previous session. But this may did not help if NP++ for some reason was unexpectedly closed(the process freezes, the power supply of the computer is interrupted, etc.) and as result you lost unsaved state of your files.
To partially protect against such an unpleasant accident, you can use the following option: Enable session snapshot and periodic backup:
After enable this, NP++ will after the interval specified in the option Backup in every N seconds, check all open and UNsaved in NP++ files, and save a copy of them with a timestamp in the file name extension(if in Windows explorer display extensions dissabled you can't see timestamp and see only filename wo extension), to the folder specified in the Backup path option.
d:\Temp\ff_stickers.js
d:\SYNCFOLDER\Settings\NP++\backup\ff_stickers.js#2022-04-19_141352
After you save original file, NP++ immediately delete this backup copy.
Also, enabling this option allows you to exit NP++ without saving opened and unsaved files. When you close the NP++, it does not prompt you to save opened and unsaved files, and the next time you open it, it displays them in the same way as before close - marked as unsaved.
Regarding the option Backup path - you cannot change this path,
because it depends on where the NP++ configuration files are stored.
By default, this is the folder backup in same folder where NP++
itself is located. In my case (on my screen), this path is located in
the same place as the configuration files path, specified in the Cloud
option:
Which was added to be able to synchronize NP++ settings.
The next options, already in the second section:
None
Simple backup
Verbose backup
With option Simple backup:
while you save original file in NP++, it will add *.bak file with previous saved state, next to the original:
d:\Temp\ff_stickers.js
d:\Temp\ff_stickers.js.bak
This *.bak remains the only one and is replaced on every save of original file.
With option Verbose backup:
while you save original file in NP++, it will add subfolder nppBackup next to the original file, and save there *.bak file with previous saved state.
d:\Temp\ff_stickers.js
d:\Temp\nppBackup\ff_stickers.js.2022-04-19_141952.bak
These files are not replaced when you save the original, and there are remain as many of them as you save the origanal file.
d:\Temp\ff_stickers.js
d:\Temp\nppBackup\ff_stickers.js.2022-04-19_141952.bak
d:\Temp\nppBackup\ff_stickers.js.2022-04-19_142717.bak
d:\Temp\nppBackup\ff_stickers.js.2022-04-19_142718.bak
d:\Temp\nppBackup\ff_stickers.js.2022-04-19_142719.bak
d:\Temp\nppBackup\ff_stickers.js.2022-04-19_142720.bak
d:\Temp\nppBackup\ff_stickers.js.2022-04-19_142721.bak
d:\Temp\nppBackup\ff_stickers.js.2022-04-19_142722.bak
d:\Temp\nppBackup\ff_stickers.js.2022-04-19_142723.bak
d:\Temp\nppBackup\ff_stickers.js.2022-04-19_142732.bak
And last option Directory, allows you to save *.bak files to a directory of your choice(here you can specify an arbitrary path).
d:\Temp\ff_stickers.js
d:\taravasya\BackUps\NPpp\ff_stickers.js.2022-04-19_143305.bak
Hope it help to use this great app and will save someone a lot of time and nerves))
Update November 2020
Autosave as it should be works on Notepad 32 bit V7.9.1
Before Nov. 2020
The autosave without a backup copy (just save after a time interval or by loosing the focus on the file) seems DEAD as of 2020.
AutoSave In Notepad++
You can enable the AutoSave function in Notepad++ using the below Steps:
Open Notepad++
Open Plugins on Top/ Plugins Admin.
Now Search for AutoSave from the options and Select it
Click on Install, Notepad++ will get restarted
i.e, you can find that plugin under the plugin area on the top.
NB: Just go to the Autosave plugin and enable the time what you want in "Options".
That's it ! COMPLETED