VSCode: "Shell Integration failed to activate" - visual-studio-code

It used to work fine, but recently whenever I run my code (Python), I get the message "Shell Integration failed to activate" when I hover my mouse over the active terminal. The active Python terminal doesn't recognize any command line commands like "pip" anymore (see screenshot)
What can I do? I played around with a couple of settings as described here, but nothing seems to work. My current setting.json file looks like this:
{
"python.defaultInterpreterPath": "C:\\Users\\cleme\\AppData\\Local\\Programs\\Python\\Python310\\python.exe",
"terminal.integrated.profiles.windows": {
"PowerShell": {
"path": "C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe",
"source": "PowerShell",
"icon": "terminal-powershell",
}
},
"terminal.integrated.defaultProfile.windows": "PowerShell"
}

I ended up deleting the whole Code folder within the C:\Users\AppData\Roaming.
Note: You have to check the box - view Hidden Files to see these folders within File Explorer.
This solved it.
There must have been some weird corrupted cache issue at the heart of this.
I found this in C:\Users<profile>\AppData\Roaming\Code\logs<datetimestamp>\ptyhost.log
[2022-10-17 07:25:50.695] [ptyhost] [warning] Couldn't get layout info, a terminal was probably disconnected Could not find pty on pty host
[2022-10-17 07:25:54.040] [ptyhost] [warning] Shell integration cannot be enabled for executable "C:\Windows\System32\cmd.exe" and args []
[2022-10-17 07:26:57.939] [ptyhost] [warning] Shell integration cannot be enabled for executable "C:\Windows\System32\cmd.exe" and args []
I think it is related to this.
BTW: I had tried adding a couple of PowerShell VSCode IDE Extensions when things went awry.
IIRC they were:
PowerShell
PowerShell Preview
I had upgraded PowerShell to the latest version 7 too.
$PSVersionTable yielded the following from the respective executables.
Executable Path
Version
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
5.1.17763.1852
C:\Program Files\PowerShell\7\pwsh.exe
7.2.6
Maybe that combo hosed things
Follow up note: Whilst it seemed to have fixed the issue once... soon after the problem manifested itself again. This time I couldn't reset VS Code to a working environment.
Then I realised had opened the Project folder in the explorer on the left of the IDE.
I had a subfolder that had a PS1 file within that.
It didn't have its own .vscode\settings.json
When I copied it down from the parent folder, suddenly everything worked again.
.vscode\settings.json just contained this:
{
}
Again this ended up being a one time solution.
I ended up back at:
Shell activation failed to activate for cmd.exe
I posted this as a new ticket here
In the end I found this to be more of a display issue than anything else!
You can actually type cls then hit ENTER, to restore things to the status quo.
The Terminal section is black with no prompt to begin with. But you can type in it!!!
Perhaps the Prompt is black text on a black background initally, since when you start typing cls, it's quite a way to the right of the left margin.

Closing VSCode, verifying that powershell works, then reopening it worked for me.

Related

VS Code Not Running Anything - No such file or directory

My VS Code
My VSCode for Mac won't run even simple Python commands. For more context my Python Terminal execute in file dir setting is turned on. I don't know what the problem is, the play button or right clicking and selecting run code also doesn't do anything.
I've already ensured I have the proper VSCode installed for Mac. Please help :(
try to edit your settings.json file like this :
"terminal.explorerKind": "external",
"terminal.integrated.defaultProfile.windows": "Command Prompt"
learn more about using python in VS Code

VS Code Powershell "←]633;P;IsWindows=True"

I am working on a web application using Angular in Vs code.
I ran into some errors while I am fixing them in the process my vscode is bricked after a couple of minutes it return to its normal state but some weird beep sounds raised so i restarted my Laptop.
When I opened VS code again beep sound repeated and my powershell is showing some weird text
So, I thought the error this is due to some misconfigurations in my vscode and I uninstalled VScode ,deleted all related data
After installation the same weird text with beep sounds appeared again
The weird text
←]633;P;IsWindows=True
633;A633;P;Cwd=D:\user\website\quizPS D:\chiru\website\quiz> 633;B
←]633;C```
As #meganrogge said in https://github.com/microsoft/vscode/issues/160419 setting terminal.integrated.shellIntegration.enabled to false fixes this
I had in the settings Terminal > Integrated: Windows Enable Conpty (setting ID terminal.integrated.windowsEnableConpty) disabled. After re-enabling it again (which is the default) the problem went away for me.
Do you have scala sbt installed? it does not work well with ms power shell. On Windows it can be used via git bash for example. Go to your user vs code settings and adjust so following terminal integration will be active
"terminal.integrated.profiles.windows":{"Git Bash":{"path":"C:\\Program Files\\Git\\bin\\bash.exe"}, },
"terminal.integrated.defaultProfile.windows": "Git Bash",
the close your ms power shell tab in vs code terminal panel and add new bash one.
looks like there is a problem with powershell so i reinstalled my powershell it worked
I solved in this way:
Ctrl + Mayus + P
I faced the same issue. I uninstalled VS Code and installed again and the issue was resolved for me

VS Code opens a new debug console every time I build/run

Every time I build or run a program in VSCode a new python debug console is loaded. Before I know it I have 20+ and need to start deleting them. After 32 open consoles I get the error "The terminal process terminated with exit code: 256". I changed the terminal from the default console to git bash recently. How can I stop this?
A way around this issue is to stop VS Code from redundantly printing to the TERMINAL during debugging in the first place. Since it prints to the DEBUG CONSOLE as well, you can use that instead.
Change console to "none" "internalConsole" in each configuration in your project's launch.json file:
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "internalConsole"
}
]
May 2019 Update: the "none" option was replaced by "internalConsole" so I edited my answer to reflect that. Here's the relevant GitHub Issue.
Adding "args": ["&&", "exit"], to launch.json remedies this for Git Bash. Certainly a hack, but I no longer have to manually close many debug terminals.
This may have been resolved in recent debug updates to core VS Code within the last year (as of 8/2022), but I was still seeing this intermittently.
I don't know if this will help the original poster, but I discovered that for me the issue persisted due to using Git Bash as the default terminal in Windows. Switching to Command Prompt as the default terminal fixed the issue. I haven't tested with other platforms or terminals.
Changing the default terminal to Command Prompt causes the Python extension to launch the "Python Debug" terminal with Command Prompt instead of Git Bash. I did log a VS Code/Python Extension defect about this. The initial response is that Git Bash is not officially supported currently.
There appears to be a communication problem between the Git Bash terminals and VS Code that causes this issue. Some of the characters between Git Bash and VS Code get dropped. Sometimes this mangles the debug command and I get and error and have to retry in addition to getting an extra debug window.
There is some additional background info and hacks to fix this from the past in this answer.
Hopefully fixed in the Insiders Build and should be in v1.54. See Debug opens a new integrated terminal for each Python session
. Test it in the Insiders Build if you can and report at the issue if it fixed/did not fix.
Actually you can delete all the instances of the terminal just by clicking on the trash can icon 🗑. If it does not work for the first time, restart the VS Code and try again.

Visual Studio Code - Ctrl+Backspace not working in Integrated Terminal

In the terminal (PowerShell) in Visual Studio Code, I'm trying to hit Ctrl+Backspace to delete last word, but it just adds ^W to end of the line, any ideas how to fix this? It works fine outside Visual Studio Code in PowerShell.
ctrl+backspace is somehow mapped to ctrl+w in vscode integrated terminal (possibly a bug) and now we need to set ctrl+w binding to delete the word explicitly. weird right?
Set-PSReadLineKeyHandler -Chord 'Ctrl+w' -Function BackwardKillWord
Note that this'll work for the current terminal session only.
To make this behaviour persistent, you can set it in profile Microsoft.PowerShell_profile.ps1 file. Create the file if it doesn't exist in your powershell version folder.
C:\Program Files\PowerShell\6\Microsoft.PowerShell_profile.ps1
write at the top
if ($env:TERM_PROGRAM -eq "vscode") {
Set-PSReadLineKeyHandler -Chord 'Ctrl+w' -Function BackwardKillWord
}
See more: Power up your PowerShell
Keybinding references:
https://learn.microsoft.com/en-gb/previous-versions/powershell/module/psreadline/Get-PSReadLineKeyHandler?view=powershell-5.0
https://learn.microsoft.com/en-gb/previous-versions/powershell/module/psreadline/set-psreadlinekeyhandler?view=powershell-5.0
Based on the latest comment https://github.com/microsoft/vscode/issues/68167 I have modified JerryGoyal's answer so we don't have to modify bindings:
Put the following at the top of your Microsoft.PowerShell_profile.ps1 config file (type $profile in the terminal to find it, you might have to create one if it doesn't exist already)
if ($env:TERM_PROGRAM -eq "vscode") {
Set-PSReadLineOption -EditMode Emacs
}
This works for me (vscode 1.43)
It was showing ^W when I pressed Ctrl+Backspace.
Just run this command in the vscode console
Set-PSReadLineOption -EditMode Emacs
NOW IT WORKS!
Looks like an issue that is being tracked: see workbench.action.terminal.deleteWordLeft Doesn't Work, Outputs ^W.
Works fine for me in git bash terminal but not powershell as of vscode 1.36.
vscode v1.45 made some changes to these terminal commands, like deleteWordLeft. Does Ctrl+Backspace work better for you now?
See https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_45.md#removal-of-several-prompt-related-commands
VSCode 1.48 (July2020) might help.
Issue 98404 does allow ctrl+backspace to delete entire word in cmd.exe, which could work for a powershell session too.
See PR 98494:
Before (when it was not working):
After (working):
Check you keybindings in your settings to be sure it is still set.
I have had some oddities with keybindings getting removed / changed when adding a new extension or an update. You may just need to add it back.
Key Bindings for Visual Studio Code
Of course VSCode and PowerShell are two different environments. If you split your terminal window (I do this all the time for my own work use case), you will end up with the VSChost and the standard consolehost and you'll see that though you are in VSCode, they behave differently.
If you have not done so, you may want to customize you VSCode profile which is what the integrated console will read, where as the consolehost will read your PowerShell console profile not you ISE profile.
To add to JerryGoyal answer:
If you have difficulties finding profile folder and/or making it works. Here's what helped me.
I created folder c:\Users\YOUR_USER_NAME\Documents\WindowsPowerShell\
Put Microsoft.PowerShell_profile.ps1 there
Powershell than tells you about security problems. You have to allow this by running powershell as admin.
Than type Set-ExecutionPolicy RemoteSigned.
Answer Y(yes). This is obviously at your own risk!
Add this to keybindings.json in vs code
{
"key": "ctrl+backspace",
"command": "workbench.action.terminal.sendSequence",
"when": "terminalFocus",
"args": { "text": "\u0017" }
},

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.