55using Microsoft . VisualStudio ;
66using Microsoft . VisualStudio . Shell ;
77using Microsoft . VisualStudio . Shell . Interop ;
8+ using Microsoft . VisualStudio . Threading ;
89using Task = System . Threading . Tasks . Task ;
910
1011namespace FineCodeCoverage . Impl
@@ -13,13 +14,13 @@ namespace FineCodeCoverage.Impl
1314 [ Export ( typeof ( ICoverageColours ) ) ]
1415 internal class CoverageColorProvider : ICoverageColoursProvider , ICoverageColours
1516 {
16- private readonly IVsFontAndColorStorage fontAndColorStorage ;
1717 private readonly ILogger logger ;
1818 private readonly uint storeFlags = ( uint ) ( __FCSTORAGEFLAGS . FCSF_READONLY | __FCSTORAGEFLAGS . FCSF_LOADDEFAULTS | __FCSTORAGEFLAGS . FCSF_NOAUTOCOLORS | __FCSTORAGEFLAGS . FCSF_PROPAGATECHANGES ) ;
1919 private readonly System . Windows . Media . Color defaultCoverageTouchedArea = System . Windows . Media . Colors . Green ;
2020 private readonly System . Windows . Media . Color defaultCoverageNotTouchedArea = System . Windows . Media . Colors . Red ;
2121 private readonly System . Windows . Media . Color defaultCoveragePartiallyTouchedArea = System . Windows . Media . Color . FromRgb ( 255 , 165 , 0 ) ;
2222 private Guid categoryWithCoverage = Guid . Parse ( "ff349800-ea43-46c1-8c98-878e78f46501" ) ;
23+ private AsyncLazy < IVsFontAndColorStorage > lazyIVsFontAndColorStorage ;
2324 private bool coverageColoursFromFontsAndColours ;
2425 private bool canUseFontsAndColours = true ;
2526 public System . Windows . Media . Color CoverageTouchedArea { get ; set ; }
@@ -37,9 +38,12 @@ public CoverageColorProvider(
3738 ILogger logger
3839 )
3940 {
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+
4347 coverageColoursFromFontsAndColours = appOptionsProvider . Get ( ) . CoverageColoursFromFontsAndColours ;
4448 appOptionsProvider . OptionsChanged += AppOptionsProvider_OptionsChanged ;
4549 this . logger = logger ;
@@ -81,6 +85,7 @@ public async Task PrepareAsync()
8185
8286 private async Task UpdateColoursFromFontsAndColorsAsync ( )
8387 {
88+ var fontAndColorStorage = await lazyIVsFontAndColorStorage . GetValueAsync ( ) ;
8489 await ThreadHelper . JoinableTaskFactory . SwitchToMainThreadAsync ( ) ;
8590 var success = fontAndColorStorage . OpenCategory ( ref categoryWithCoverage , storeFlags ) ;
8691 var usedFontsAndColors = false ;
0 commit comments