Visual Studio Code Terminal Exits Immediately - visual-studio-code

When I open the terminal in VS Code, the terminal opens for about half a second, crashes, and outputs this message:
The terminal process "/bin/zsh '-l, '" terminated with exit code: 1.
What could possibly be the cause of this problem. and how do I fix it? I'm using a Mac.

You would want to check your user settings first. Review terminal.integrated settings that could affect the launch.
You're using a Mac, so on macOS, go to Code > Preferences > Settings. In the settings, you may want to search for this:
Just in case you modified settings.json without knowing, you could by typing in #modified or accessing it by Filter Settings (top right) > Modified.
If you did not modified anything, then it may be due to these:
Test your shell directly. Try running your designated integrated terminal shell outside VS Code from an external terminal or command prompt. Some terminal launch failures may be due to your shell installation and are not specific to VS Code. The exit codes displayed come from the shell and you may be able to diagnose shell issues by searching on the internet for the specific shell and exit code.
Use the most recent version of VS Code. Each VS Code monthly release has many updates and fixes and may include integrated terminal improvements. You can check your VS Code version via Help > About (on macOS Code > About Visual Studio Code). To find the latest version of VS Code, go to the VS Code release notes. You may also want to check that you have installed the latest version of your shell.
Use the most recent version of your shell. If your shell is installed separate from your platform, try installing the latest available version of the shell. The same advice applies if you are on an older build of your operating system. For example, some older versions of Windows 10 did not work well with the VS Code terminal.
Enable trace logging. You can enable trace logging and capture a log when launching the terminal. Logging often reveals what is wrong as all arguments used to create the terminal process/pty are recorded. Bad shell names, arguments, or environment variables can cause the terminal to not launch. Keep this log for later if your problem isn't solved.
Exit codes and shells
Search for the specific shells or exit codes in Google (if provided), maybe it would help.
If these still did not help, you may consider searching it in Google (mainly Stackoverflow or github).
Reference link: https://code.visualstudio.com/docs/supporting/troubleshoot-terminal-launch

Related

VS_Code : Shell Integration Failed To Activate

When i hover on my vscode terminal name: (in terminal's upper right corner named "Powershell")
it shows : shell intergartion failed to activate,
how to solve this error, while
I tried installing vs code again but still no change, and also installed powershell 7
There are a few potential solutions for this issue.
Make sure that you have the latest version of VS Code and the Shell Integrate extension installed.
Check that the integrated terminal in VS Code is set to the shell you want to use (e.g. PowerShell, Command Prompt, Bash).
Try running VS Code as an administrator.
If you are using Windows, try adding the path of the shell you want to use (e.g. C:\Windows\System32\bash.exe) to the "terminal.integrated.shell.windows" setting in your VS Code settings.
You can also try reinstalling vscode and the extension.
If none of the above solutions work, you can try searching for specific error messages in the output panel of vscode or in the output of the terminal.

Elixir: VS Code ExUnit cannot find Mix

I cannot load or run my tests, from within VS Code.
I'm a new user to Elixir, and to VS Code. I'm running Lubuntu 21.10 (Impish). I've downloaded Erlang/OTP 25 (.deb), and Elixir 1.14 (precompiled binary in /usr/share/elixir), and can get anything I need running in a Bash terminal. Again, in a standard QTerminal window,
erl, iex, mix, elixir, etc. all work fine.
In VS Code, however, I get some errors. I feel stupid, but I'm coming from Sublime Text, so please forgive me.
In the left pane of VS Code, ExUnit shows an error (red):
Clicking on this error gives me this, on the bottom right pane. The command line options, passed to mix test, seem to be the default configuration:
This result is bizarre to me, because I can open the integrated terminal, execute /bin/sh, and then run the exact mix test line that's displayed:
/usr/share/elixir/bin has been added to my PATH variable, in ~/.bashrc, ~/.profile, and /etc/environment.
However, I am further confused by all tests being excluded, and wonder if there's some connection to the core issue:
Note that I can run my tests just fine, using different command line options. I've tried adding tags, but that didn't fix the problem.
I tried Google'ing this, and played around with my settings. Here is what I have configured in the "User" settings.json, and I made sure nothing overrides this in "Workspace" settings:
Changing the useNativeTesting setting doesn't solve the problem.
On another (?) note, I get a "failed to run elixir" upon VS Code startup:
Again, I have no problem running commands from a Linux terminal, or from a terminal within VS Code.
Plot twist: If I remove the precompiled Elixir 1.14, and downgrade to an older version, via apt, the problem goes away. But Lubuntu 21.10 doesn't offer Elixir 1.14, and I'm really into using the new dbg() feature.
But for now, I cannot load or run my tests, from within VS Code, apparently because Mix cannot be found.
Thanks to Daniel Imms, from the VS Code team, for answering my question on Twitter:
"Try moving where ever you init mix and elixir (.bashrc?) into your .bash_profile and then logging out and in again or restarting. I'm guessing it's in your bashrc which doesn't run in non-interactive sessions like in tasks."

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

How can I get Visual Studio Code to reset the IntelliSense engine for Rust?

I am working on two projects, one is a library, the other is a program that uses that library. When I make changes to the library the other window (the program) doesn't see these changes, so I do not get updated IntelliSense. Closing the program that uses the library and reopening it does force an update but I really prefer not having to go that far.
Answering the title directly and not the root issue...
You can reset IntelliSense and all Rust code features by running the "Rust: Restart the Rust server" command from the command palette (Ctrl+Shift+P).
Progress will be indicated in the status bar.
Still a blunt tool but it will ensure you're in a fresh state without having to restart VS Code entirely.

VSCode Powershell integrated terminal hangs when starting

I am using VSCode version 1.12.2 in Windows 10 x64 build 16193. I am trying to debug Powershell in VSCode, but I cannot get the PowerShell Integrated Terminal working. Every time I started the terminal, here's what I see:
And then it hangs in that stage. I can still debug, start, step in, step out..., but I cannot view my variable or run any expression.
My VSCode is using powershell x64 here:
"terminal.integrated.shell.windows": "C:\\WINDOWS\\Sysnative\\WindowsPowerShell\\v1.0\\powershell.exe"
So this is a known issue with this version of windows 10. Workaround here: https://github.com/PowerShell/vscode-powershell/issues/742
It's possible it's getting stuck on something while loading your profile(s). Try adding this to your settings to skip this:
"powershell.enableProfileLoading": false
I have had a similar problem, it seems. I cannot be sure it is the same, but when I would "load a file with VSCode" (user installer confirmed, system installer unconfirmed), it would hang. The following avenues tested:
Double-clicking on a PS1 file (the association to Code being made)
Starting VsCode empty and then loading the file
Starting VsCode from the command-line with a file-designation parameter
Using the --verbose switch, I got a listing which lead me to believe that VsCode seemed to be checking on updates using NPM (I could be wrong here).
Whatever the underlying problem, I did a lot of prodding and probing, and the cure I found was this.
Delete the directory called C:\Users\YourUserId\.vscode.
This directory is rather large, is not wiped by software removal, and may be corrupted apparently. After deleting it, the problem disappeared.