@@ -28,7 +28,7 @@ import { ConnectionService } from './connectionService';
2828import { MetadataRegistryService } from './metadataRegistryService' ;
2929import { ProjectService } from './projectService' ;
3030import { unknownToErrorCause } from './shared' ;
31- import { SourceTrackingService } from './sourceTrackingService' ;
31+ import { SourceTrackingService , type SourceTrackingOptions } from './sourceTrackingService' ;
3232
3333export class MetadataRetrieveError extends Data . TaggedError ( 'MetadataRetrieveError' ) < {
3434 readonly cause : unknown ;
@@ -63,7 +63,7 @@ const buildComponentSet = (members: MetadataMember[]) =>
6363 } ) ;
6464 } ) . pipe ( Effect . withSpan ( 'buildComponentSet' ) ) ;
6565
66- const retrieve = ( members : MetadataMember [ ] ) =>
66+ const retrieve = ( members : MetadataMember [ ] , options ?: SourceTrackingOptions ) =>
6767 Effect . gen ( function * ( ) {
6868 const [ connection , project , registryAccess ] = yield * Effect . all (
6969 [
@@ -77,6 +77,17 @@ const retrieve = (members: MetadataMember[]) =>
7777
7878 const componentSet = yield * buildComponentSet ( members ) ;
7979
80+ const tracking = yield * Effect . flatMap ( SourceTrackingService , svc => svc . getSourceTracking ( options ) ) ;
81+ if ( tracking ) {
82+ yield * Effect . promise ( ( ) => tracking . reReadLocalTrackingCache ( ) ) . pipe (
83+ Effect . withSpan ( 'STL.ReReadLocalTrackingCache' )
84+ ) ;
85+
86+ if ( ! options ?. ignoreConflicts ) {
87+ yield * Effect . flatMap ( SourceTrackingService , svc => svc . checkConflicts ( tracking ) ) ;
88+ }
89+ }
90+
8091 const title = `Retrieving ${ members . map ( m => `${ m . type } : ${ m . fullName === '*' ? 'all' : m . fullName } ` ) . join ( ', ' ) } ` ;
8192 return yield * performRetrieveOperation ( componentSet , connection , project , registryAccess , title ) ;
8293 } ) . pipe ( Effect . withSpan ( 'retrieve' , { attributes : { members } } ) ) ;
@@ -90,41 +101,39 @@ const performRetrieveOperation = (
90101 title : string
91102) =>
92103 Effect . gen ( function * ( ) {
93- const retrieveFiber = yield * Effect . fork (
94- Effect . tryPromise ( {
95- try : async ( ) => {
96- const retrieveOperation = new MetadataApiRetrieve ( {
97- usernameOrConnection : connection ,
98- components : componentSet ,
99- output : project . getDefaultPackage ( ) . fullPath ,
100- format : 'source' ,
101- merge : true ,
102- registry : registryAccess
103- } ) ;
104-
105- const retrieveResult = await vscode . window . withProgress (
106- {
107- location : vscode . ProgressLocation . Notification ,
108- title,
109- cancellable : true
110- } ,
111- async ( _ , token ) => {
112- token . onCancellationRequested ( async ( ) => {
113- await retrieveOperation . cancel ( ) ;
114- await Effect . runPromise ( Fiber . interrupt ( retrieveFiber ) ) ;
115- } ) ;
116- await retrieveOperation . start ( ) ;
117- return await retrieveOperation . pollStatus ( ) ;
118- }
119- ) ;
120- return retrieveResult ;
121- } ,
122- catch : e => {
123- console . error ( e ) ;
124- return new MetadataRetrieveError ( unknownToErrorCause ( e ) ) ;
125- }
126- } ) . pipe ( Effect . withSpan ( 'retrieve (API call)' ) )
127- ) ;
104+ const retrieveFiber = yield * Effect . tryPromise ( {
105+ try : async ( ) => {
106+ const retrieveOperation = new MetadataApiRetrieve ( {
107+ usernameOrConnection : connection ,
108+ components : componentSet ,
109+ output : project . getDefaultPackage ( ) . fullPath ,
110+ format : 'source' ,
111+ merge : true ,
112+ registry : registryAccess
113+ } ) ;
114+
115+ const retrieveResult = await vscode . window . withProgress (
116+ {
117+ location : vscode . ProgressLocation . Notification ,
118+ title,
119+ cancellable : true
120+ } ,
121+ async ( _ , token ) => {
122+ token . onCancellationRequested ( async ( ) => {
123+ await retrieveOperation . cancel ( ) ;
124+ await Effect . runPromise ( Fiber . interrupt ( retrieveFiber ) ) ;
125+ } ) ;
126+ await retrieveOperation . start ( ) ;
127+ return await retrieveOperation . pollStatus ( ) ;
128+ }
129+ ) ;
130+ return retrieveResult ;
131+ } ,
132+ catch : e => {
133+ console . error ( e ) ;
134+ return new MetadataRetrieveError ( unknownToErrorCause ( e ) ) ;
135+ }
136+ } ) . pipe ( Effect . withSpan ( 'retrieve (API call)' ) , Effect . fork ) ;
128137
129138 const retrieveOutcome = yield * Effect . matchCauseEffect ( Fiber . join ( retrieveFiber ) , {
130139 onFailure : cause =>
@@ -145,7 +154,7 @@ const performRetrieveOperation = (
145154 } ) ;
146155
147156/** Retrieve metadata using a ComponentSet directly */
148- const retrieveComponentSet = ( components : ComponentSet ) =>
157+ const retrieveComponentSet = ( components : ComponentSet , options ?: SourceTrackingOptions ) =>
149158 Effect . gen ( function * ( ) {
150159 yield * Effect . annotateCurrentSpan ( { components : components . size } ) ;
151160 const [ connection , project , registryAccess , configAggregator ] = yield * Effect . all (
@@ -161,6 +170,17 @@ const retrieveComponentSet = (components: ComponentSet) =>
161170
162171 yield * setComponentSetProperties ( components , project , configAggregator ) ;
163172
173+ const tracking = yield * Effect . flatMap ( SourceTrackingService , svc => svc . getSourceTracking ( options ) ) ;
174+ if ( tracking ) {
175+ yield * Effect . promise ( ( ) => tracking . reReadLocalTrackingCache ( ) ) . pipe (
176+ Effect . withSpan ( 'STL.ReReadLocalTrackingCache' )
177+ ) ;
178+
179+ if ( ! options ?. ignoreConflicts ) {
180+ yield * Effect . flatMap ( SourceTrackingService , svc => svc . checkConflicts ( tracking ) ) ;
181+ }
182+ }
183+
164184 const title = `Retrieving ${ components . size } component${ components . size === 1 ? '' : 's' } ` ;
165185 return yield * performRetrieveOperation ( components , connection , project , registryAccess , title ) ;
166186 } ) . pipe ( Effect . withSpan ( 'retrieveComponentSet' , { attributes : { componentCount : components . size } } ) ) ;
0 commit comments