@@ -19,7 +19,7 @@ import { commands } from "vscode";
1919import { ext } from "../extensionVariables" ;
2020import { QueryResult , QueryResultType } from "../models/queryResult" ;
2121import { ServerObject } from "../models/serverObject" ;
22- import { delay , getAutoFocusOutputOnEntrySetting } from "../utils/core" ;
22+ import { delay } from "../utils/core" ;
2323import { convertStringToArray , handleQueryResults } from "../utils/execution" ;
2424import { MessageKind , notify } from "../utils/notifications" ;
2525import { queryWrapper } from "../utils/queryUtils" ;
@@ -83,47 +83,41 @@ export class LocalConnection {
8383 public async connect (
8484 callback : nodeq . AsyncValueCallback < LocalConnection > ,
8585 ) : Promise < void > {
86+ if ( this . connection && this . connected ) return ;
87+
8688 const options = await this . getCustomAuthOptions ( ) ;
8789
8890 nodeq . connect ( options , ( err , conn ) => {
8991 if ( err || ! conn ) {
9092 ext . serverProvider . reload ( ) ;
91-
9293 notify (
9394 `Connection to server ${ this . options . host } :${ this . options . port } failed.` ,
9495 MessageKind . ERROR ,
9596 { logger, params : err } ,
9697 ) ;
97-
9898 return ;
9999 }
100+
100101 conn . addListener ( "close" , ( ) => {
101102 commands . executeCommand ( "kdb.connections.disconnect" , this . connLabel ) ;
102103 notify (
103104 `Connection closed: ${ this . options . host } :${ this . options . port } ` ,
104105 MessageKind . DEBUG ,
105106 { logger } ,
106107 ) ;
107- if ( getAutoFocusOutputOnEntrySetting ( ) ) {
108- ext . outputChannel . show ( true ) ;
109- }
110108 } ) ;
111109
112- if ( this . connection && this . connected ) {
113- this . connection . close ( ( ) => {
114- this . onConnect ( err , conn , callback ) ;
115- } ) ;
116- } else {
117- this . onConnect ( err , conn , callback ) ;
118- }
119-
120- this . connected = false ;
110+ this . connection = conn ;
111+ this . connected = true ;
112+ this . update ( ) ;
113+ callback ( err , this ) ;
121114 } ) ;
122115 }
123116
124117 public disconnect ( ) : void {
125118 if ( this . connected ) {
126119 this . connection ?. close ( ) ;
120+ this . connection = undefined ;
127121 this . connected = false ;
128122 }
129123 }
@@ -378,18 +372,6 @@ export class LocalConnection {
378372 } ) ;
379373 }
380374
381- private onConnect (
382- err : Error | undefined ,
383- conn : nodeq . Connection ,
384- callback : nodeq . AsyncValueCallback < LocalConnection > ,
385- ) : void {
386- this . connected = true ;
387- this . connection = conn ;
388-
389- this . update ( ) ;
390- callback ( err , this ) ;
391- }
392-
393375 async getCustomAuthOptions ( ) : Promise < nodeq . ConnectionParameters > {
394376 if ( ext . customAuth ) {
395377 const { kdb } = await ext . customAuth . auth ( {
0 commit comments