@@ -26,16 +26,26 @@ export interface ConnectionSettings {
26
26
export class AtelierAPI {
27
27
private _config : ConnectionSettings ;
28
28
private namespace : string ;
29
- private cache ;
30
- private workspaceFolder ;
29
+ private configName : string ;
30
+
31
+ // when FileSystemProvider used
32
+ public externalServer = false ;
31
33
32
34
public get ns ( ) : string {
33
35
return this . namespace || this . _config . ns ;
34
36
}
35
37
36
38
public get config ( ) : ConnectionSettings {
37
- const { active, apiVersion , https, host , port , pathPrefix, username , password } = this . _config ;
39
+ const { active = false , https = false , pathPrefix = "" , username } = this . _config ;
38
40
const ns = this . namespace || this . _config . ns ;
41
+ const host = this . externalServer
42
+ ? this . _config . host
43
+ : workspaceState . get ( this . configName + ":host" , this . _config . host ) ;
44
+ const port = this . externalServer
45
+ ? this . _config . port
46
+ : workspaceState . get ( this . configName + ":port" , this . _config . port ) ;
47
+ const password = workspaceState . get ( this . configName + ":password" , this . _config . password ) ;
48
+ const apiVersion = workspaceState . get ( this . configName + ":apiVersion" , DEFAULT_API_VERSION ) ;
39
49
return {
40
50
active,
41
51
apiVersion,
@@ -50,7 +60,7 @@ export class AtelierAPI {
50
60
}
51
61
52
62
private get iris ( ) : boolean {
53
- return workspaceState . get ( this . workspaceFolder + ":iris" , false ) ;
63
+ return workspaceState . get ( this . configName + ":iris" , false ) ;
54
64
}
55
65
56
66
private transformNameIfCsp ( filename : string ) : string {
@@ -105,7 +115,7 @@ export class AtelierAPI {
105
115
}
106
116
107
117
public xdebugUrl ( ) : string {
108
- const { host, username, https, port, password, apiVersion } = this . _config ;
118
+ const { host, username, https, port, password, apiVersion } = this . config ;
109
119
const proto = https ? "wss" : "ws" ;
110
120
const auth = this . iris
111
121
? `IRISUsername=${ username } &IRISPassword=${ password } `
@@ -129,8 +139,10 @@ export class AtelierAPI {
129
139
130
140
private setConnection ( workspaceFolderName : string , namespace ?: string ) : void {
131
141
let serverName ;
132
- if ( config ( `intersystems.servers.${ workspaceFolderName } ` ) ) {
133
- serverName = workspaceFolderName ;
142
+ this . configName = workspaceFolderName ;
143
+ if ( config ( "intersystems.servers" ) . has ( workspaceFolderName . toLowerCase ( ) ) ) {
144
+ this . externalServer = true ;
145
+ serverName = workspaceFolderName . toLowerCase ( ) ;
134
146
workspaceFolderName = currentWorkspaceFolder ( ) ;
135
147
}
136
148
const conn = config ( "conn" , workspaceFolderName ) ;
@@ -140,12 +152,12 @@ export class AtelierAPI {
140
152
141
153
if ( serverName && serverName . length ) {
142
154
const {
143
- webServer : { scheme, host, port, pathPrefix } ,
155
+ webServer : { scheme, host, port, pathPrefix = "" } ,
144
156
username,
145
157
password,
146
- } = config ( ` intersystems.servers. ${ serverName } ` , workspaceFolderName ) ;
158
+ } = config ( " intersystems.servers" , workspaceFolderName ) . get ( serverName ) ;
147
159
this . _config = {
148
- active : conn . active ,
160
+ active : this . externalServer || conn . active ,
149
161
apiVersion : 1 ,
150
162
https : scheme === "https" ,
151
163
ns : namespace || conn . ns ,
@@ -157,14 +169,12 @@ export class AtelierAPI {
157
169
} ;
158
170
} else {
159
171
this . _config = conn ;
160
- this . _config . port = workspaceState . get ( workspaceFolderName + ":port" , this . _config . port ) ;
161
172
}
162
- this . _config . password = workspaceState . get ( workspaceFolderName + ":password" , this . _config . password ) ;
163
- this . _config . apiVersion = workspaceState . get ( workspaceFolderName + ":apiVersion" , DEFAULT_API_VERSION ) ;
173
+ }
164
174
165
- this . workspaceFolder = workspaceFolderName ;
166
- const { host, port } = this . _config ;
167
- this . cache = new Cache ( extensionContext , `API:${ host } :${ port } ` ) ;
175
+ private get cache ( ) : Cache {
176
+ const { host, port } = this . config ;
177
+ return new Cache ( extensionContext , `API:${ host } :${ port } ` ) ;
168
178
}
169
179
170
180
public async request (
@@ -178,18 +188,14 @@ export class AtelierAPI {
178
188
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
179
189
headers ?: any
180
190
) : Promise < any > {
181
- const {
182
- active = false ,
183
- apiVersion = 1 ,
184
- host = "localhost" ,
185
- port = 52773 ,
186
- username = "_SYSTEM" ,
187
- password = "SYS" ,
188
- https = false ,
189
- } = this . _config ;
191
+ const { active, apiVersion, host, port, username, password, https } = this . config ;
190
192
if ( ! active ) {
191
193
return Promise . reject ( ) ;
192
194
}
195
+ if ( ! username || ! username . length || ! password || ! password . length ) {
196
+ outputChannel . appendLine ( "username and password fields in settinds are mandatory" ) ;
197
+ return Promise . reject ( ) ;
198
+ }
193
199
if ( minVersion > apiVersion ) {
194
200
return Promise . reject ( `${ path } not supported by API version ${ apiVersion } ` ) ;
195
201
}
@@ -264,7 +270,6 @@ export class AtelierAPI {
264
270
. then ( ( response ) => this . updateCookies ( response . headers [ "set-cookie" ] ) . then ( ( ) => response ) )
265
271
. then ( ( response ) => {
266
272
panel . text = `${ connInfo } - Connected` ;
267
- // console.log(`APIResponse: ${method} ${proto}://${host}:${port}${path}`)
268
273
if ( method === "HEAD" ) {
269
274
return this . cookies ;
270
275
}
@@ -299,7 +304,10 @@ export class AtelierAPI {
299
304
}
300
305
} )
301
306
. catch ( ( error ) => {
307
+ console . log ( error . error ) ;
302
308
if ( error . error && error . error . code === "ECONNREFUSED" ) {
309
+ workspaceState . update ( this . configName + ":host" , undefined ) ;
310
+ workspaceState . update ( this . configName + ":port" , undefined ) ;
303
311
setTimeout ( checkConnection , 30000 ) ;
304
312
}
305
313
console . error ( error ) ;
@@ -322,8 +330,8 @@ export class AtelierAPI {
322
330
} ;
323
331
}
324
332
return Promise . all ( [
325
- workspaceState . update ( currentWorkspaceFolder ( ) + ":apiVersion" , apiVersion ) ,
326
- workspaceState . update ( currentWorkspaceFolder ( ) + ":iris" , data . version . startsWith ( "IRIS" ) ) ,
333
+ workspaceState . update ( this . configName + ":apiVersion" , apiVersion ) ,
334
+ workspaceState . update ( this . configName + ":iris" , data . version . startsWith ( "IRIS" ) ) ,
327
335
] ) . then ( ( ) => info ) ;
328
336
}
329
337
} ) ;
0 commit comments