Skip to content

Commit de8caf4

Browse files
committed
Merge pull request #110 from PowerShell/daviwil/minor-fixes
Minor bug fixes for 0.5.0
2 parents cda014d + b1083d8 commit de8caf4

File tree

3 files changed

+72
-39
lines changed

3 files changed

+72
-39
lines changed

package.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -221,15 +221,20 @@
221221
"type": "object",
222222
"title": "PowerShell Configuration",
223223
"properties": {
224+
"powershell.useX86Host": {
225+
"type": "boolean",
226+
"default": false,
227+
"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."
228+
},
224229
"powershell.scriptAnalysis.enable": {
225230
"type": "boolean",
226231
"default": true,
227232
"description": "Enables real-time script analysis using PowerShell Script Analyzer."
228233
},
229234
"powershell.developer.editorServicesHostPath": {
230235
"type": "string",
231-
"default": "../bin/Microsoft.PowerShell.EditorServices.Host.exe",
232-
"description": "Specifies the path to the PowerShell Editor Services host executable."
236+
"default": "../bin/",
237+
"description": "Specifies the path to the folder containing the PowerShell Editor Services host executables."
233238
},
234239
"powershell.developer.editorServicesLogLevel": {
235240
"type": "string",

src/main.ts

+62-36
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
'use strict';
66

7+
import os = require('os');
78
import path = require('path');
89
import vscode = require('vscode');
910
import settingsManager = require('./settings');
@@ -64,45 +65,57 @@ export function activate(context: vscode.ExtensionContext): void {
6465
}
6566
});
6667

67-
let args = [];
68-
if (settings.developer.editorServicesWaitForDebugger) {
69-
args.push('/waitForDebugger');
70-
}
71-
if (settings.developer.editorServicesLogLevel) {
72-
args.push('/logLevel:' + settings.developer.editorServicesLogLevel)
73-
}
74-
75-
let serverPath = resolveLanguageServerPath(settings);
76-
let serverOptions = {
77-
run: {
78-
command: serverPath,
79-
args: args
80-
},
81-
debug: {
82-
command: serverPath,
83-
args: ['/waitForDebugger']
68+
// The language server is only available on Windows
69+
if (os.platform() == "win32")
70+
{
71+
let args = [];
72+
if (settings.developer.editorServicesWaitForDebugger) {
73+
args.push('/waitForDebugger');
8474
}
85-
};
86-
87-
let clientOptions: LanguageClientOptions = {
88-
documentSelector: [PowerShellLanguageId],
89-
synchronize: {
90-
configurationSection: PowerShellLanguageId,
91-
//fileEvents: vscode.workspace.createFileSystemWatcher('**/.eslintrc')
75+
if (settings.developer.editorServicesLogLevel) {
76+
args.push('/logLevel:' + settings.developer.editorServicesLogLevel)
9277
}
93-
}
9478

95-
languageServerClient =
96-
new LanguageClient(
97-
'PowerShell Editor Services',
98-
serverOptions,
99-
clientOptions);
79+
try
80+
{
81+
let serverPath = resolveLanguageServerPath(settings);
82+
let serverOptions = {
83+
run: {
84+
command: serverPath,
85+
args: args
86+
},
87+
debug: {
88+
command: serverPath,
89+
args: ['/waitForDebugger']
90+
}
91+
};
92+
93+
let clientOptions: LanguageClientOptions = {
94+
documentSelector: [PowerShellLanguageId],
95+
synchronize: {
96+
configurationSection: PowerShellLanguageId,
97+
//fileEvents: vscode.workspace.createFileSystemWatcher('**/.eslintrc')
98+
}
99+
}
100+
101+
languageServerClient =
102+
new LanguageClient(
103+
'PowerShell Editor Services',
104+
serverOptions,
105+
clientOptions);
100106

101-
languageServerClient.onReady().then(
102-
() => registerFeatures(),
103-
(reason) => vscode.window.showErrorMessage("Could not start language service: " + reason));
107+
languageServerClient.onReady().then(
108+
() => registerFeatures(),
109+
(reason) => vscode.window.showErrorMessage("Could not start language service: " + reason));
104110

105-
languageServerClient.start();
111+
languageServerClient.start();
112+
}
113+
catch (e)
114+
{
115+
vscode.window.showErrorMessage(
116+
"The language service could not be started: " + e);
117+
}
118+
}
106119
}
107120

108121
function registerFeatures() {
@@ -128,11 +141,17 @@ function resolveLanguageServerPath(settings: settingsManager.ISettings): string
128141
if (editorServicesHostPath) {
129142
console.log("Found Editor Services path from config: " + editorServicesHostPath);
130143

144+
// Does the path end in a .exe? Alert the user if so.
145+
if (path.extname(editorServicesHostPath) != '') {
146+
throw "The editorServicesHostPath setting must point to a directory, not a file.";
147+
}
148+
131149
// Make the path absolute if it's not
132150
editorServicesHostPath =
133151
path.resolve(
134152
__dirname,
135-
editorServicesHostPath);
153+
editorServicesHostPath,
154+
getHostExeName(settings.useX86Host));
136155

137156
console.log(" Resolved path to: " + editorServicesHostPath);
138157
}
@@ -143,10 +162,17 @@ function resolveLanguageServerPath(settings: settingsManager.ISettings): string
143162
__dirname,
144163
'..',
145164
'bin',
146-
'Microsoft.PowerShell.EditorServices.Host.exe');
165+
getHostExeName(settings.useX86Host));
147166

148167
console.log("Using default Editor Services path: " + editorServicesHostPath);
149168
}
150169

151170
return editorServicesHostPath;
152171
}
172+
173+
function getHostExeName(useX86Host: boolean): string {
174+
// The useX86Host setting is only relevant on 64-bit OS
175+
var is64BitOS = process.env.hasOwnProperty('PROCESSOR_ARCHITEW6432');
176+
var archText = useX86Host && is64BitOS ? ".x86" : "";
177+
return "Microsoft.PowerShell.EditorServices.Host" + archText + ".exe";
178+
}

src/settings.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface IDeveloperSettings {
1717
}
1818

1919
export interface ISettings {
20+
useX86Host?: boolean,
2021
scriptAnalysis?: IScriptAnalysisSettings,
2122
developer?: IDeveloperSettings,
2223
}
@@ -29,12 +30,13 @@ export function load(myPluginId: string): ISettings {
2930
};
3031

3132
let defaultDeveloperSettings = {
32-
editorServicesHostPath: "../bin/Microsoft.PowerShell.EditorServices.Host.exe",
33+
editorServicesHostPath: "../bin/",
3334
editorServicesLogLevel: "Normal",
3435
editorServicesWaitForDebugger: false
3536
}
3637

3738
return {
39+
useX86Host: configuration.get<boolean>("useX86Host", false),
3840
scriptAnalysis: configuration.get<IScriptAnalysisSettings>("scriptAnalysis", defaultScriptAnalysisSettings),
3941
developer: configuration.get<IDeveloperSettings>("developer", defaultDeveloperSettings)
4042
}

0 commit comments

Comments
 (0)