5
5
using Microsoft . VisualStudio ;
6
6
using Microsoft . VisualStudio . Shell ;
7
7
using Microsoft . VisualStudio . Shell . Interop ;
8
+ using Microsoft . VisualStudio . Threading ;
8
9
using Task = System . Threading . Tasks . Task ;
9
10
10
11
namespace FineCodeCoverage . Impl
@@ -13,13 +14,13 @@ namespace FineCodeCoverage.Impl
13
14
[ Export ( typeof ( ICoverageColours ) ) ]
14
15
internal class CoverageColorProvider : ICoverageColoursProvider , ICoverageColours
15
16
{
16
- private readonly IVsFontAndColorStorage fontAndColorStorage ;
17
17
private readonly ILogger logger ;
18
18
private readonly uint storeFlags = ( uint ) ( __FCSTORAGEFLAGS . FCSF_READONLY | __FCSTORAGEFLAGS . FCSF_LOADDEFAULTS | __FCSTORAGEFLAGS . FCSF_NOAUTOCOLORS | __FCSTORAGEFLAGS . FCSF_PROPAGATECHANGES ) ;
19
19
private readonly System . Windows . Media . Color defaultCoverageTouchedArea = System . Windows . Media . Colors . Green ;
20
20
private readonly System . Windows . Media . Color defaultCoverageNotTouchedArea = System . Windows . Media . Colors . Red ;
21
21
private readonly System . Windows . Media . Color defaultCoveragePartiallyTouchedArea = System . Windows . Media . Color . FromRgb ( 255 , 165 , 0 ) ;
22
22
private Guid categoryWithCoverage = Guid . Parse ( "ff349800-ea43-46c1-8c98-878e78f46501" ) ;
23
+ private AsyncLazy < IVsFontAndColorStorage > lazyIVsFontAndColorStorage ;
23
24
private bool coverageColoursFromFontsAndColours ;
24
25
private bool canUseFontsAndColours = true ;
25
26
public System . Windows . Media . Color CoverageTouchedArea { get ; set ; }
@@ -37,9 +38,12 @@ public CoverageColorProvider(
37
38
ILogger logger
38
39
)
39
40
{
40
- ThreadHelper . ThrowIfNotOnUIThread ( ) ;
41
- fontAndColorStorage = ( IVsFontAndColorStorage ) serviceProvider . GetService ( typeof ( IVsFontAndColorStorage ) ) ;
42
- Assumes . Present ( fontAndColorStorage ) ;
41
+ lazyIVsFontAndColorStorage = new AsyncLazy < IVsFontAndColorStorage > ( async ( ) =>
42
+ {
43
+ await ThreadHelper . JoinableTaskFactory . SwitchToMainThreadAsync ( ) ;
44
+ return ( IVsFontAndColorStorage ) serviceProvider . GetService ( typeof ( IVsFontAndColorStorage ) ) ;
45
+ } , ThreadHelper . JoinableTaskFactory ) ;
46
+
43
47
coverageColoursFromFontsAndColours = appOptionsProvider . Get ( ) . CoverageColoursFromFontsAndColours ;
44
48
appOptionsProvider . OptionsChanged += AppOptionsProvider_OptionsChanged ;
45
49
this . logger = logger ;
@@ -81,6 +85,7 @@ public async Task PrepareAsync()
81
85
82
86
private async Task UpdateColoursFromFontsAndColorsAsync ( )
83
87
{
88
+ var fontAndColorStorage = await lazyIVsFontAndColorStorage . GetValueAsync ( ) ;
84
89
await ThreadHelper . JoinableTaskFactory . SwitchToMainThreadAsync ( ) ;
85
90
var success = fontAndColorStorage . OpenCategory ( ref categoryWithCoverage , storeFlags ) ;
86
91
var usedFontsAndColors = false ;
0 commit comments