Where does breakpoints stores - visual-studio-code

In VSCode, where do the breakpoints store?
When I relaunch VSCode, those breakpoints still exists, so there should be a place for VSCode to store them. But it is stored neither in the workspace, nor in .vscode.
I need to know where they store so that I can backup/restore/add/modify/delete multiple breakpoints conveniently and efficiently.

Where are the breakpoints stored?
On Windows, the breakpoints are stored in:
%APPDATA%/Code/User/workspaceStorage/(long_hash)/state.vscdb
On Linux, they are in (per Matt's comment):
$HOME/.config/Code/User/workspaceStorage/(long_hash)/state.vscdb
To locate the (long_hash), I added a breakpoint and looked for a file that was recently modified. If you have Cygwin bash, a command like this works, right after adding or removing a breakpoint:
$ cd $APPDATA/Code
$ find . -mmin -1
The state.vscdb file is a SQLite database. I'm able to pull some data out of it using strings (another Cygwin command):
$ strings state.vscdb | grep 'debug.breakpoint'
debug.breakpoint
debug.breakpoint
debug.breakpoint[{"enabled":true,"uri":{"$mid":1,"fsPath":"d:\\wrk\\learn\\vscode\\cpphello\\helloworld.cpp","_sep":1,"external":"file:///d%3A/wrk/learn/vscode/cpphello/helloworld.cpp","path":"/D:/wrk/learn/vscode/cpphello/helloworld.cpp","scheme":"file"},"lineNumber":12},{"enabled":true,"uri":{"$mid":1,"fsPath":"d:\\wrk\\learn\\vscode\\cpphello\\helloworld.cpp","_sep":1,"external":"file:///d%3A/wrk/learn/vscode/cpphello/helloworld.cpp","path":"/D:/wrk/learn/vscode/cpphello/helloworld.cpp","scheme":"file"},"lineNumber":13}]g
debug.breakpoint[{"enabled":true,"uri":{"$mid":1,"fsPath":"d:\\wrk\\learn\\vscode\\cpphello\\helloworld.cpp","_sep":1,"external":"file:///d%3A/wrk/learn/vscode/cpphello/helloworld.cpp","path":"/D:/wrk/learn/vscode/cpphello/helloworld.cpp","scheme":"file"},"lineNumber":12}]
The above is with a single breakpoint at helloworld.cpp line 12.
Is accessing this file a good idea?
Probably not!
If your goal is to query or manipulate the breakpoints yourself by modifying this file, I'd caution that that risks corrupting VSCode's internal storage (even if using a proper SQLite client).
I recommend instead using the VSCode extension APIs debug.breakpoints and debug.addBreakpoints to query and modify them from within VSCode.

On mac, it's
~/Library/Application Support/Code/User/workspaceStorage/<hash>

Related

How to undo after running sudo code . --user-data-dir='.'?

I was doing the VSCode configuration, but accidentally I saw this command line which I am not sure what it is doing.
However, after running, it always creates the cache data whenever I start my VSCode.
Note: Whenever I typed this command in any directory, it'll automatically shown those folder and file in that directory.
By setting --user-data-dir you're telling VS Code where it should keep your user / session data, which is why it's creating all of those new directories. This is necessary because when you run code as sudo, it doesn't know where your user data directory is, since you're running as a different user. Like this answer says, you probably shouldn't be running code with sudo: VSCode - what exactly --user-data-dir is specifiying. See that answer for suggestions on alternatives.
As for deleting the data it made, just a simple sudo rm -rf <dir> should do the trick (be careful of course).

VS Code Integrated terminal does not execute commands from extensions

Ideally, the integrated VS Code terminal, depending on the context, the type of the folder and the extension, executes some commands. For example, when opening a folder containing a Python virtual environment in VS code, the environment is recognized and activated (by the python extension) by default when opening a new integrated terminal instance (situation 1). This is done by running some command similar to source /path/to/venv/bin/activate.
Or, when using the ROS extension to debug nodes, selecting "Start Debugging (F5)" uses the launch.json file to start some nodes and finally starts debugging the desired code. To do so also, there is some command that is executed (also by he ROS extension, I assume) in the integrated terminal (situation 2) to start the debugging process. In case of debugging ROS nodes, the command usually looks something like /usr/bin/env /bin/sh /tmp/someFileName.
But, unfortunately, both of the above mentioned situations fail. I believe this happens because while the extension tries to run these two commands within their respective integrated terminals, the commands do not actually get executed in either situation. Instead, these commands are printed on the top of the terminal, but the state of the terminal is unchanged (as opposed to when the commands would have been executed, in which case depending on the commands some actions are performed). Here are two images to show what I mean. Top, situation 1 and bottom, situation 2.
The fact that these two commands are printed on top of the terminal as soon as the a new terminal instance is opened tells me that the extension tries to execute them, but they do not work for some unknown reasons.
Just to be clear, both of them are run in a seperate VC Code window, they have nothing to do with each other. When I manually run both the commands in their respective terminals I do get the desired results.
Now, I am unsure exactly how to name this issue. But I think this is surely an issue with the integrated terminal, and not a problem of the extensions. I am not sure how one could reproduce this problem.
I did a clean reinstall of VS code by deleting %APPDATA%\Code and %USERPROFILE%\.vscode. Because I am using this on WSL, there is only ~/.vscode-server on the ubuntu side. I manually uninstalled all extensions on WSL but did not delete this folder, in fear of breaking something. The problem still persisted. I have also created an issue on the VS Code GitHub page with nearly the same information.
I am unsure if this is a bug or is there something wrong with my settings. Does anyone know how I could fix this? For smaller use-cases I can still manually enter the command in the terminal. But I am trying to debug a ROS application with nearly 10 different terminals opening up and I cannot be manually entering the command each time to restart the process.
Please let me know if you need any more information. Many thanks in advance.
Edit: both edits to frame the question properly.
Although not related to WSL, I dug a little deeper today as to why in my case the extension commands were not being executed or were being chopped.
I'm an iTerm2 user. iTerm2 has something called Shell Integrations, which allow iTerm to behave differently under certain circumstances, for example, adding markers to each prompt or coloring output with certain text (e.g. WARNING or ERROR)
From time to time, I also use the VSCode Integrated Terminal, which recently added support for reporting whether the previous command errored out with an indicator on the gutter of the Integrated Terminal panel using the exit code.
iTerm can do something similar but the shell integrations mess up completely the VSCode functionality and therefore I changed my .bashrc file to detect if the terminal emulator was iTerm2 or not (which can be done with the it2check utility of iTerm2) so that it only sourced the shell integrations if I was using iTerm2.
The problem is that it2check "eats" some STDIN bytes using dd, specifically, until it finds an n so that it can obtain the name of the emulator. This of course chops the commands on the STDIN until the first n and makes VSCode Extension Terminal commands unusable
The workaround I came up with is to use the value of "$TERM_PROGRAM" as means to distinguish between the different programs. The only caveat is that the value won't be passed if you're inside of a tmux session or similar, but I can live with that.
In your case, I'd check for any process that is either not passing the STDIN to the WSL process or any dot files or shell profile scripts eating up the STDIN they receive.
I suspect that the real problem is that the local process doesn't relay the STDIN contents to the WSL and as a workaround you may try to create a VSCode Integrated Terminal profile that uses SSH to connect to the WSL host so that the STDIN is preserved

VS Code Terminal command extra first letter

In vs code terminal I'm getting first letter of command twice. it's not causing any problem but it's kind of annoys me to watch the wrong command. I'm not writing any letter twice, the first letter of all commands gets repeated automatically.
as you can see there are 2 commands first one ppython first p automatically got repeated even though i wrote python it makes it ppython. and the first p that got repeated won't delete from there even if i spam backspace so many time . the I tried to clear the command till first p and as I'm not able to remove first p from terminal I just wrote ython in front of it. it looks proper now python. but I got a error response as ython is not recognized command. this same happens with other commands too like cd converts to ccd.
Edit : I Re-installed vs code then but that didn't resolved my problem, when I installed it again all my extensions were there already installed then I deleted vs code again then went to the vs code's location there was a folder name .vscode I deleted that then installed vs code again now all the extensions were deleted from vs code but I'm still having the main problem . that doesn't resolved it. and I'm not getting that error while using other terminals like git bash and I'm getting this error only when I open python file's folder not when I open a react app folder or normal js or other language.
I also tried reseting the default setting from setting.json file as one of the answers suggested but that doesn't worked.
It's hard to answer this without knowing your configuration. What plugins have you installed? Try disabling those related to the terminal emulator one by one to see if they're causing any issues.
In doing this, you would naturally restart the terminal emulator as well. If the problem persists, check if you get this erroneous doubling on a terminal emulator outside of VS Code (Terminal or PowerShell).
If nothing works, try reinstalling the interpreter and also VS Code. Especially the latter, if this seems to affect only the terminal emulator within VS Code.
It's really hard to answer your question without knowing your vs code configuration setting.
The easiest way is you can reset your vs code to default
The Steps
Go to View > Command Palette or press Cmd + Shift + P (macOS) or Ctrl + Shift + P (Windows).
Search for open settings json and select Preferences: Open Settings (JSON) which show ups from the result list.
If you’ve been working with VS Code for a while and installed a lot of things and made a lot of changes, you’ll find there’s a lot of stuff in this file:
Delete everything inside the root braces and save the file
Relaunch your VS Code.
(This step is optional) In case you want to not only reset VS Code but also remove all installed extensions:
Delete the ~/.vscode/extensions folder if you’re on a Mac.
Delete the %USERPROFILE%.vscode\extensions folder if you’re using Windows.

Renaming files doesn't take effect in VScode while using WSL2

I have a very annoying problem in my VScode setup.
I'm using WSL as a terminal to work on my projects and occasionally, mistype the name of one of the folder or file that I'm working with.
For example:
I accidentally created the Mainheader.js file in layout folder (without the capitalized L) therefore, I decided to rename the folder with a capital L.
Now on my React app, any changes made to MainHeader.js file will not be reflected. I did update the related import.
So I decided to delete the entire folder and recreate it with MainHeader.js but this is what I end up with.
The file is there in my folder but when I click on it, I get
"Unable to open Mainheader.js - File not found"
So I try to create it then I get this error:
Unable to create file 'wsl\path]to\MainHeader.js' that already exists when overwrite flag is not set
Has anyone run into this type of behavior in WSL before? It's quite annoying because the only workaround I've found so far is to create a completely different folder with a different name...
Any help would be appreciated. I can't really work like this.
I've been having the same problem for the past 2 days. I presume its a permissions issue, but unfortunately I don't know how to permanently fix it.
I did find this work-around though:
Open a new VS Code window. (I'd recommend closing any VS Code window that had
your project directory open.)
Create a duplicate or copy the contents of the problem file so you don't lose
your code.
Delete the problem file.
Now create the file again using VS Code. Go to File > New Text File. Next paste
in your code.
Now save your new file. Go to File > Save As and save your new file with at the same path + filename + extension that was giving you problems previously. VS Code should allow you to save the new file without any issue.
Now you can open this new VS Code window to your project directory and you should be able to continuing accessing the file that was a problem before.
Basically we just deleted the problem file and then created it again from scratch in a new VS Code window.
Hope this work-around works for you!
EDIT 09/20/2022
Following Baza86's answer here solved the issue for me. Seems like it was a permissions issue of sorts, but if you use the Remote-WSL extension VS code can directly access the linux filesystem.
How to run VScode in sudo mode in WSL2?
You may need add the case option to you options in the wsl config. The default is set to off, however you can set this to off, dir or force.
Open your wsl.conf using sudo with any text editor while running window subsystem Linux. The config file resides in /etc/wsl.conf. This file is used to configure settings per-distribution for Linux distros running on WSL 1 or WSL 2.
My default config looked like this yours may be different:
[automount]
options = "metadata"
add
[automount]
options = "metadata,case=dir"
Here is the official Microsoft docs for Advanced settings configuration in WSL - https://learn.microsoft.com/en-us/windows/wsl/wsl-config

Storing code in Google Drive/DropBox

First I understand I should probably be using GitHub or some other online repository, but I would like to explore some of the concepts necessary for my method to work.
I would like to run a batch script/program every time I close Visual Studio, Eclipse, Notepad. Specifically, I would like to run a copy program to copy all of my source code that I generated with that program to a folder inside a Google Drive/Dropbox folder. That way I know it is saved to the cloud. this way I do not have to set up a special backup extension inside each Development enviornment.
Firstly is there a built in simple solution for doing the above? or Do I need to write a custom service that checks to see when those programs are closed? and if that is the way to go where should I look for an example of how to get started?
Thanks.
No, there is no simple built-in method that will backup the files that you want when you want it.
Instead you could simply point your work directories to your Gdrive or DropBox folders, and create a folder inside them for each.
Or you could create a task that copies the files every 10 minutes or however long.
But if you want it to run only when you exit the programs you specify: Yeah, you'll pretty much need to write a batch file for each of the programs you want to back up. Then call the batch file instead of the program.
startVS.bat
set DropBox=C:\Wherever\
start /wait "" "C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe"
xcopy /s /e /d /y "%userprofile%\Documents\Visual Studio 2008\Projects\*.*" "%DropBox%"
If you want to have the same icon, and for the batch file run minimized:
1) Open Windows Explorer, navigate to startVS.bat, right-click on it, and click Create Shortcut.
2) Right-click on startVS - ShortCut -> Click Rename and rename it Visual Studios, then press [ENTER].
3) Right-Click on the new Visual Studios -> Properties -> Change Icon -> Browse
4) Paste %ProgramFiles% (x86)\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe into the File Name box.
5) Click Open -> OK
6) Click Normal Window -> Minimized -> OK
7) Put a copy of Visual Studios (really named Visual Studios.lnk) where ever you want it, like in the Start menu.
If you are not running a 64 bit system, at step 4 paste %ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe into the File Name box.
I think instead of going for this approach, you can run your script on a timely basis - say every 15 min.
This appraise will have below advantages advantages:
Easy to implement
Tool Independent
Timely Backup
Re-Use
So I think your problem will be solved by this approach.
For Google Drive, I've been messing around with GoogleCL: (I'm on Linux/Crunchbang)
$ sudo apt-get install python-gdata
$ sudo apt-get install googleCL
This'll give you the 'google' command:
$ which google
$ man google
You can upload files:
$ google docs upload foo.txt
(seems to store it as 'foo')
And download it: (in my opinion, syntax is inconsistent)
$ google docs get --title foo
(it won't find foo.txt for some reason)
So far, I'm not that happy with it. I want to encrypt files and park them there,
but it seems to choke on them. I've tried uuencoding them so I can just upload
a text file, but have had inconsistent results on files that aren't all that big
(1.6 Mbytes). Maybe Google doesn't want to deal with files it can't get any search
results out of ? Anyway, maybe Dropbox is better; haven't tried it yet.