From dca434fac45c9efdfa521b2fae0da97f966310ce Mon Sep 17 00:00:00 2001 From: David Wilson Date: Wed, 9 Mar 2016 14:14:46 -0800 Subject: [PATCH 1/2] Fix #106: Don't start LanguageClient on non-Win OS This change causes the LanguageClient class to not be created on non-Windows OSes (specifically OS X and Linux). Previously this had not caused a major issue for users on OS X but it eventually became apparent that VS Code's default word-based completion engine did not work for OS X users because we were still registering our completion provider even though it was not able to execute on that OS. --- src/main.ts | 71 ++++++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/src/main.ts b/src/main.ts index 1146186c17..4e8ff72521 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,49 @@ 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'); } - }; + 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'] + } + }; - let clientOptions: LanguageClientOptions = { - documentSelector: [PowerShellLanguageId], - synchronize: { - configurationSection: PowerShellLanguageId, - //fileEvents: vscode.workspace.createFileSystemWatcher('**/.eslintrc') + let clientOptions: LanguageClientOptions = { + documentSelector: [PowerShellLanguageId], + synchronize: { + configurationSection: PowerShellLanguageId, + //fileEvents: vscode.workspace.createFileSystemWatcher('**/.eslintrc') + } } - } - languageServerClient = - new LanguageClient( - 'PowerShell Editor Services', - serverOptions, - clientOptions); + 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(); + } } function registerFeatures() { From b1083d80e50114dd93a7e7f66d5a8988133ecfa9 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Wed, 9 Mar 2016 16:44:15 -0800 Subject: [PATCH 2/2] Add useX86Host setting for language service This change adds a new 'useX86Host' setting for the language service which causes the 32-bit host to be launched in 64-bit Windows. Part of the solution for #55. --- package.json | 9 ++++-- src/main.ts | 79 +++++++++++++++++++++++++++++++------------------ src/settings.ts | 4 ++- 3 files changed, 60 insertions(+), 32 deletions(-) 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 4e8ff72521..eec00557b3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -76,37 +76,45 @@ export function activate(context: vscode.ExtensionContext): void { args.push('/logLevel:' + settings.developer.editorServicesLogLevel) } - 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') + 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 = + 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); + } } } @@ -133,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); } @@ -148,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) }