microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.97k stars 29.19k forks source link

Support PowerShell as the default shell on Unix-like platforms #60971

Open mklement0 opened 6 years ago

mklement0 commented 6 years ago

Migrated and generalized from https://github.com/OmniSharp/omnisharp-vscode/issues/2605

It would be great if Visual Studio Code also supported a Unix configuration where PowerShell (Core) is configured as the user's default shell.

Below is an example of where that currently fails: when using an external terminal (as controlled by setting console": "externalTerminal) for debugging, the debugger-invocation command line assumes a POSIX-like shell on Unix, and submits a command using the latter's syntax, which breaks in PowerShell.

There may be other, related cases.

In the debugger-invocation case, only a trivial tweak is required to support PowerShell too (see below).

Steps to reproduce

Desired behavior

Debugger invocation should succeed.

Current behavior

Debugger invocation fails, because the command line sent to the terminal assumes POSIX-like-shell syntax (e.g., bash), which PowerShell doesn't support.

Sample symptom:

PS /Users/jdoe> cd '/Users/jdoe/.vscode/extensions/ms-vscode.csharp-1.16.2/.debugger/';  '/Users/jdoe/.vscode/extensions/ms-vscode.csharp-1.16.2/.debugger/vsdbg' '--interpreter=vscode' '--connection=/var/folders/19/0lxcl7hd63d6fqd813glqppc0000gn/T/CoreFxPipe_vsdbg-ui-9bb838baf07245f591dda2adcfd2536f'
At line:1 char:155
+ ... -vscode.csharp-1.16.2/.debugger/vsdbg' '--interpreter=vscode' '--conn ...
+                                            ~~~~~~~~~~~~~~~~~~~~~~
Unexpected token ''--interpreter=vscode'' in expression or statement.
At line:1 char:178
+ ... ter=vscode' '--connection=/var/folders/19/0lxcl7hd63d6fqd813glqppc000 ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token ''--connection=/var/folders/19/0lxcl7hd63d6fqd813glqppc0000gn/T/CoreFxPipe_vsdbg-ui-9bb838baf07245f591dda2adcfd2536f'' in expression or statement.
+ CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken

With a quoted path to vsdbg, the call would have to be prefixed with to make PowerShell happy.

A pragmatic workaround would be not to quote the vsdbg path, which would make the call succeed in PowerShell too, without special-casing.

This should be safe as long as the user's $HOME path has no embedded spaces - something I've never seen in the Unix world.

weinand commented 5 years ago

Clarification: PowerShell on Unix-like platforms is already supported for VS Code's integrated terminal:

2018-11-07_10-15-01

I'm using these settings to configure the integrated terminal to use PowerShell:

    "terminal.integrated.shell.osx": "/usr/local/bin/powershell",
    "terminal.integrated.shellArgs.osx": []

Without this setting VS Code doesn't know how to preprocess command line arguments correctly.

What you are asking for is to support the same for the "external terminal", e.g. the launch config setting "console": "externalTerminal".

mklement0 commented 5 years ago

Yes, this issue is about the external terminal (as noted in the "Steps to reproduce" section, but I've updated the description at the top to make that clearer).

It's more helpful to debug PowerShell itself in an external terminal, and using an external terminal is the default debug configuration in the PowerShell Core source-code repo.

Two asides: