Skip to content

Various fixes for 64-bit VS Code #1021

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

Merged
merged 6 commits into from
Sep 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ vscode-powershell.zip
vscps-preview.zip
*.vsix
npm-debug.log
.vscode-test/
15 changes: 13 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"args": [ "--extensionDevelopmentPath=${workspaceRoot}" ],
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/out"],
"outFiles": ["${workspaceRoot}/out/src/**/*.js"],
"preLaunchTask": "BuildAll"
},
{
Expand All @@ -20,7 +20,18 @@
"args": [ "--extensionDevelopmentPath=${workspaceRoot}" ],
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/out"],
"outFiles": ["${workspaceRoot}/out/src/**/*.js"],
"preLaunchTask": "Build"
},
{
"name": "Launch Extension Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test" ],
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/out/test/**/*.js"],
"preLaunchTask": "Build"
},
{
Expand Down
36 changes: 30 additions & 6 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"version": "2.0.0",

"windows": {
"command": "${env:windir}\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe",
"command": "${env:windir}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"args": [ "-NoProfile", "-ExecutionPolicy", "Bypass" ]
},
"linux": {
Expand All @@ -20,28 +20,52 @@
{
"taskName": "Install",
"suppressTaskName": true,
"args": [ "Invoke-Build Restore" ]
"args": [
"Invoke-Build Restore"
]
},
{
"taskName": "CleanAll",
"suppressTaskName": true,
"args": [ "Invoke-Build CleanAll" ]
"args": [
"Invoke-Build CleanAll"
]
},
{
"taskName": "Clean",
"suppressTaskName": true,
"args": [ "Invoke-Build Clean" ]
"args": [
"Invoke-Build Clean"
]
},
{
"taskName": "BuildAll",
"suppressTaskName": true,
"isBuildCommand": true,
"args": [ "Invoke-Build BuildAll" ]
"args": [
"Invoke-Build BuildAll"
],
"problemMatcher": []
},
{
"taskName": "Build",
"suppressTaskName": true,
"args": [ "Invoke-Build Build" ]
"args": [
"Invoke-Build Build"
],
"problemMatcher": []
},
{
"taskName": "Test",
"suppressTaskName": true,
"args": [
"Invoke-Build Test"
],
"group": {
"kind": "test",
"isDefault": true
},
"problemMatcher": []
}
]
}
3 changes: 3 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.vscode/**
.vscode-test/**
vscode-powershell.build.ps1
typings/**
**/*.ts
Expand All @@ -10,5 +11,7 @@ bin/DebugAdapter.log
bin/*.vshost.*
bin/PowerShell/**
logs/**
out/test/**
test/**
sessions/**
scripts/Install-VSCode.ps1
2 changes: 1 addition & 1 deletion examples/.vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

// Start PowerShell
"windows": {
"command": "${env:windir}\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe",
"command": "${env:windir}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"args": [ "-NoProfile", "-ExecutionPolicy", "Bypass" ]
},
"linux": {
Expand Down
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@
"type": "git",
"url": "https://github.com/PowerShell/vscode-powershell.git"
},
"main": "./out/main",
"main": "./out/src/main",
"activationEvents": [
"onLanguage:powershell",
"onCommand:PowerShell.NewProjectFromTemplate",
"onCommand:PowerShell.OpenExamplesFolder",
"onCommand:PowerShell.StartDebugSession",
"onCommand:PowerShell.PickPSHostProcess",
"onCommand:PowerShell.SpecifyScriptArgs",
"onCommand:PowerShell.ShowSessionConsole"
"onCommand:PowerShell.ShowSessionConsole",
"onCommand:PowerShell.ShowSessionMenu",
"onCommand:PowerShell.RestartSession"
],
"dependencies": {
"vscode-languageclient": "3.3.0-alpha.6"
Expand All @@ -41,15 +43,18 @@
"@types/node": "^6.0.40",
"typescript": "^2.0.3",
"vsce": "^1.18.0",
"vscode": "^1.1.0"
"vscode": "^1.1.0",
"mocha": "^2.3.3",
"@types/mocha": "^2.2.32"
},
"extensionDependencies": [
"vscode.powershell"
],
"scripts": {
"compile": "tsc -p ./",
"compile-watch": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install"
"postinstall": "node ./node_modules/vscode/bin/install",
"test": "node ./node_modules/vscode/bin/test"
},
"contributes": {
"keybindings": [
Expand Down Expand Up @@ -188,7 +193,7 @@
"powershell"
]
},
"program": "./out/debugAdapter.js",
"program": "./out/src/debugAdapter.js",
"runtime": "node",
"variables": {
"PickPSHostProcess": "PowerShell.PickPSHostProcess",
Expand Down
2 changes: 1 addition & 1 deletion src/debugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Logger } from './logging';
// named pipes or a network protocol). It is purely a naive data
// relay between the two transports.

var logBasePath = path.resolve(__dirname, "../logs");
var logBasePath = path.resolve(__dirname, "../../logs");

var debugAdapterLogWriter =
fs.createWriteStream(
Expand Down
2 changes: 1 addition & 1 deletion src/features/Examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class ExamplesFeature implements IFeature {
private examplesPath: string;

constructor() {
this.examplesPath = path.resolve(__dirname, "../../examples");
this.examplesPath = path.resolve(__dirname, "../../../examples");
this.command = vscode.commands.registerCommand('PowerShell.OpenExamplesFolder', () => {
vscode.commands.executeCommand(
"vscode.openFolder",
Expand Down
2 changes: 1 addition & 1 deletion src/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class Logger {
constructor() {
this.logChannel = vscode.window.createOutputChannel("PowerShell Extension Logs");

this.logBasePath = path.resolve(__dirname, "../logs");
this.logBasePath = path.resolve(__dirname, "../../logs");
utils.ensurePathExists(this.logBasePath);

this.commands = [
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function checkForUpdatedVersion(context: vscode.ExtensionContext) {
if (choice === showReleaseNotes) {
vscode.commands.executeCommand(
'markdown.showPreview',
vscode.Uri.file(path.resolve(__dirname, "../CHANGELOG.md")));
vscode.Uri.file(path.resolve(__dirname, "../../CHANGELOG.md")));
}
});
}
Expand Down
171 changes: 171 additions & 0 deletions src/platform.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/

import fs = require('fs');
import os = require('os');
import path = require('path');
import vscode = require('vscode');
import process = require('process');
import Settings = require('./settings');

export enum OperatingSystem {
Unknown,
Windows,
MacOS,
Linux
}

export interface PlatformDetails {
operatingSystem: OperatingSystem
isOS64Bit: boolean
isProcess64Bit: boolean
}

export interface PowerShellExeDetails {
versionName: string;
exePath: string;
}

export function getPlatformDetails(): PlatformDetails {
var operatingSystem = OperatingSystem.Unknown;

if (process.platform === "win32") {
operatingSystem = OperatingSystem.Windows;
}
else if (process.platform === "darwin") {
operatingSystem = OperatingSystem.MacOS;
}
else if (process.platform === "linux") {
operatingSystem = OperatingSystem.Linux;
}

let isProcess64Bit = process.arch === "x64";

return {
operatingSystem: operatingSystem,
isOS64Bit: isProcess64Bit || process.env.hasOwnProperty('PROCESSOR_ARCHITEW6432'),
isProcess64Bit: isProcess64Bit
}
}

export function getDefaultPowerShellPath(
platformDetails: PlatformDetails,
use32Bit: boolean = false): string | null {

var powerShellExePath = undefined;

// Find the path to powershell.exe based on the current platform
// and the user's desire to run the x86 version of PowerShell
if (platformDetails.operatingSystem == OperatingSystem.Windows) {
if (use32Bit) {
powerShellExePath =
platformDetails.isOS64Bit && platformDetails.isProcess64Bit
? SysWow64PowerShellPath
: System32PowerShellPath
}
else {
powerShellExePath =
!platformDetails.isOS64Bit || platformDetails.isProcess64Bit
? System32PowerShellPath
: SysnativePowerShellPath
}
}
else if (platformDetails.operatingSystem == OperatingSystem.MacOS) {
powerShellExePath = "/usr/local/bin/powershell";
}
else if (platformDetails.operatingSystem == OperatingSystem.Linux) {
powerShellExePath = "/usr/bin/powershell";
}

return powerShellExePath;
}

export function getWindowsSystemPowerShellPath(systemFolderName: string) {
return `${process.env.windir}\\${systemFolderName}\\WindowsPowerShell\\v1.0\\powershell.exe`
}

export const System32PowerShellPath = getWindowsSystemPowerShellPath('System32');
export const SysnativePowerShellPath = getWindowsSystemPowerShellPath('Sysnative');
export const SysWow64PowerShellPath = getWindowsSystemPowerShellPath('SysWow64');

export const WindowsPowerShell64BitLabel = "Windows PowerShell (x64)";
export const WindowsPowerShell32BitLabel = "Windows PowerShell (x86)";

const powerShell64BitPathOn32Bit = SysnativePowerShellPath.toLocaleLowerCase();
const powerShell32BitPathOn64Bit = SysWow64PowerShellPath.toLocaleLowerCase();

export function fixWindowsPowerShellPath(powerShellExePath: string, platformDetails: PlatformDetails): string {
let lowerCasedPath = powerShellExePath.toLocaleLowerCase();

if ((platformDetails.isProcess64Bit && (lowerCasedPath === powerShell64BitPathOn32Bit)) ||
(!platformDetails.isProcess64Bit && (lowerCasedPath === powerShell32BitPathOn64Bit))) {
return System32PowerShellPath;
}

// If the path doesn't need to be fixed, return the original
return powerShellExePath;
}

export function getAvailablePowerShellExes(platformDetails: PlatformDetails): PowerShellExeDetails[] {

var paths: PowerShellExeDetails[] = [];

if (platformDetails.operatingSystem === OperatingSystem.Windows) {
const psCoreInstallPath =
(!platformDetails.isProcess64Bit ? process.env.ProgramW6432 : process.env.ProgramFiles) + '\\PowerShell';

if (platformDetails.isProcess64Bit) {
paths.push({
versionName: WindowsPowerShell64BitLabel,
exePath: System32PowerShellPath
})

paths.push({
versionName: WindowsPowerShell32BitLabel,
exePath: SysWow64PowerShellPath
})
}
else {
if (platformDetails.isOS64Bit) {
paths.push({
versionName: WindowsPowerShell64BitLabel,
exePath: SysnativePowerShellPath
})
}

paths.push({
versionName: WindowsPowerShell32BitLabel,
exePath: System32PowerShellPath
})
}

if (fs.existsSync(psCoreInstallPath)) {
var psCorePaths =
fs.readdirSync(psCoreInstallPath)
.map(item => path.join(psCoreInstallPath, item))
.filter(item => fs.lstatSync(item).isDirectory())
.map(item => {
return {
versionName: `PowerShell Core ${path.parse(item).base}`,
exePath: path.join(item, "powershell.exe")
};
});

if (psCorePaths) {
paths = paths.concat(psCorePaths);
}
}
}
else {
paths.push({
versionName: "PowerShell Core",
exePath:
os.platform() === "darwin"
? "/usr/local/bin/powershell"
: "/usr/bin/powershell"
});
}

return paths;
}
4 changes: 2 additions & 2 deletions src/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class PowerShellProcess {
let startScriptPath =
path.resolve(
__dirname,
'../scripts/Start-EditorServices.ps1');
'../../scripts/Start-EditorServices.ps1');

var editorServicesLogPath = this.log.getLogFilePath(logFileName);

Expand Down Expand Up @@ -77,7 +77,7 @@ export class PowerShellProcess {
// NOTE: This batch file approach is needed temporarily until VS Code's
// createTerminal API gets an argument for setting environment variables
// on the launched process.
var batScriptPath = path.resolve(__dirname, '../sessions/powershell.bat');
var batScriptPath = path.resolve(__dirname, '../../sessions/powershell.bat');
fs.writeFileSync(
batScriptPath,
`@set DEVPATH=${path.dirname(powerShellExePath)}\r\n@${powerShellExePath} %*`);
Expand Down
Loading