Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shell type is detected incorrectly after VSCode update #16175

Closed
mattkellymt opened this issue May 7, 2021 · 19 comments
Closed

Shell type is detected incorrectly after VSCode update #16175

mattkellymt opened this issue May 7, 2021 · 19 comments
Assignees
Labels
area-terminal bug Issue identified by VS Code Team member as probable bug

Comments

@mattkellymt
Copy link

mattkellymt commented May 7, 2021

Error: & was unexpected at this time

Workaround: #16175 (comment)

When I run a python script, without ever changing a setting in vs code after its installation, it uses powershell as the default terminal profile and there is no issue.

image

But when I change the default terminal profile from powershell to command prompt

image
image

I get the "& was unexpected at this time." error

image

I've seen people say I should type ctrl+shift+p then type "select default terminal" to change my terminal from powershell to the command prompt, but this isn't an option in the 2021-05-06 version of Visual Studio Code

image
image

I am using a fresh Windows 10 install with nothing but miniconda and visual studio code.

@mattkellymt mattkellymt added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels May 7, 2021
@Sunillad08
Copy link

I tried changing default terminal to cmd but it still runs .ps1 instead of .bat file for venv . We can manually run .bat file and it will work in cmd.

@mattkellymt
Copy link
Author

mattkellymt commented May 7, 2021

I tried changing default terminal to cmd but it still runs .ps1 instead of .bat file for venv . We can manually run .bat file and it will work in cmd.

When you @Sunillad08 say "we can manually run .bat" are you suggesting that I do this?

@Sunillad08
Copy link

I tried changing default terminal to cmd but it still runs .ps1 instead of .bat file for venv . We can manually run .bat file and it will work in cmd.

When you @Sunillad08 say "we can manually run .bat" are you suggesting that I do this?

Not really , you can run that if you want to work with cmd only . I was just addressing that I got same issue.

@banggua
Copy link

banggua commented May 7, 2021

terminal.integrated.shell.windows works good for me, but terminal.integrated.defaultProfile.windows doesn't.

@skilkis
Copy link

skilkis commented May 8, 2021

Can confirm that this is also the case when using Git Bash as terminal.integrated.shell.windows works while terminal.integrated.defaultProfile.windows does not. According to @brettcannon's answer, Git Bash is not officially supported but I had no issues prior to the introduction of the new terminal settings with VS Code 1.56. To clarify here are my settings:

    "terminal.integrated.defaultProfile.windows": "Git Bash",
    "terminal.integrated.profiles.windows": {
        "Git Bash": {
            "source": "Git Bash",
            "icon": "terminal-bash"
        }
    },
    "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",

Which results in the correct activation command:

$ source c:/Users/MDRyzenPC/Python/numfoil/.venv/Scripts/activate
(.venv) 

Wheras with the terminal.integrated.shell.windows setting omitted the output is:

$ & c:/Users/MDRyzenPC/Python/numfoil/.venv/Scripts/Activate.ps1
bash: syntax error near unexpected token `&'

Therefore, it seems like vscode-python is not using the new settings yet!

@banggua
Copy link

banggua commented May 8, 2021

I disable it by setting "python.terminal.activateEnvironment": false,. I control the activation of the Python environment through .bashrc. I always use python -m venv venv to create a new Python environment in my project, so I add [ -f "venv/Scripts/activate" ] && source venv/Scripts/activate to .bashrc. The important thing is that it works well for me.

vscode settings.json

"python.terminal.activateEnvironment": false,
"terminal.integrated.defaultProfile.windows": "Git Bash",
"terminal.integrated.profiles.windows": {
    "Git Bash": {
        "source": "Git Bash"
    }
},

.bashrc

function pyenv() {
    python -m venv venv
    pyac
    python -m pip install -U pip setuptools
}
function pyac() {
    [ -f "venv/Scripts/activate" ] && source venv/Scripts/activate
}
function pyde() {
    deactivate
}
function pylock() {
    pip freeze >requirements.txt
}
function pyinstall() {
    pip install -r requirements.txt
}
pyac

@asdasd-123
Copy link

Also having this issue since the latest update. Worked fine before the weekend then from launch today I've been getting the issue.

I used the workaround @skilkis showed and that seems to have resolved it for now so would recomend that if anyone else is have trouble

@karthiknadig karthiknadig added area-terminal triage and removed triage-needed Needs assignment to the proper sub-team labels May 10, 2021
@karrtikr
Copy link

Thanks for the bug report! We just wanted to quickly acknowledge we received it and we will triage this as soon as we can. #16169 could be related.

@karrtikr karrtikr added investigating We are looking into the cause of the issue and removed triage labels May 10, 2021
@franneck94
Copy link

Also having this issue since the latest update.

@bshark8
Copy link

bshark8 commented May 11, 2021

Also experiencing issue starting today. Using version 1.56.1

The removal of the entry below in settings.json file will cause the "& was unexpected at this time" issue even though it is marked as deprecated (yellow underline). Adding the entry fixes this issue.

"terminal.integrated.shell.windows": "C:\WINDOWS\System32\cmd.exe",

@karrtikr
Copy link

karrtikr commented May 11, 2021

I can reproduce this issue, thanks! There're 2 bugs:

const shellConfig = this.workspace.getConfiguration('terminal.integrated.shell');

The correct backwards compatible solution would be to read the new setting key first if it exists, and then fallback on the old setting key to support older versions of VSCode.

Related: #16023

@karrtikr karrtikr added needs PR and removed investigating We are looking into the cause of the issue labels May 11, 2021
@karrtikr karrtikr removed their assignment May 11, 2021
@karrtikr karrtikr changed the title & was unexpected at this time. Shell type is detected incorrectly after VSCode update May 11, 2021
@karrtikr karrtikr self-assigned this May 12, 2021
@karrtikr
Copy link

Please try the workaround mentioned here: #16175 (comment)

@ChandlerTayek
Copy link

ChandlerTayek commented May 12, 2021

Please try the workaround mentioned here: #16175 (comment)

Confirming that this workaround worked for git bash.
Steps I took:

  1. Set my default profile to Git Bash.
  2. Then I added "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe" in my .../user/settings.json file.

Worked like a charm thank you @karrtikr and @banggua

@karrtikr
Copy link

Blocked on getting upstream vscode issue fixed microsoft/vscode#121760

@Tyriar
Copy link
Member

Tyriar commented May 12, 2021

We're switching the default priority to always use the shell setting over the default profile if specified microsoft/vscode#123174. Unfortunately there isn't an easy/low risk fix for this other than that workaround.

@karrtikr
Copy link

karrtikr commented May 12, 2021

I have followed up in the original issue. microsoft/vscode#121760 (comment)

@karrtikr
Copy link

karrtikr commented May 14, 2021

Hi everyone 👋 The fix seems to be now available on VSCode insiders. Please try it out and let us know how it goes.

FYI things are better but I'm still having this issue microsoft/vscode#121760 (comment), you may also see it.

@ChandlerTayek
Copy link

@karrtikr I'm able to select different default profiles and have the correct behavior with the insiders build.

@karrtikr
Copy link

Should be fixed in the next stable release of VSCode. Note if you have both settings we prioritize the shell setting for now, #16175 (comment).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-terminal bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests