Skip to content

Commit

Permalink
Fix terminal detection due to VS Code's change in 1.35
Browse files Browse the repository at this point in the history
  • Loading branch information
formulahendry committed Jun 12, 2019
1 parent e46d77f commit 86e6712
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 0.9.11 (2019-06-12)
* [#491](https://github.com/formulahendry/vscode-code-runner/issues/491): Fix terminal detection due to VS Code's change in 1.35

### 0.9.10 (2019-06-02)
* [#484](https://github.com/formulahendry/vscode-code-runner/pull/484): Fix Rust attributes considered as Shebang

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"name": "code-runner",
"displayName": "Code Runner",
"description": "Run C, C++, Java, JS, PHP, Python, Perl, Ruby, Go, Lua, Groovy, PowerShell, CMD, BASH, F#, C#, VBScript, TypeScript, CoffeeScript, Scala, Swift, Julia, Crystal, OCaml, R, AppleScript, Elixir, VB.NET, Clojure, Haxe, Obj-C, Rust, Racket, AutoHotkey, AutoIt, Kotlin, Dart, Pascal, Haskell, Nim, D, Lisp, Kit",
"version": "0.9.10",
"version": "0.9.11",
"publisher": "formulahendry",
"icon": "images/logo.png",
"engines": {
"vscode": "^1.17.0"
"vscode": "^1.35.0"
},
"categories": [
"Programming Languages",
Expand Down
25 changes: 24 additions & 1 deletion src/codeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class CodeManager implements vscode.Disposable {
private _workspaceFolder: string;
private _config: vscode.WorkspaceConfiguration;
private _appInsightsClient: AppInsightsClient;
private _TERMINAL_DEFAULT_SHELL_WINDOWS: string | null = null;

constructor() {
this._outputChannel = vscode.window.createOutputChannel("Code");
Expand Down Expand Up @@ -390,7 +391,10 @@ export class CodeManager implements vscode.Disposable {

private changeExecutorFromCmdToPs(executor: string): string {
if (os.platform() === "win32") {
const windowsShell = vscode.workspace.getConfiguration("terminal").get<string>("integrated.shell.windows");
let windowsShell = vscode.workspace.getConfiguration("terminal").get<string>("integrated.shell.windows");
if (windowsShell === null) {
windowsShell = this.getTerminalDefaultShellWindows();
}
if (windowsShell && windowsShell.toLowerCase().indexOf("powershell") > -1 && executor.indexOf(" && ") > -1) {
let replacement = "; if ($?) {";
executor = executor.replace("&&", replacement);
Expand All @@ -403,6 +407,25 @@ export class CodeManager implements vscode.Disposable {
return executor;
}

/*
Workaround for https://github.com/formulahendry/vscode-code-runner/issues/491
The following code is based on https://github.com/microsoft/vscode-maven/commit/7c1dea723fe91f665c4e624e3bf71a411ceafd93
This is only a fall back to identify the default shell used by VSC.
*/
private getTerminalDefaultShellWindows(): string {
if (!this._TERMINAL_DEFAULT_SHELL_WINDOWS) {
const isAtLeastWindows10 = os.platform() === "win32" && parseFloat(os.release()) >= 10;
const is32ProcessOn64Windows = process.env.hasOwnProperty("PROCESSOR_ARCHITEW6432");
const powerShellPath =
`${process.env.windir}\\${is32ProcessOn64Windows ? "Sysnative" : "System32"}\\WindowsPowerShell\\v1.0\\powershell.exe`;
this._TERMINAL_DEFAULT_SHELL_WINDOWS = isAtLeastWindows10 ? powerShellPath : this.getWindowsShell();
}
return this._TERMINAL_DEFAULT_SHELL_WINDOWS;
}
private getWindowsShell(): string {
return process.env.comspec || "cmd.exe";
}

private changeFilePathForBashOnWindows(command: string): string {
if (os.platform() === "win32") {
const windowsShell = vscode.workspace.getConfiguration("terminal").get<string>("integrated.shell.windows");
Expand Down

0 comments on commit 86e6712

Please sign in to comment.