@@ -428,4 +428,86 @@ export function addAssetsIfNecessary(server: OmnisharpServer): Promise<AddAssetR
428428 } ) . catch ( err =>
429429 reject ( err ) ) ;
430430 } ) ;
431+ }
432+
433+ function doAssetsExists ( paths : Paths ) {
434+ return new Promise < boolean > ( ( resolve , reject ) => {
435+ fs . existsAsync ( paths . launchJsonPath ) . then ( res => {
436+ if ( res ) {
437+ resolve ( true ) ;
438+ }
439+ else {
440+ fs . existsAsync ( paths . tasksJsonPath ) . then ( res => {
441+ resolve ( res ) ;
442+ } ) ;
443+ }
444+ } ) ;
445+ } ) ;
446+ }
447+
448+ function deleteAsset ( path : string ) {
449+ return new Promise < void > ( ( resolve , reject ) => {
450+ fs . existsAsync ( path ) . then ( res => {
451+ if ( res ) {
452+ // TODO: Should we check after unlinking to see if the file still exists?
453+ fs . unlinkAsync ( path ) . then ( ( ) => {
454+ resolve ( ) ;
455+ } ) ;
456+ }
457+ } ) ;
458+ } ) ;
459+ }
460+
461+ function deleteAssets ( paths : Paths ) {
462+ return Promise . all ( [
463+ deleteAsset ( paths . launchJsonPath ) ,
464+ deleteAsset ( paths . tasksJsonPath )
465+ ] ) ;
466+ }
467+
468+ function shouldGenerateAssets ( paths : Paths ) {
469+ return new Promise < boolean > ( ( resolve , reject ) => {
470+ doAssetsExists ( paths ) . then ( res => {
471+ if ( res ) {
472+ const yesItem = { title : 'Yes' } ;
473+ const cancelItem = { title : 'Cancel' , isCloseAffordance : true } ;
474+
475+ vscode . window . showWarningMessage ( 'Replace existing build and debug assets?' , cancelItem , yesItem )
476+ . then ( selection => {
477+ if ( selection === yesItem ) {
478+ deleteAssets ( paths ) . then ( _ => resolve ( true ) ) ;
479+ }
480+ else {
481+ // The user clicked cancel
482+ resolve ( false ) ;
483+ }
484+ } ) ;
485+ }
486+ else {
487+ // The assets don't exist, so we're good to go.
488+ resolve ( true ) ;
489+ }
490+ } ) ;
491+
492+ } ) ;
493+ }
494+
495+ export function generateAssets ( server : OmnisharpServer ) {
496+ serverUtils . requestWorkspaceInformation ( server ) . then ( info => {
497+ if ( info . DotNet && info . DotNet . Projects . length > 0 ) {
498+ getOperations ( ) . then ( operations => {
499+ if ( hasOperations ( operations ) ) {
500+ const paths = getPaths ( ) ;
501+ shouldGenerateAssets ( paths ) . then ( res => {
502+ if ( res ) {
503+ fs . ensureDirAsync ( paths . vscodeFolder ) . then ( ( ) => {
504+ const data = findTargetProjectData ( info . DotNet . Projects ) ;
505+ addAssets ( data , paths , operations ) ;
506+ } ) ;
507+ }
508+ } ) ;
509+ }
510+ } ) ;
511+ }
512+ } ) ;
431513}
0 commit comments