Skip to content

Commit 34af8bd

Browse files
committed
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.
1 parent 5ec9425 commit 34af8bd

File tree

3 files changed

+60
-32
lines changed

3 files changed

+60
-32
lines changed

package.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,20 @@
206206
"type": "object",
207207
"title": "PowerShell Configuration",
208208
"properties": {
209+
"powershell.useX86Host": {
210+
"type": "boolean",
211+
"default": false,
212+
"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."
213+
},
209214
"powershell.scriptAnalysis.enable": {
210215
"type": "boolean",
211216
"default": true,
212217
"description": "Enables real-time script analysis using PowerShell Script Analyzer."
213218
},
214219
"powershell.developer.editorServicesHostPath": {
215220
"type": "string",
216-
"default": "../bin/Microsoft.PowerShell.EditorServices.Host.exe",
217-
"description": "Specifies the path to the PowerShell Editor Services host executable."
221+
"default": "../bin/",
222+
"description": "Specifies the path to the folder containing the PowerShell Editor Services host executables."
218223
},
219224
"powershell.developer.editorServicesLogLevel": {
220225
"type": "string",

src/main.ts

+50-29
Original file line numberDiff line numberDiff line change
@@ -76,37 +76,45 @@ export function activate(context: vscode.ExtensionContext): void {
7676
args.push('/logLevel:' + settings.developer.editorServicesLogLevel)
7777
}
7878

79-
let serverPath = resolveLanguageServerPath(settings);
80-
let serverOptions = {
81-
run: {
82-
command: serverPath,
83-
args: args
84-
},
85-
debug: {
86-
command: serverPath,
87-
args: ['/waitForDebugger']
88-
}
89-
};
90-
91-
let clientOptions: LanguageClientOptions = {
92-
documentSelector: [PowerShellLanguageId],
93-
synchronize: {
94-
configurationSection: PowerShellLanguageId,
95-
//fileEvents: vscode.workspace.createFileSystemWatcher('**/.eslintrc')
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+
}
9699
}
97-
}
98100

99-
languageServerClient =
100-
new LanguageClient(
101-
'PowerShell Editor Services',
102-
serverOptions,
103-
clientOptions);
101+
languageServerClient =
102+
new LanguageClient(
103+
'PowerShell Editor Services',
104+
serverOptions,
105+
clientOptions);
104106

105-
languageServerClient.onReady().then(
106-
() => registerFeatures(),
107-
(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));
108110

109-
languageServerClient.start();
111+
languageServerClient.start();
112+
}
113+
catch (e)
114+
{
115+
vscode.window.showErrorMessage(
116+
"The language service could not be started: " + e);
117+
}
110118
}
111119
}
112120

@@ -133,11 +141,17 @@ function resolveLanguageServerPath(settings: settingsManager.ISettings): string
133141
if (editorServicesHostPath) {
134142
console.log("Found Editor Services path from config: " + editorServicesHostPath);
135143

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+
136149
// Make the path absolute if it's not
137150
editorServicesHostPath =
138151
path.resolve(
139152
__dirname,
140-
editorServicesHostPath);
153+
editorServicesHostPath,
154+
getHostExeName(settings.useX86Host));
141155

142156
console.log(" Resolved path to: " + editorServicesHostPath);
143157
}
@@ -148,10 +162,17 @@ function resolveLanguageServerPath(settings: settingsManager.ISettings): string
148162
__dirname,
149163
'..',
150164
'bin',
151-
'Microsoft.PowerShell.EditorServices.Host.exe');
165+
getHostExeName(settings.useX86Host));
152166

153167
console.log("Using default Editor Services path: " + editorServicesHostPath);
154168
}
155169

156170
return editorServicesHostPath;
157171
}
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)