@@ -5,6 +5,7 @@ import * as url from "url";
55import * as vscode from "vscode" ;
66import * as Cache from "vscode-cache" ;
77import {
8+ getResolvedConnectionSpec ,
89 config ,
910 extensionContext ,
1011 FILESYSTEM_SCHEMA ,
@@ -39,6 +40,9 @@ export class AtelierAPI {
3940 // when FileSystemProvider used
4041 public externalServer = false ;
4142
43+ // record of the constructor argument
44+ public readonly wsOrFile ?: string | vscode . Uri ;
45+
4246 public get ns ( ) : string {
4347 return this . namespace || this . _config . ns ;
4448 }
@@ -81,9 +85,12 @@ export class AtelierAPI {
8185 return filename ;
8286 }
8387
84- public constructor ( wsOrFile ?: string | vscode . Uri ) {
88+ public constructor ( wsOrFile ?: string | vscode . Uri , retryAfter401 = true ) {
89+ if ( retryAfter401 ) {
90+ this . wsOrFile = wsOrFile ;
91+ }
8592 let workspaceFolderName = "" ;
86- let namespace ;
93+ let namespace = "" ;
8794 if ( wsOrFile ) {
8895 if ( wsOrFile instanceof vscode . Uri ) {
8996 if ( wsOrFile . scheme === FILESYSTEM_SCHEMA || wsOrFile . scheme === FILESYSTEM_READONLY_SCHEMA ) {
@@ -147,24 +154,23 @@ export class AtelierAPI {
147154 }
148155
149156 private setConnection ( workspaceFolderName : string , namespace ?: string ) : void {
150- let serverName ;
151157 this . configName = workspaceFolderName ;
152- if ( config ( "intersystems.servers" ) . has ( workspaceFolderName . toLowerCase ( ) ) ) {
153- this . externalServer = true ;
154- serverName = workspaceFolderName . toLowerCase ( ) ;
155- workspaceFolderName = currentWorkspaceFolder ( ) ;
156- }
157158 const conn = config ( "conn" , workspaceFolderName ) ;
158- if ( ! serverName && conn . server ) {
159+ let serverName = workspaceFolderName . toLowerCase ( ) ;
160+ if ( config ( "intersystems.servers" ) . has ( serverName ) ) {
161+ this . externalServer = true ;
162+ } else if ( conn . server ) {
159163 serverName = conn . server ;
164+ } else {
165+ serverName = "" ;
160166 }
161167
162168 if ( serverName && serverName . length ) {
163169 const {
164170 webServer : { scheme, host, port, pathPrefix = "" } ,
165171 username,
166172 password,
167- } = config ( "intersystems.servers" , workspaceFolderName ) . get ( serverName ) ;
173+ } = getResolvedConnectionSpec ( serverName , config ( "intersystems.servers" , workspaceFolderName ) . get ( serverName ) ) ;
168174 this . _config = {
169175 active : this . externalServer || conn . active ,
170176 apiVersion : 1 ,
@@ -176,6 +182,13 @@ export class AtelierAPI {
176182 password,
177183 pathPrefix,
178184 } ;
185+
186+ // Report server as inactive when no namespace has been determined,
187+ // otherwise output channel reports the issue.
188+ // This arises when a server-only workspace is editing the user's settings.json, or the .code-workspace file.
189+ if ( this . _config . ns === "" && this . externalServer ) {
190+ this . _config . active = false ;
191+ }
179192 } else {
180193 this . _config = conn ;
181194 }
@@ -201,10 +214,6 @@ export class AtelierAPI {
201214 if ( ! active ) {
202215 return Promise . reject ( ) ;
203216 }
204- if ( ! username || ! username . length || ! password || ! password . length ) {
205- outputChannel . appendLine ( "username and password fields in settings are mandatory." ) ;
206- return Promise . reject ( ) ;
207- }
208217 if ( minVersion > apiVersion ) {
209218 return Promise . reject ( `${ path } not supported by API version ${ apiVersion } ` ) ;
210219 }
@@ -318,6 +327,10 @@ export class AtelierAPI {
318327 workspaceState . update ( this . configName + ":host" , undefined ) ;
319328 workspaceState . update ( this . configName + ":port" , undefined ) ;
320329 setTimeout ( checkConnection , 30000 ) ;
330+ } else if ( error . statusCode === 401 && this . wsOrFile ) {
331+ setTimeout ( ( ) => {
332+ checkConnection ( true , typeof this . wsOrFile === "object" ? this . wsOrFile : undefined ) ;
333+ } , 1000 ) ;
321334 }
322335 console . error ( error ) ;
323336 throw error ;
0 commit comments