Skip to content

Commit 0fb3e6f

Browse files
authored
Merge pull request #79 from glennsarti/start-windows-server
(GH-65) Start language server on Windows
2 parents 6a35d5a + cede979 commit 0fb3e6f

File tree

3 files changed

+71
-24
lines changed

3 files changed

+71
-24
lines changed

client/package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,27 +83,27 @@
8383
"puppet.languageserver.address": {
8484
"type": "string",
8585
"default": "127.0.0.1",
86-
"description": "The address of the VSCode languge sever to connect to"
86+
"description": "The IP address or hostname of the Puppet Language Server to connect to"
8787
},
8888
"puppet.languageserver.port": {
8989
"type": "integer",
9090
"default": 8081,
91-
"description": "The port of the VSCode languge sever to connect to"
92-
},
93-
"puppet.languageserver.stopOnClientExit": {
94-
"type":"boolean",
95-
"default": true,
96-
"description": "Stop the VSCode languge sever when the client disconnects"
91+
"description": "The TCP Port of the Puppet Language Server to connect to"
9792
},
9893
"puppet.languageserver.timeout": {
9994
"type": "integer",
10095
"default": 10,
101-
"description": "The timeout to connect to the VSCode languge sever"
96+
"description": "The timeout to connect to the local Puppet Language Server"
10297
},
10398
"puppet.languageserver.preLoadPuppet": {
10499
"type":"boolean",
105100
"default": true,
106-
"description": "Initalize puppet on VSCode languge start"
101+
"description": "Initalize Puppet and Facter when local Puppet Language Server starts"
102+
},
103+
"puppet.languageserver.debugFilePath": {
104+
"type":"string",
105+
"default": "",
106+
"description": "Set the local Puppet Language Server to send debug information to a file"
107107
}
108108
}
109109
}

client/src/connection.ts

Lines changed: 54 additions & 7 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

@@ -26,9 +27,9 @@ export interface IConnectionConfiguration {
2627
type: ConnectionType;
2728
host: string;
2829
port: number;
29-
stopOnClientExit: string;
30-
timeout: string;
31-
preLoadPuppet: string;
30+
timeout: number;
31+
preLoadPuppet: boolean;
32+
debugFilePath: string;
3233
}
3334

3435
export interface IConnectionManager {
@@ -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,26 @@ 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+
226+
if ((this.connectionConfiguration.host == undefined) || (this.connectionConfiguration.host == '')) {
227+
args.push('--ip=127.0.0.1');
228+
} else {
229+
args.push('--ip=' + this.connectionConfiguration.host);
230+
}
231+
args.push('--port=' + this.connectionConfiguration.port);
232+
args.push('--timeout=' + this.connectionConfiguration.timeout);
233+
if (this.connectionConfiguration.preLoadPuppet == false) { args.push('--no-preload'); }
234+
if ((this.connectionConfiguration.debugFilePath != undefined) && (this.connectionConfiguration.debugFilePath != '')) {
235+
args.push('--debug=' + this.connectionConfiguration.debugFilePath);
236+
}
237+
192238
console.log("Starting the language server with " + cmd + " " + args.join(" "));
239+
myOutputChannel.appendLine("Starting the language server with " + cmd + " " + args.join(" "));
193240
var proc = cp.spawn(cmd, args, options)
194241
console.log("ProcID = " + proc.pid);
195242
myOutputChannel.appendLine('Language server PID:' + proc.pid)

client/src/extension.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ export class ConnectionConfiguration implements IConnectionConfiguration {
1515
public type: ConnectionType = ConnectionType.Unknown;
1616
public host: string = undefined;
1717
public port: number = undefined;
18-
public stopOnClientExit: string = undefined;
19-
public timeout: string = undefined;
20-
public preLoadPuppet: string = undefined;
18+
public timeout: number = undefined;
19+
public preLoadPuppet: boolean = undefined;
20+
public debugFilePath: string = undefined;
2121

2222
constructor(context: vscode.ExtensionContext) {
2323
let config = vscode.workspace.getConfiguration('puppet');
2424

25-
this.host = config['languageserver']['address']; // '127.0.0.1';
26-
this.port = config['languageserver']['port']; // 8081;
27-
this.stopOnClientExit = config['languageserver']['stopOnClientExit']; // true;
28-
this.timeout = config['languageserver']['timeout']; // 10;
29-
this.preLoadPuppet = config['languageserver']['preLoadPuppet']; // true;
25+
this.host = config['languageserver']['address'];
26+
this.port = config['languageserver']['port'];
27+
this.timeout = config['languageserver']['timeout'];
28+
this.preLoadPuppet = config['languageserver']['preLoadPuppet'];
29+
this.debugFilePath = config['languageserver']['debugFilePath'];
3030
}
3131
}
3232

0 commit comments

Comments
 (0)