diff --git a/package.json b/package.json index 9dabefa369..8a3d20e882 100644 --- a/package.json +++ b/package.json @@ -221,6 +221,11 @@ "type": "object", "title": "PowerShell Configuration", "properties": { + "powershell.useX86Host": { + "type": "boolean", + "default": false, + "description": "If true, causes the 32-bit language service to be used on 64-bit Windows. On 32-bit Windows this setting has no effect. This setting does not affect the debugger which has its own architecture configuration." + }, "powershell.scriptAnalysis.enable": { "type": "boolean", "default": true, @@ -228,8 +233,8 @@ }, "powershell.developer.editorServicesHostPath": { "type": "string", - "default": "../bin/Microsoft.PowerShell.EditorServices.Host.exe", - "description": "Specifies the path to the PowerShell Editor Services host executable." + "default": "../bin/", + "description": "Specifies the path to the folder containing the PowerShell Editor Services host executables." }, "powershell.developer.editorServicesLogLevel": { "type": "string", diff --git a/src/main.ts b/src/main.ts index 1146186c17..eec00557b3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,6 +4,7 @@ 'use strict'; +import os = require('os'); import path = require('path'); import vscode = require('vscode'); import settingsManager = require('./settings'); @@ -64,45 +65,57 @@ export function activate(context: vscode.ExtensionContext): void { } }); - let args = []; - if (settings.developer.editorServicesWaitForDebugger) { - args.push('/waitForDebugger'); - } - if (settings.developer.editorServicesLogLevel) { - args.push('/logLevel:' + settings.developer.editorServicesLogLevel) - } - - let serverPath = resolveLanguageServerPath(settings); - let serverOptions = { - run: { - command: serverPath, - args: args - }, - debug: { - command: serverPath, - args: ['/waitForDebugger'] + // The language server is only available on Windows + if (os.platform() == "win32") + { + let args = []; + if (settings.developer.editorServicesWaitForDebugger) { + args.push('/waitForDebugger'); } - }; - - let clientOptions: LanguageClientOptions = { - documentSelector: [PowerShellLanguageId], - synchronize: { - configurationSection: PowerShellLanguageId, - //fileEvents: vscode.workspace.createFileSystemWatcher('**/.eslintrc') + if (settings.developer.editorServicesLogLevel) { + args.push('/logLevel:' + settings.developer.editorServicesLogLevel) } - } - languageServerClient = - new LanguageClient( - 'PowerShell Editor Services', - serverOptions, - clientOptions); + try + { + let serverPath = resolveLanguageServerPath(settings); + let serverOptions = { + run: { + command: serverPath, + args: args + }, + debug: { + command: serverPath, + args: ['/waitForDebugger'] + } + }; + + let clientOptions: LanguageClientOptions = { + documentSelector: [PowerShellLanguageId], + synchronize: { + configurationSection: PowerShellLanguageId, + //fileEvents: vscode.workspace.createFileSystemWatcher('**/.eslintrc') + } + } + + languageServerClient = + new LanguageClient( + 'PowerShell Editor Services', + serverOptions, + clientOptions); - languageServerClient.onReady().then( - () => registerFeatures(), - (reason) => vscode.window.showErrorMessage("Could not start language service: " + reason)); + languageServerClient.onReady().then( + () => registerFeatures(), + (reason) => vscode.window.showErrorMessage("Could not start language service: " + reason)); - languageServerClient.start(); + languageServerClient.start(); + } + catch (e) + { + vscode.window.showErrorMessage( + "The language service could not be started: " + e); + } + } } function registerFeatures() { @@ -128,11 +141,17 @@ function resolveLanguageServerPath(settings: settingsManager.ISettings): string if (editorServicesHostPath) { console.log("Found Editor Services path from config: " + editorServicesHostPath); + // Does the path end in a .exe? Alert the user if so. + if (path.extname(editorServicesHostPath) != '') { + throw "The editorServicesHostPath setting must point to a directory, not a file."; + } + // Make the path absolute if it's not editorServicesHostPath = path.resolve( __dirname, - editorServicesHostPath); + editorServicesHostPath, + getHostExeName(settings.useX86Host)); console.log(" Resolved path to: " + editorServicesHostPath); } @@ -143,10 +162,17 @@ function resolveLanguageServerPath(settings: settingsManager.ISettings): string __dirname, '..', 'bin', - 'Microsoft.PowerShell.EditorServices.Host.exe'); + getHostExeName(settings.useX86Host)); console.log("Using default Editor Services path: " + editorServicesHostPath); } return editorServicesHostPath; } + +function getHostExeName(useX86Host: boolean): string { + // The useX86Host setting is only relevant on 64-bit OS + var is64BitOS = process.env.hasOwnProperty('PROCESSOR_ARCHITEW6432'); + var archText = useX86Host && is64BitOS ? ".x86" : ""; + return "Microsoft.PowerShell.EditorServices.Host" + archText + ".exe"; +} diff --git a/src/settings.ts b/src/settings.ts index 82415b7a8c..610fd426ae 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -17,6 +17,7 @@ export interface IDeveloperSettings { } export interface ISettings { + useX86Host?: boolean, scriptAnalysis?: IScriptAnalysisSettings, developer?: IDeveloperSettings, } @@ -29,12 +30,13 @@ export function load(myPluginId: string): ISettings { }; let defaultDeveloperSettings = { - editorServicesHostPath: "../bin/Microsoft.PowerShell.EditorServices.Host.exe", + editorServicesHostPath: "../bin/", editorServicesLogLevel: "Normal", editorServicesWaitForDebugger: false } return { + useX86Host: configuration.get("useX86Host", false), scriptAnalysis: configuration.get("scriptAnalysis", defaultScriptAnalysisSettings), developer: configuration.get("developer", defaultDeveloperSettings) }