33using GitHub . Commands ;
44using GitHub . Services ;
55using GitHub . Settings ;
6+ using GitHub . VisualStudio ;
7+ using Microsoft . VisualStudio . Shell ;
68using Microsoft . VisualStudio . Utilities ;
79using Microsoft . VisualStudio . Text . Editor ;
810
@@ -19,25 +21,28 @@ namespace GitHub.InlineReviews.Margins
1921 [ TextViewRole ( PredefinedTextViewRoles . Editable ) ]
2022 internal sealed class PullRequestFileMarginProvider : IWpfTextViewMarginProvider
2123 {
22- readonly IPullRequestSessionManager sessionManager ;
23- readonly IToggleInlineCommentMarginCommand enableInlineCommentsCommand ;
24- readonly IGoToSolutionOrPullRequestFileCommand goToSolutionOrPullRequestFileCommand ;
25- readonly IPackageSettings packageSettings ;
24+ readonly Lazy < IPullRequestSessionManager > sessionManager ;
25+ readonly Lazy < IToggleInlineCommentMarginCommand > enableInlineCommentsCommand ;
26+ readonly Lazy < IGoToSolutionOrPullRequestFileCommand > goToSolutionOrPullRequestFileCommand ;
27+ readonly Lazy < IPackageSettings > packageSettings ;
2628 readonly Lazy < IUsageTracker > usageTracker ;
29+ readonly UIContext uiContext ;
2730
2831 [ ImportingConstructor ]
2932 public PullRequestFileMarginProvider (
30- IToggleInlineCommentMarginCommand enableInlineCommentsCommand ,
31- IGoToSolutionOrPullRequestFileCommand goToSolutionOrPullRequestFileCommand ,
32- IPullRequestSessionManager sessionManager ,
33- IPackageSettings packageSettings ,
33+ Lazy < IToggleInlineCommentMarginCommand > enableInlineCommentsCommand ,
34+ Lazy < IGoToSolutionOrPullRequestFileCommand > goToSolutionOrPullRequestFileCommand ,
35+ Lazy < IPullRequestSessionManager > sessionManager ,
36+ Lazy < IPackageSettings > packageSettings ,
3437 Lazy < IUsageTracker > usageTracker )
3538 {
3639 this . enableInlineCommentsCommand = enableInlineCommentsCommand ;
3740 this . goToSolutionOrPullRequestFileCommand = goToSolutionOrPullRequestFileCommand ;
3841 this . sessionManager = sessionManager ;
3942 this . packageSettings = packageSettings ;
4043 this . usageTracker = usageTracker ;
44+
45+ uiContext = UIContext . FromUIContextGuid ( new Guid ( Guids . UIContext_Git ) ) ;
4146 }
4247
4348 /// <summary>
@@ -50,8 +55,14 @@ public PullRequestFileMarginProvider(
5055 /// </returns>
5156 public IWpfTextViewMargin CreateMargin ( IWpfTextViewHost wpfTextViewHost , IWpfTextViewMargin marginContainer )
5257 {
58+ if ( ! uiContext . IsActive )
59+ {
60+ // Only create margin when in the context of a Git repository
61+ return null ;
62+ }
63+
5364 // Comments in the editor feature flag
54- if ( ! packageSettings . EditorComments )
65+ if ( ! packageSettings . Value . EditorComments )
5566 {
5667 return null ;
5768 }
@@ -63,7 +74,11 @@ public IWpfTextViewMargin CreateMargin(IWpfTextViewHost wpfTextViewHost, IWpfTex
6374 }
6475
6576 return new PullRequestFileMargin (
66- wpfTextViewHost . TextView , enableInlineCommentsCommand , goToSolutionOrPullRequestFileCommand , sessionManager , usageTracker ) ;
77+ wpfTextViewHost . TextView ,
78+ enableInlineCommentsCommand . Value ,
79+ goToSolutionOrPullRequestFileCommand . Value ,
80+ sessionManager . Value ,
81+ usageTracker ) ;
6782 }
6883
6984 bool IsDiffView ( ITextView textView ) => textView . Roles . Contains ( "DIFF" ) ;
0 commit comments