VS Code: Is there some way to associate my debug session to a specific terminal? - visual-studio-code

I'm always working with multiple nodejs projects, and every time I debug a new terminal is opened so I'm constantly getting lost on which terminal corresponds to each debug session.
Is there some way to do something like double clicking the debug session in the call stack and open the terminal it corresponds? Any insight would be greatly appreciated.
Thanks.

Based on my personal experience, looking at all the logs in one terminal makes it more confusing.
I have a better alternative for you, so let say you are debugging A and B projects.
Open A project in one window of VS code and use an integrated terminal
Open B project in another window of VS and use integrated terminal
and so on...
(To open the integrated terminal, Mac: Cmd + j and for Windows: Ctrl+` )

Windows:
Ctrl + Shift + P
Mac:
Cmd + Shift + p
And running those hotkeys type: Terminal: Rename, now you can change the terminal title
You could also add a keyboard shortcut for this command: workbench.action.terminal.rename

in addition to the answers, my approach is isolate the VS by opening different windows for different sessions, and keep the 2 windows on 2 different monitors, for that you need an extra monitor.
when i had 1 monitor, identifying which window corresponded to which was a time waste task and more of distraction. now attaching extra monitor to laptop has saved me a ton of time, organizing windows and switching between became seamless and of course most importantly, productivity and speed increased around 33%.

Related

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 Not Allowing Typing

My VS code terminal was working fine, until one day when I tried to work on a project, that was still open in VS code, my terminal didn't allow me to type any commands. I couldn't type anything. This is the screen that I get.
Okay, for those of you struggling with the same problem, I've managed to solve it by clicking on the drop-down menu that says powershell and changing it to cmd.
this happened to me and simply
close vs code
right click on it
run as administrator
open the terminal and it will work
this problem happened when I changed the default path of CMD
For me, I tried using Powershell/CMD/Bash and I was having errors/blank terminal. I found typing echo hello and pressing CTRL + C made it appear. So in fact, everything was working, my terminal was just blank/glitched out, but was really accepting input.
I had a similar issue when running ionic serve command which runs the development server on the localhost. I paid attention after executing the command above, and it said:
Use Ctrl+C to quit this process
Pressing Ctrl+C then displays:
Terminate batch job (Y/N)?
Type Y or y
then the command prompt is shown again!
Here is a sample terminal window - trimmed for brevity:
For who has this problem using React. This happens when you start a live version using npm start. The terminal that handles the live version of the app cannot be used for anything else.
So to continue using the terminal you need to open a new terminal to use in parallel. To do so just click on the plus icon in the top right corner of the terminal panel then choose the "Power Shell" option. This will open a new terminal without restarting visual studio.
In Mac, when working with Python, this helped me: instead of clicking on the "Run Code" option, click on "Run Python file", in the right corner.
For Ubuntu users this is solved by this solution:
File -> Preferences -> Setting -> Features -> Terminal -> Inherit Env
I found two vscode on my desktop, I opened the other one and it worked. Looks like I updated it but the older one didn't disappear.
If typing Ctrl+C can help to get out of this frozen state, that will be easier to do with VSCode 1.64 (Jan. 2022)
The terminal can type the answer for you.
Terminal -- Auto-reply
The terminal is now able to automatically reply when a specific sequences of characters is received.
A good example of where this is useful, which is also the only default case, is the Windows batch script message Terminate batch job (Y/N)? after hitting Ctrl+C when running a batch script.
This typically just ends up causing problems for the user.
The terminal will now automatically reply with Y and enter (\r) which makes Ctrl+C in Windows feel much better.
Pressing Ctrl+C will immediately reply to the question and return to the prompt:
Theme: Sapphire
The feature was made generically so you can setup custom replies for other thing, just be careful when doing this as you are sending text to the process automatically.
For example you could use it to automatically update Oh My Zsh when prompted:
"terminal.integrated.autoReplies": {
"[Oh My Zsh] Would you like to check for updates? [Y/n]": "Y\r"
}
If you use Clink and enable their similar feature, you can disable it in Clink or in VS Code by setting the reply to null to avoid the two features conflicting with each other:
"terminal.integrated.autoReplies": {
"Terminate batch job (Y/N)": null
}
Go to terminal, preferences, settings.
Check "run code in terminal"
Restart VS.
I changed from bash to powershell in terminal first but the command prompt still not shown.
Then I navigate to File -> Perferences -> Settings and it starts working (command prompt shown)
This seems to just be a display problem. It happened to me when I changed my display settings for desktop icon and app scaling settings.
I managed to fix the problem by simply restarting my computer and re-opening VS code
I had the same problem ... In my case just run vs-code as administrator and works

VS code - 2 split terminal in one (split)

As I'm working with Node.js and Angular, I've currently work with two terminals where I have to switch terminal by the dropdown option.
Is there a way to have two terminals (split) in the same place
like this:
Couldn't find a way.
Update - Visual studio code has this feature starting with version 1.21
Split terminals
The Integrated Terminal can now be split such that multiple are visible at once, which can enable much easier management of terminals when you need a watch and a run command for example:
Open the article to see the GIF demonstration.
Splitting can be done by clicking the split button in the panel, through the context menu or the command Ctrl+Shift + 5.
....
Before VS Code introduced the feature
Inside vs code
You can configure your console to bash or cygwin, and then install and use tmux or screen.
Initial answer before I understood the question intent was to do it inside vs code
Outside vs code
On windows
I'm using Cmder.
It allows opening multiple cmd tabs, and configure more types of command lines / tabs - such as bash, nodejs etc.
On Linux
I got to play a bit with tmux and I heard it's a good option.
Screen shot from google:
On Mac
As Brad stated - tmux works also on Macs, so have a look at the Linux section above.
VSCode has added support to split the integrated terminal in february 2018, as requested by this issue.
At the time it is not yet released, you need to install the Insiders version of VSCode.
You have to set the keybindings yourself, the default are still being discussed here.
As of June 2021, you can select the terminal then enter command: ctrl + shift + 5.

Using "Visual Studio code" with interactive Powershell window like Powershell ISE

I'm new to Visual Studio code so thanks in advance for the help.
I often use the PowerShell ISE with an interactive PowerShell window. I open it, type a few commands, then run a script (such as opening a PowerShell session with Office 365) and then type a few more commands.
Is there any way to do the same thing with Visual Studio code? I see a way to run scripts and debug them but not have them complete but the PowerShell window still stay around so I can continue working.
Decided to convert to answer, since this is a bit too much for comments:
Go to settings > user settings and change "terminal.integrated.shell.windows" to:
"C:\\WINDOWS\\Sysnative\\WindowsPowerShell\\v1.0\\powershell.exe",
Ctrl + Shift + ` opens the terminal. Using the + button on the terminal window you can launch additional powershell instances.
Also there's an extension that allows for launching several different terminals under the same VSCode process (cmd,powershell,bash,etc). Minor nuance, shells are being started with the same permissions VSCode has, but you can re-elevate once inside the shell.
References:
https://code.visualstudio.com/docs/editor/integrated-terminal
https://code.visualstudio.com/docs/customization/userandworkspace
https://github.com/Microsoft/vscode/issues/10893
Edit: but I would say its not really convenient, terminal takes away too much space on the screen (well, unless you have like 2k or 4k display), so I use powershell + vscode.

Sublime Text 3 has integrated terminal?

I normally use the WebStorm IDE for Node.js and FE JavaScript development. However I was thinking of using Sublime Text 3 since I am running out of computing power on a crappy old Macbook Pro and ST3 should be lighter on memory and CPU.
However, my one hangup is that ST3 doesn't seem to have a command line terminal integration possible. I find this to be a very useful feature that's available in Eclipse and WebStorm.
I did some Googling and I don't see any great terminal integration plugins for ST3, is there such a thing or not?
Here is WebStorm with the terminal integrated:
Terminus does this. Supports both Unix and Windows. Works great. 👍
In View (on Windows)
Ctrl + Shift + P --> Terminus: Open Default Shell in Tab (View)
In Panel (on Unix)
Ctrl + Shift + P --> Terminus: Open Default Shell in Panel
Type exit to exit and close the terminal opened in a panel.
I installed the Sublime package TerminalView that can show a terminal window within Sublime in a separate tab.
It works with MacOS or Linux but is no longer actively supported.
Installation:
Open the command palette (Cmd+Shift+P on Mac, Ctrl+Shift+P on Windows) and find Package Control: Install Package
Search for TerminalView and hit Return to install.
The terminal windows has a few flaws (at least on macOS) as it seems to conflict with Sublime's keyboard shortcuts. I however use it only to automatically run unit tests when the edited program code changes. Therefore it works just fine. In that case it works best if I show the terminal window below the text editor. You can do so in the menu View > Layout > Rows: 2.
In sublime 3,
ctrl + shift + p search Package Control: Install Package
Search and install TerminalView
to set shortcuts,
go to Preferences -> Key Bindings
on right side Pane paste this,
[
{ "keys": ["ctrl+shift+t"], "command": "terminal_view_open" }
]
Now ctrl+shift+t is your shortcuts
I prefer Terminus and it's the first cross platform terminal for Sublime Text. Check this video it might help you
I tried Sublime package - TerminalView, quickly realized I couldn't copy paste things. Tried on MacOS.
Terminus(https://github.com/randy3k/Terminus ) looks good to me, it has two options
(i) opens in a tab(view)
(ii) opens also in a panel. (which I prefer most)
The below original answer is now outdated; see below answer by Svish.
I was wondering the same thing a while back, and I believe the answer is: no.
There's no good terminal integration in ST3, except, maybe, for Terminal, which simply takes you to the terminal from any given project folder.
Works ok, but not sure how much it really saves.
No way to have it in the ST3 window AFAIK.