11import * as vscode from "vscode" ;
22
3- import { Log } from "../Logger" ;
3+ import Log from "../Logger" ;
44import Project from "../microclimate/project/Project" ;
55import Connection from "../microclimate/connection/Connection" ;
66import ConnectionManager from "../microclimate/connection/ConnectionManager" ;
7- import { ProjectState } from "../microclimate/project/ProjectState" ;
7+ import ProjectState from "../microclimate/project/ProjectState" ;
88
99import Commands from "../constants/Commands" ;
1010
@@ -84,7 +84,7 @@ export function createCommands(): vscode.Disposable[] {
8484 * @param acceptableStates - If at least one state is passed, only projects in one of these states will be presented to the user.
8585 */
8686export async function promptForProject ( ...acceptableStates : ProjectState . AppStates [ ] ) : Promise < Project | undefined > {
87- const project = await promptForResourceInner ( false , true , ...acceptableStates ) ;
87+ const project = await promptForResourceInner ( false , true , false , ...acceptableStates ) ;
8888 if ( project instanceof Project ) {
8989 return project as Project ;
9090 }
@@ -97,12 +97,16 @@ export async function promptForProject(...acceptableStates: ProjectState.AppStat
9797 return undefined ;
9898}
9999
100- export async function promptForConnection ( ) : Promise < Connection | undefined > {
100+ export async function promptForConnection ( activeOnly : boolean ) : Promise < Connection | undefined > {
101101 if ( ConnectionManager . instance . connections . length === 1 ) {
102- return ConnectionManager . instance . connections [ 0 ] ;
102+ const onlyConnection = ConnectionManager . instance . connections [ 0 ] ;
103+ if ( onlyConnection . isConnected || ! activeOnly ) {
104+ return onlyConnection ;
105+ }
106+ // else continue to promptForResource, which will report if there are no suitable connections.
103107 }
104108
105- const connection = await promptForResourceInner ( true , false ) ;
109+ const connection = await promptForResourceInner ( true , false , activeOnly ) ;
106110 if ( connection instanceof Connection ) {
107111 return connection as Connection ;
108112 }
@@ -115,38 +119,56 @@ export async function promptForConnection(): Promise<Connection | undefined> {
115119 return undefined ;
116120}
117121
118- export async function promptForResource ( ...acceptableStates : ProjectState . AppStates [ ] ) : Promise < Project | Connection | undefined > {
119- return promptForResourceInner ( true , true , ...acceptableStates ) ;
122+ export async function promptForResource ( activeConnectionsOnly : boolean , ...acceptableStates : ProjectState . AppStates [ ] ) :
123+ Promise < Project | Connection | undefined > {
124+
125+ return promptForResourceInner ( true , true , activeConnectionsOnly , ...acceptableStates ) ;
120126}
121127
122- async function promptForResourceInner ( includeConnections : boolean , includeProjects : boolean , ...acceptableStates : ProjectState . AppStates [ ] ) :
123- Promise < Project | Connection | undefined > {
128+ /**
129+ * If !includeConnections, activeConnectionsOnly is ignored.
130+ * If !includeProjects, acceptableStates is ignored.
131+ */
132+ async function promptForResourceInner ( includeConnections : boolean , includeProjects : boolean , activeConnectionsOnly : boolean ,
133+ ...acceptableStates : ProjectState . AppStates [ ] ) :
134+ Promise < Project | Connection | undefined > {
124135
125136 if ( ! includeConnections && ! includeProjects ) {
126137 // One of these must always be set
127138 Log . e ( "Neither connection or projects are to be included!" ) ;
128139 return undefined ;
129140 }
130141 else if ( ! includeProjects && acceptableStates . length > 0 ) {
131- // This is a misuse of this function
142+ // This doesn't actually matter, but we're going to log this misuse anyway
132143 Log . e ( "Not including projects, but acceptable states were specified!" ) ;
133144 acceptableStates = [ ] ;
134145 }
146+ else if ( ! includeConnections && activeConnectionsOnly ) {
147+ // This doesn't actually matter, but we're going to log this misuse anyway
148+ Log . e ( "Not including connections, but activeConnectionsOnly is set!" ) ;
149+ }
135150
136151 const choices : vscode . QuickPickItem [ ] = [ ] ;
137152
138153 const connections = ConnectionManager . instance . connections ;
139154 if ( includeConnections ) {
140- // Convert each Connected Connection into a QuickPickItem
141- // choices.push(... (connections.filter( (conn) => conn.isConnected)));
142- choices . push ( ...connections ) ;
155+ if ( activeConnectionsOnly ) {
156+ choices . push ( ...( connections . filter ( ( conn ) => conn . isConnected ) ) ) ;
157+ }
158+ else {
159+ choices . push ( ...connections ) ;
160+ }
143161 }
144162
145163 if ( includeProjects ) {
146164 // for now, assume if they want Started, they also accept Debugging. This may change.
147165 if ( acceptableStates . includes ( ProjectState . AppStates . STARTED ) && ! acceptableStates . includes ( ProjectState . AppStates . DEBUGGING ) ) {
148166 acceptableStates . push ( ProjectState . AppStates . DEBUGGING ) ;
149167 }
168+ // same for Starting / Starting - Debug
169+ if ( acceptableStates . includes ( ProjectState . AppStates . STARTING ) && ! acceptableStates . includes ( ProjectState . AppStates . DEBUG_STARTING ) ) {
170+ acceptableStates . push ( ProjectState . AppStates . DEBUG_STARTING ) ;
171+ }
150172
151173 // Logger.log("Accept states", acceptableStates);
152174
0 commit comments