33import * as vscode from 'vscode' ;
44import * as path from 'path' ;
55
6- import { IConnectionConfiguration , ConnectionType } from './interfaces' ;
6+ import { IConnectionConfiguration , ConnectionType , ProtocolType } from './interfaces' ;
77
88export class ConnectionConfiguration implements IConnectionConfiguration {
99 public host : string ;
@@ -12,8 +12,8 @@ export class ConnectionConfiguration implements IConnectionConfiguration {
1212 public enableFileCache : boolean ;
1313 public debugFilePath : string ;
1414 public langID : string = 'puppet' ; // don't change this
15- config :vscode . WorkspaceConfiguration ;
16- context :vscode . ExtensionContext ;
15+ config : vscode . WorkspaceConfiguration ;
16+ context : vscode . ExtensionContext ;
1717
1818 constructor ( context : vscode . ExtensionContext ) {
1919 this . context = context ;
@@ -26,65 +26,69 @@ export class ConnectionConfiguration implements IConnectionConfiguration {
2626 this . debugFilePath = this . config [ 'languageserver' ] [ 'debugFilePath' ] ;
2727 }
2828
29- get puppetAgentDir ( ) :string {
30- if ( this . config [ 'puppetAgentDir' ] !== null ) {
29+ get puppetAgentDir ( ) : string {
30+ if ( this . config [ 'puppetAgentDir' ] !== null ) {
3131 return this . config [ 'puppetAgentDir' ] ;
3232 }
3333
34- switch ( process . platform ) {
34+ switch ( process . platform ) {
3535 case 'win32' :
3636 let programFiles = process . env [ 'ProgramFiles' ] || 'C:\\Program Files' ;
3737 if ( process . env [ 'PROCESSOR_ARCHITEW6432' ] === 'AMD64' ) {
38- programFiles = process . env [ 'ProgramW6432' ] || 'C:\\Program Files' ;
38+ programFiles = process . env [ 'ProgramW6432' ] || 'C:\\Program Files' ;
3939 }
4040 return path . join ( programFiles , 'Puppet Labs' , 'Puppet' ) ;
4141 default :
4242 return '/opt/puppetlabs/puppet' ;
4343 }
4444 }
4545
46- get pdkDir ( ) :string {
47- if ( this . config [ 'pdkDir' ] !== null ) {
46+ get pdkDir ( ) : string {
47+ if ( this . config [ 'pdkDir' ] !== null ) {
4848 return this . config [ 'pdkDir' ] ;
4949 }
5050
51- switch ( process . platform ) {
51+ switch ( process . platform ) {
5252 case 'win32' :
5353 let programFiles = process . env [ 'ProgramFiles' ] || 'C:\\Program Files' ;
5454 if ( process . env [ 'PROCESSOR_ARCHITEW6432' ] === 'AMD64' ) {
55- programFiles = process . env [ 'ProgramW6432' ] || 'C:\\Program Files' ;
55+ programFiles = process . env [ 'ProgramW6432' ] || 'C:\\Program Files' ;
5656 }
5757 return path . join ( programFiles , 'Puppet Labs' , 'DevelopmentKit' ) ;
5858 default :
5959 return '/opt/puppetlabs/pdk' ;
6060 }
6161 }
6262
63- get puppetDir ( ) :string {
63+ get puppetDir ( ) : string {
6464 return path . join ( this . puppetAgentDir , 'puppet' ) ;
6565 }
6666
67- get facterDir ( ) :string {
67+ get facterDir ( ) : string {
6868 return path . join ( this . puppetAgentDir , 'facter' ) ;
6969 }
7070
71- get hieraDir ( ) :string {
71+ get hieraDir ( ) : string {
7272 return path . join ( this . puppetAgentDir , 'hiera' ) ;
7373 }
7474
75- get mcoDir ( ) :string {
75+ get mcoDir ( ) : string {
7676 return path . join ( this . puppetAgentDir , 'mcollective' ) ;
7777 }
7878
79- get rubydir ( ) :string {
79+ get rubydir ( ) : string {
8080 return path . join ( this . puppetAgentDir , 'sys' , 'ruby' ) ;
8181 }
8282
83- get rubylib ( ) :string {
84- var p = path . join ( this . puppetDir , 'lib' ) + this . pathEnvSeparator ( )
85- + path . join ( this . facterDir , 'lib' ) + this . pathEnvSeparator ( )
86- + path . join ( this . hieraDir , 'lib' ) + this . pathEnvSeparator ( )
87- + path . join ( this . mcoDir , 'lib' ) ;
83+ get rubylib ( ) : string {
84+ var p =
85+ path . join ( this . puppetDir , 'lib' ) +
86+ this . pathEnvSeparator ( ) +
87+ path . join ( this . facterDir , 'lib' ) +
88+ this . pathEnvSeparator ( ) +
89+ path . join ( this . hieraDir , 'lib' ) +
90+ this . pathEnvSeparator ( ) +
91+ path . join ( this . mcoDir , 'lib' ) ;
8892
8993 if ( process . platform === 'win32' ) {
9094 // Translate all slashes to / style to avoid puppet/ruby issue #11930
@@ -94,60 +98,86 @@ export class ConnectionConfiguration implements IConnectionConfiguration {
9498 return p ;
9599 }
96100
97- get sslCertDir ( ) :string {
101+ get sslCertDir ( ) : string {
98102 return path . join ( this . puppetDir , 'ssl' , 'certs' ) ;
99103 }
100104
101- get sslCertFile ( ) :string {
105+ get sslCertFile ( ) : string {
102106 return path . join ( this . puppetDir , 'ssl' , 'cert.pem' ) ;
103107 }
104108
105- get environmentPath ( ) :string {
106- return path . join ( this . puppetDir , 'bin' ) + this . pathEnvSeparator ( ) +
107- path . join ( this . facterDir , 'bin' ) + this . pathEnvSeparator ( ) +
108- path . join ( this . hieraDir , 'bin' ) + this . pathEnvSeparator ( ) +
109- path . join ( this . mcoDir , 'bin' ) + this . pathEnvSeparator ( ) +
110- path . join ( this . puppetAgentDir , 'bin' ) + this . pathEnvSeparator ( ) +
111- path . join ( this . rubydir , 'bin' ) + this . pathEnvSeparator ( ) +
109+ get environmentPath ( ) : string {
110+ return (
111+ path . join ( this . puppetDir , 'bin' ) +
112+ this . pathEnvSeparator ( ) +
113+ path . join ( this . facterDir , 'bin' ) +
114+ this . pathEnvSeparator ( ) +
115+ path . join ( this . hieraDir , 'bin' ) +
116+ this . pathEnvSeparator ( ) +
117+ path . join ( this . mcoDir , 'bin' ) +
118+ this . pathEnvSeparator ( ) +
119+ path . join ( this . puppetAgentDir , 'bin' ) +
120+ this . pathEnvSeparator ( ) +
121+ path . join ( this . rubydir , 'bin' ) +
122+ this . pathEnvSeparator ( ) +
112123 path . join ( this . puppetAgentDir , 'sys' , 'tools' , 'bin' ) +
113- this . pathEnvSeparator ( ) ;
124+ this . pathEnvSeparator ( )
125+ ) ;
114126 }
115127
116- get languageServerPath ( ) :string {
128+ get languageServerPath ( ) : string {
117129 return this . context . asAbsolutePath ( path . join ( 'vendor' , 'languageserver' , 'puppet-languageserver' ) ) ;
118130 }
119131
120- get type ( ) : ConnectionType {
121- if ( this . host === '127.0.0.1' ||
122- this . host === 'localhost' ||
123- this . host === '' ) {
132+ get type ( ) : ConnectionType {
133+ if ( this . host === '127.0.0.1' || this . host === 'localhost' || this . host === '' ) {
124134 return ConnectionType . Local ;
125135 } else {
126136 return ConnectionType . Remote ;
127137 }
128138 }
129139
130- get languageServerCommandLine ( ) :Array < string > {
140+ get protocol ( ) : ProtocolType {
141+ switch ( this . config [ 'languageclient' ] [ 'protocol' ] ) {
142+ case 'stdio' :
143+ return ProtocolType . STDIO ;
144+ case 'tcp' :
145+ return ProtocolType . TCP ;
146+ default :
147+ return ProtocolType . STDIO ;
148+ }
149+ }
150+
151+ get languageServerCommandLine ( ) : Array < string > {
131152 var args = new Array < string > ( ) ;
132153
133- if ( ( this . host === undefined ) || ( this . host === '' ) ) {
134- args . push ( '--ip=127.0.0.1' ) ;
135- } else {
136- args . push ( '--ip=' + this . host ) ;
154+ switch ( this . protocol ) {
155+ case ProtocolType . STDIO :
156+ args . push ( '--stdio' ) ;
157+ break ;
158+ case ProtocolType . TCP :
159+ if ( this . host === undefined || this . host === '' ) {
160+ args . push ( '--ip=127.0.0.1' ) ;
161+ } else {
162+ args . push ( '--ip=' + this . host ) ;
163+ }
164+ args . push ( '--port=' + this . port ) ;
165+ break ;
166+ default :
167+ break ;
137168 }
138169
170+ args . push ( '--timeout=' + this . timeout ) ;
171+
139172 if ( vscode . workspace . workspaceFolders !== undefined ) {
140173 args . push ( '--local-workspace=' + vscode . workspace . workspaceFolders [ 0 ] . uri . fsPath ) ;
141174 }
142175
143- args . push ( '--port=' + this . port ) ;
144- args . push ( '--timeout=' + this . timeout ) ;
145-
146176 if ( this . enableFileCache ) {
147177 args . push ( '--enable-file-cache' ) ;
148178 }
149179
150- if ( ( this . debugFilePath !== undefined ) && ( this . debugFilePath !== '' ) ) {
180+ if ( this . debugFilePath !== undefined && this . debugFilePath !== '' ) {
151181 args . push ( '--debug=' + this . debugFilePath ) ;
152182 }
153183
0 commit comments