@@ -26,16 +26,26 @@ export interface ConnectionSettings {
2626export class AtelierAPI {
2727 private _config : ConnectionSettings ;
2828 private namespace : string ;
29- private cache ;
30- private workspaceFolder ;
29+ private configName : string ;
30+
31+ // when FileSystemProvider used
32+ public externalServer = false ;
3133
3234 public get ns ( ) : string {
3335 return this . namespace || this . _config . ns ;
3436 }
3537
3638 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 ;
3840 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 ) ;
3949 return {
4050 active,
4151 apiVersion,
@@ -50,7 +60,7 @@ export class AtelierAPI {
5060 }
5161
5262 private get iris ( ) : boolean {
53- return workspaceState . get ( this . workspaceFolder + ":iris" , false ) ;
63+ return workspaceState . get ( this . configName + ":iris" , false ) ;
5464 }
5565
5666 private transformNameIfCsp ( filename : string ) : string {
@@ -105,7 +115,7 @@ export class AtelierAPI {
105115 }
106116
107117 public xdebugUrl ( ) : string {
108- const { host, username, https, port, password, apiVersion } = this . _config ;
118+ const { host, username, https, port, password, apiVersion } = this . config ;
109119 const proto = https ? "wss" : "ws" ;
110120 const auth = this . iris
111121 ? `IRISUsername=${ username } &IRISPassword=${ password } `
@@ -129,8 +139,10 @@ export class AtelierAPI {
129139
130140 private setConnection ( workspaceFolderName : string , namespace ?: string ) : void {
131141 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 ( ) ;
134146 workspaceFolderName = currentWorkspaceFolder ( ) ;
135147 }
136148 const conn = config ( "conn" , workspaceFolderName ) ;
@@ -140,12 +152,12 @@ export class AtelierAPI {
140152
141153 if ( serverName && serverName . length ) {
142154 const {
143- webServer : { scheme, host, port, pathPrefix } ,
155+ webServer : { scheme, host, port, pathPrefix = "" } ,
144156 username,
145157 password,
146- } = config ( ` intersystems.servers. ${ serverName } ` , workspaceFolderName ) ;
158+ } = config ( " intersystems.servers" , workspaceFolderName ) . get ( serverName ) ;
147159 this . _config = {
148- active : conn . active ,
160+ active : this . externalServer || conn . active ,
149161 apiVersion : 1 ,
150162 https : scheme === "https" ,
151163 ns : namespace || conn . ns ,
@@ -157,14 +169,12 @@ export class AtelierAPI {
157169 } ;
158170 } else {
159171 this . _config = conn ;
160- this . _config . port = workspaceState . get ( workspaceFolderName + ":port" , this . _config . port ) ;
161172 }
162- this . _config . password = workspaceState . get ( workspaceFolderName + ":password" , this . _config . password ) ;
163- this . _config . apiVersion = workspaceState . get ( workspaceFolderName + ":apiVersion" , DEFAULT_API_VERSION ) ;
173+ }
164174
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 } ` ) ;
168178 }
169179
170180 public async request (
@@ -178,18 +188,14 @@ export class AtelierAPI {
178188 // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
179189 headers ?: any
180190 ) : 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 ;
190192 if ( ! active ) {
191193 return Promise . reject ( ) ;
192194 }
195+ if ( ! username || ! username . length || ! password || ! password . length ) {
196+ outputChannel . appendLine ( "username and password fields in settinds are mandatory" ) ;
197+ return Promise . reject ( ) ;
198+ }
193199 if ( minVersion > apiVersion ) {
194200 return Promise . reject ( `${ path } not supported by API version ${ apiVersion } ` ) ;
195201 }
@@ -264,7 +270,6 @@ export class AtelierAPI {
264270 . then ( ( response ) => this . updateCookies ( response . headers [ "set-cookie" ] ) . then ( ( ) => response ) )
265271 . then ( ( response ) => {
266272 panel . text = `${ connInfo } - Connected` ;
267- // console.log(`APIResponse: ${method} ${proto}://${host}:${port}${path}`)
268273 if ( method === "HEAD" ) {
269274 return this . cookies ;
270275 }
@@ -299,7 +304,10 @@ export class AtelierAPI {
299304 }
300305 } )
301306 . catch ( ( error ) => {
307+ console . log ( error . error ) ;
302308 if ( error . error && error . error . code === "ECONNREFUSED" ) {
309+ workspaceState . update ( this . configName + ":host" , undefined ) ;
310+ workspaceState . update ( this . configName + ":port" , undefined ) ;
303311 setTimeout ( checkConnection , 30000 ) ;
304312 }
305313 console . error ( error ) ;
@@ -322,8 +330,8 @@ export class AtelierAPI {
322330 } ;
323331 }
324332 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" ) ) ,
327335 ] ) . then ( ( ) => info ) ;
328336 }
329337 } ) ;
0 commit comments