@@ -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
public constructor ( wsOrFile ?: string | vscode . Uri ) {
@@ -95,7 +105,7 @@ export class AtelierAPI {
95
105
}
96
106
97
107
public xdebugUrl ( ) : string {
98
- const { host, username, https, port, password, apiVersion } = this . _config ;
108
+ const { host, username, https, port, password, apiVersion } = this . config ;
99
109
const proto = https ? "wss" : "ws" ;
100
110
const auth = this . iris
101
111
? `IRISUsername=${ username } &IRISPassword=${ password } `
@@ -119,8 +129,10 @@ export class AtelierAPI {
119
129
120
130
private setConnection ( workspaceFolderName : string , namespace ?: string ) : void {
121
131
let serverName ;
122
- if ( config ( `intersystems.servers.${ workspaceFolderName } ` ) ) {
123
- serverName = workspaceFolderName ;
132
+ this . configName = workspaceFolderName ;
133
+ if ( config ( "intersystems.servers" ) . has ( workspaceFolderName . toLowerCase ( ) ) ) {
134
+ this . externalServer = true ;
135
+ serverName = workspaceFolderName . toLowerCase ( ) ;
124
136
workspaceFolderName = currentWorkspaceFolder ( ) ;
125
137
}
126
138
const conn = config ( "conn" , workspaceFolderName ) ;
@@ -130,12 +142,12 @@ export class AtelierAPI {
130
142
131
143
if ( serverName && serverName . length ) {
132
144
const {
133
- webServer : { scheme, host, port, pathPrefix } ,
145
+ webServer : { scheme, host, port, pathPrefix = "" } ,
134
146
username,
135
147
password,
136
- } = config ( ` intersystems.servers. ${ serverName } ` , workspaceFolderName ) ;
148
+ } = config ( " intersystems.servers" , workspaceFolderName ) . get ( serverName ) ;
137
149
this . _config = {
138
- active : conn . active ,
150
+ active : this . externalServer || conn . active ,
139
151
apiVersion : 1 ,
140
152
https : scheme === "https" ,
141
153
ns : namespace || conn . ns ,
@@ -147,14 +159,12 @@ export class AtelierAPI {
147
159
} ;
148
160
} else {
149
161
this . _config = conn ;
150
- this . _config . port = workspaceState . get ( workspaceFolderName + ":port" , this . _config . port ) ;
151
162
}
152
- this . _config . password = workspaceState . get ( workspaceFolderName + ":password" , this . _config . password ) ;
153
- this . _config . apiVersion = workspaceState . get ( workspaceFolderName + ":apiVersion" , DEFAULT_API_VERSION ) ;
163
+ }
154
164
155
- this . workspaceFolder = workspaceFolderName ;
156
- const { host, port } = this . _config ;
157
- this . cache = new Cache ( extensionContext , `API:${ host } :${ port } ` ) ;
165
+ private get cache ( ) : Cache {
166
+ const { host, port } = this . config ;
167
+ return new Cache ( extensionContext , `API:${ host } :${ port } ` ) ;
158
168
}
159
169
160
170
public async request (
@@ -168,18 +178,14 @@ export class AtelierAPI {
168
178
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
169
179
headers ?: any
170
180
) : Promise < any > {
171
- const {
172
- active = false ,
173
- apiVersion = 1 ,
174
- host = "localhost" ,
175
- port = 52773 ,
176
- username = "_SYSTEM" ,
177
- password = "SYS" ,
178
- https = false ,
179
- } = this . _config ;
181
+ const { active, apiVersion, host, port, username, password, https } = this . config ;
180
182
if ( ! active ) {
181
183
return Promise . reject ( ) ;
182
184
}
185
+ if ( ! username || ! username . length || ! password || ! password . length ) {
186
+ outputChannel . appendLine ( "username and password fields in settinds are mandatory" ) ;
187
+ return Promise . reject ( ) ;
188
+ }
183
189
if ( minVersion > apiVersion ) {
184
190
return Promise . reject ( `${ path } not supported by API version ${ apiVersion } ` ) ;
185
191
}
@@ -254,7 +260,6 @@ export class AtelierAPI {
254
260
. then ( ( response ) => this . updateCookies ( response . headers [ "set-cookie" ] ) . then ( ( ) => response ) )
255
261
. then ( ( response ) => {
256
262
panel . text = `${ connInfo } - Connected` ;
257
- // console.log(`APIResponse: ${method} ${proto}://${host}:${port}${path}`)
258
263
if ( method === "HEAD" ) {
259
264
return this . cookies ;
260
265
}
@@ -292,7 +297,10 @@ export class AtelierAPI {
292
297
}
293
298
} )
294
299
. catch ( ( error ) => {
300
+ console . log ( error . error ) ;
295
301
if ( error . error && error . error . code === "ECONNREFUSED" ) {
302
+ workspaceState . update ( this . configName + ":host" , undefined ) ;
303
+ workspaceState . update ( this . configName + ":port" , undefined ) ;
296
304
setTimeout ( checkConnection , 30000 ) ;
297
305
}
298
306
console . error ( error ) ;
@@ -315,8 +323,8 @@ export class AtelierAPI {
315
323
} ;
316
324
}
317
325
return Promise . all ( [
318
- workspaceState . update ( currentWorkspaceFolder ( ) + ":apiVersion" , apiVersion ) ,
319
- workspaceState . update ( currentWorkspaceFolder ( ) + ":iris" , data . version . startsWith ( "IRIS" ) ) ,
326
+ workspaceState . update ( this . configName + ":apiVersion" , apiVersion ) ,
327
+ workspaceState . update ( this . configName + ":iris" , data . version . startsWith ( "IRIS" ) ) ,
320
328
] ) . then ( ( ) => info ) ;
321
329
}
322
330
} ) ;
0 commit comments