@@ -5,6 +5,7 @@ import cp = require('child_process');
55import { LanguageClient , LanguageClientOptions , ServerOptions } from 'vscode-languageclient' ;
66import { setupPuppetCommands } from '../src/puppetcommands' ;
77import * as messages from '../src/messages' ;
8+ import fs = require( 'fs' ) ;
89
910const 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
3435export 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 )
0 commit comments