@@ -258,24 +258,54 @@ async function getOpenDreamInstallation(): Promise<OpenDreamInstallation | undef
258258 function isOpenDreamSource ( path : string ) : Promise < boolean > {
259259 return exists ( `${ path } /OpenDream.sln` ) ;
260260 }
261+ async function selectOpenDreamPath ( message : string , oldValue ?: string ) : Promise < string | undefined > {
262+ let choice = await vscode . window . showInformationMessage ( message , "Configure" , "Not now" ) ;
263+ if ( choice !== "Configure" ) {
264+ return undefined ;
265+ }
266+
267+ let selection = await vscode . window . showOpenDialog ( {
268+ defaultUri : oldValue ? vscode . Uri . file ( oldValue ) : undefined ,
269+ canSelectFiles : false ,
270+ canSelectFolders : true ,
271+ } ) ;
272+ if ( ! selection ) { // cancelled
273+ return undefined ;
274+ }
275+ if ( selection [ 0 ] . scheme !== 'file' ) {
276+ return oldValue ;
277+ }
278+ var value = selection [ 0 ] . fsPath ;
279+ workspace . getConfiguration ( 'opendream' ) . update ( 'sourcePath' , value , vscode . ConfigurationTarget . Global ) ;
280+ return value ;
281+ }
261282
283+ // Check if one of the workspace folders is an OpenDream source checkout.
262284 for ( let folder of workspace . workspaceFolders || [ ] ) {
263285 if ( folder . uri . scheme === 'file' && await isOpenDreamSource ( folder . uri . fsPath ) ) {
264286 return new ODWorkspaceFolderInstallation ( folder ) ;
265287 }
266288 }
267289
290+ // Check if the configured path is a valid OpenDream source checkout.
268291 let configuredPath : string | undefined = workspace . getConfiguration ( 'opendream' ) . get ( 'sourcePath' ) ;
269292 if ( ! configuredPath ) {
270- // TODO: add UI prompt
271- return ;
293+ configuredPath = await selectOpenDreamPath ( "This feature requires an OpenDream path to be configured. Select now?" , configuredPath ) ;
294+ if ( ! configuredPath ) {
295+ return ;
296+ }
272297 }
273298
274- if ( await isOpenDreamSource ( configuredPath ) ) {
275- return new ODSourceInstallation ( configuredPath ) ;
276- }
299+ do {
300+ if ( await isOpenDreamSource ( configuredPath ) ) {
301+ return new ODSourceInstallation ( configuredPath ) ;
302+ }
303+
304+ // When OD starts shipping a binary distribution, attempt ODBinaryDistribution here.
277305
278- // When OD starts shipping a binary distribution, attempt ODBinaryDistribution here.
306+ // Doesn't appear to be valid; prompt for another.
307+ configuredPath = await selectOpenDreamPath ( "The folder you selected does not contain `OpenDream.sln`. Select again?" , configuredPath ) ;
308+ } while ( configuredPath ) ;
279309}
280310
281311// Hypothetical OD binary distribution; not used because OD doesn't have one.
0 commit comments