@@ -12,9 +12,9 @@ internal sealed class UpToDateCheckHost : IUpToDateCheckHost
12
12
{
13
13
private readonly IVsService < IVsAppId > _vsAppId ;
14
14
private readonly IVsService < IVsAppCommandLine > _vsAppCommandLine ;
15
- private readonly JoinableTaskContext _joinableTaskContext ;
16
15
17
- private bool ? _hasDesignTimeBuild ;
16
+ private readonly AsyncLazy < bool > _hasDesignTimeBuild ;
17
+ private readonly CancellationTokenSource _cancellationTokenSource = new ( ) ;
18
18
19
19
[ ImportingConstructor ]
20
20
public UpToDateCheckHost (
@@ -24,45 +24,48 @@ public UpToDateCheckHost(
24
24
{
25
25
_vsAppId = vsAppId ;
26
26
_vsAppCommandLine = vsAppCommandLine ;
27
- _joinableTaskContext = joinableTaskContext ;
27
+
28
+ _hasDesignTimeBuild = new ( HasDesignTimeBuildsInternalAsync , joinableTaskContext . Factory ) ;
28
29
}
29
30
30
31
public async ValueTask < bool > HasDesignTimeBuildsAsync ( CancellationToken cancellationToken )
31
32
{
32
- _hasDesignTimeBuild ??= await HasDesignTimeBuildsInternalAsync ( ) ;
33
+ cancellationToken . Register ( _cancellationTokenSource . Cancel ) ;
33
34
34
- return _hasDesignTimeBuild . Value ;
35
+ return await _hasDesignTimeBuild . GetValueAsync ( cancellationToken ) ;
36
+ }
35
37
36
- async Task < bool > HasDesignTimeBuildsInternalAsync ( )
37
- {
38
- IVsAppCommandLine vsAppCommandLine = await _vsAppCommandLine . GetValueAsync ( cancellationToken ) ;
38
+ private async Task < bool > HasDesignTimeBuildsInternalAsync ( )
39
+ {
40
+ CancellationToken token = _cancellationTokenSource . Token ;
41
+
42
+ IVsAppCommandLine vsAppCommandLine = await _vsAppCommandLine . GetValueAsync ( token ) ;
39
43
40
- if ( ErrorHandler . Succeeded ( vsAppCommandLine . GetOption ( "populateSolutionCache" , out int populateSolutionCachePresent , out string _ ) ) )
44
+ if ( ErrorHandler . Succeeded ( vsAppCommandLine . GetOption ( "populateSolutionCache" , out int populateSolutionCachePresent , out string _ ) ) )
45
+ {
46
+ if ( populateSolutionCachePresent != 0 )
41
47
{
42
- if ( populateSolutionCachePresent != 0 )
43
- {
44
- // Design time builds are available when running with /populateSolutionCache.
45
- return true ;
46
- }
48
+ // Design time builds are available when running with /populateSolutionCache.
49
+ return true ;
47
50
}
51
+ }
48
52
49
- IVsAppId vsAppId = await _vsAppId . GetValueAsync ( cancellationToken ) ;
53
+ IVsAppId vsAppId = await _vsAppId . GetValueAsync ( token ) ;
50
54
51
- if ( ErrorHandler . Succeeded ( vsAppId . GetProperty ( ( int ) __VSAPROPID10 . VSAPROPID_IsInCommandLineMode , out object value ) ) )
55
+ if ( ErrorHandler . Succeeded ( vsAppId . GetProperty ( ( int ) __VSAPROPID10 . VSAPROPID_IsInCommandLineMode , out object value ) ) )
56
+ {
57
+ if ( value is bool isInCommandLineMode )
52
58
{
53
- if ( value is bool isInCommandLineMode )
54
- {
55
- // Design-time builds do not occur in command line mode, other than with /populateSolutionCache (checked earlier).
56
- return ! isInCommandLineMode ;
57
- }
59
+ // Design-time builds do not occur in command line mode, other than with /populateSolutionCache (checked earlier).
60
+ return ! isInCommandLineMode ;
58
61
}
62
+ }
59
63
60
- // We shouldn't reach this point.
61
- System . Diagnostics . Debug . Fail ( $ "{ nameof ( UpToDateCheckHost ) } .{ nameof ( HasDesignTimeBuildsAsync ) } was unable to determine result reliably.") ;
64
+ // We shouldn't reach this point.
65
+ System . Diagnostics . Debug . Fail ( $ "{ nameof ( UpToDateCheckHost ) } .{ nameof ( HasDesignTimeBuildsAsync ) } was unable to determine result reliably.") ;
62
66
63
- // Assume we don't have design-time builds, to prevent hangs from waiting for snapshot data that will never arrive.
64
- return false ;
65
- }
67
+ // Assume we don't have design-time builds, to prevent hangs from waiting for snapshot data that will never arrive.
68
+ return false ;
66
69
}
67
70
}
68
71
}
0 commit comments