Skip to content

Commit b795664

Browse files
committed
(GH-65) Add Windows support to local Language Server
This commit adds Windows support to the local Language Server. It detects when a 32bit VS Code is on a 64bit OS and will use the appropriate file system redirection to find a Puppet Agent installation. This commit also improves the user experience and will not throw large errors, but instead warns the user that the language server could not be started and has reduced functionality.
1 parent c522202 commit b795664

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

client/src/connection.ts

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import cp = require('child_process');
55
import { LanguageClient, LanguageClientOptions, ServerOptions } from 'vscode-languageclient';
66
import { setupPuppetCommands } from '../src/puppetcommands';
77
import * as messages from '../src/messages';
8+
import fs = require('fs');
89

910
const langID = 'puppet'; // don't change this
1011

@@ -89,7 +90,13 @@ export class ConnectionManager implements IConnectionManager {
8990

9091
if (this.connectionConfiguration.type == ConnectionType.Local) {
9192
this.languageServerProcess = this.createLanguageServerProcess(contextPath, this.puppetOutputChannel);
92-
if (this.languageServerProcess == undefined) { throw new Error('Unable to start the server process'); }
93+
if (this.languageServerProcess == undefined) {
94+
if (this.connectionStatus == ConnectionStatus.Failed) {
95+
// We've already handled this state. Just return
96+
return
97+
}
98+
throw new Error('Unable to start the Language Server Process');
99+
}
93100

94101
this.languageServerProcess.stdout.on('data', (data) => {
95102
console.log("OUTPUT: " + data.toString());
@@ -162,7 +169,7 @@ export class ConnectionManager implements IConnectionManager {
162169
private createLanguageServerProcess(serverExe: string, myOutputChannel: vscode.OutputChannel) {
163170
myOutputChannel.appendLine('Language server found at: ' + serverExe)
164171

165-
let cmd = '';
172+
let cmd: string = undefined;
166173
let args = [serverExe];
167174
let options = {};
168175

@@ -176,8 +183,29 @@ export class ConnectionManager implements IConnectionManager {
176183
// | 'win32';
177184
switch (process.platform) {
178185
case 'win32':
179-
myOutputChannel.appendLine('Windows spawn process does not work at the moment')
180-
vscode.window.showErrorMessage('Windows spawn process does not work at the moment. Functionality will be limited to syntax highlighting');
186+
let comspec: string = process.env["COMSPEC"];
187+
let programFiles = process.env["ProgramFiles"];
188+
if (process.env["PROCESSOR_ARCHITEW6432"] == "AMD64") {
189+
// VSCode is running as 32bit process on a 64bit Operating System. Need to break out
190+
// of the 32bit using the sysnative redirection and environment variables
191+
comspec = path.join(process.env["WINDIR"],"sysnative","cmd.exe");
192+
programFiles = process.env["ProgramW6432"];
193+
}
194+
let puppetDir : string = path.join(programFiles,"Puppet Labs","Puppet")
195+
let environmentBat : string = path.join(puppetDir,"bin","environment.bat")
196+
197+
if (!fs.existsSync(puppetDir)) {
198+
this.setSessionFailure("Could not find Puppet Agent at " + puppetDir);
199+
vscode.window.showWarningMessage('Could not find Puppet Agent installed at "' + puppetDir + '". Functionality will be limited to syntax highlighting');
200+
return;
201+
}
202+
203+
cmd = comspec;
204+
args = ['/K','CALL',environmentBat,'&&','ruby.exe',serverExe]
205+
options = {
206+
env: process.env,
207+
stdio: 'pipe',
208+
};
181209
break;
182210
default:
183211
myOutputChannel.appendLine('Starting language server')
@@ -189,7 +217,14 @@ export class ConnectionManager implements IConnectionManager {
189217
};
190218
}
191219

220+
if (cmd == undefined) {
221+
this.setSessionFailure("Unable to start the Language Server on this platform");
222+
vscode.window.showWarningMessage('The Puppet Language Server is not supported on this platform (' + process.platform + '). Functionality will be limited to syntax highlighting');
223+
return;
224+
}
225+
192226
console.log("Starting the language server with " + cmd + " " + args.join(" "));
227+
myOutputChannel.appendLine("Starting the language server with " + cmd + " " + args.join(" "));
193228
var proc = cp.spawn(cmd, args, options)
194229
console.log("ProcID = " + proc.pid);
195230
myOutputChannel.appendLine('Language server PID:' + proc.pid)

0 commit comments

Comments
 (0)