Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 7a9d086

Browse files
authored
Merge branch 'master' into fixes/1158-merge-base-crash
2 parents 54e7e12 + ffe9738 commit 7a9d086

File tree

2 files changed

+76
-57
lines changed

2 files changed

+76
-57
lines changed

src/GitHub.InlineReviews/Commands/InlineCommentNavigationCommand.cs

Lines changed: 67 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using GitHub.Extensions;
66
using GitHub.InlineReviews.Services;
77
using GitHub.InlineReviews.Tags;
8+
using GitHub.VisualStudio;
89
using Microsoft.VisualStudio;
910
using Microsoft.VisualStudio.ComponentModelHost;
1011
using Microsoft.VisualStudio.Editor;
@@ -98,72 +99,83 @@ protected int GetCursorPoint(ITextView textView, int lineNumber)
9899
/// </remarks>
99100
protected IEnumerable<ITextView> GetCurrentTextViews()
100101
{
101-
var serviceProvider = Package;
102-
var monitorSelection = (IVsMonitorSelection)serviceProvider.GetService(typeof(SVsShellMonitorSelection));
103-
if (monitorSelection == null)
104-
{
105-
yield break;
106-
}
102+
var result = new List<ITextView>();
107103

108-
object curDocument;
109-
if (ErrorHandler.Failed(monitorSelection.GetCurrentElementValue((uint)VSConstants.VSSELELEMID.SEID_DocumentFrame, out curDocument)))
104+
try
110105
{
111-
yield break;
112-
}
106+
var serviceProvider = Package;
107+
var monitorSelection = (IVsMonitorSelection)serviceProvider.GetService(typeof(SVsShellMonitorSelection));
108+
if (monitorSelection == null)
109+
{
110+
return result;
111+
}
113112

114-
IVsWindowFrame frame = curDocument as IVsWindowFrame;
115-
if (frame == null)
116-
{
117-
yield break;
118-
}
113+
object curDocument;
114+
if (ErrorHandler.Failed(monitorSelection.GetCurrentElementValue((uint)VSConstants.VSSELELEMID.SEID_DocumentFrame, out curDocument)))
115+
{
116+
return result;
117+
}
119118

120-
object docView = null;
121-
if (ErrorHandler.Failed(frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out docView)))
122-
{
123-
yield break;
124-
}
119+
IVsWindowFrame frame = curDocument as IVsWindowFrame;
120+
if (frame == null)
121+
{
122+
return result;
123+
}
125124

126-
if (docView is IVsDifferenceCodeWindow)
127-
{
128-
var diffWindow = (IVsDifferenceCodeWindow)docView;
129-
130-
switch (diffWindow.DifferenceViewer.ViewMode)
125+
object docView = null;
126+
if (ErrorHandler.Failed(frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out docView)))
131127
{
132-
case DifferenceViewMode.Inline:
133-
yield return diffWindow.DifferenceViewer.InlineView;
134-
break;
135-
case DifferenceViewMode.SideBySide:
136-
switch (diffWindow.DifferenceViewer.ActiveViewType)
137-
{
138-
case DifferenceViewType.LeftView:
139-
yield return diffWindow.DifferenceViewer.LeftView;
140-
yield return diffWindow.DifferenceViewer.RightView;
141-
break;
142-
case DifferenceViewType.RightView:
143-
yield return diffWindow.DifferenceViewer.RightView;
144-
yield return diffWindow.DifferenceViewer.LeftView;
145-
break;
146-
}
147-
yield return diffWindow.DifferenceViewer.LeftView;
148-
break;
149-
case DifferenceViewMode.RightViewOnly:
150-
yield return diffWindow.DifferenceViewer.RightView;
151-
break;
128+
return result;
152129
}
153-
}
154-
else if (docView is IVsCodeWindow)
155-
{
156-
IVsTextView textView;
157-
if (ErrorHandler.Failed(((IVsCodeWindow)docView).GetPrimaryView(out textView)))
130+
131+
if (docView is IVsDifferenceCodeWindow)
158132
{
159-
yield break;
133+
var diffWindow = (IVsDifferenceCodeWindow)docView;
134+
135+
switch (diffWindow.DifferenceViewer.ViewMode)
136+
{
137+
case DifferenceViewMode.Inline:
138+
result.Add(diffWindow.DifferenceViewer.InlineView);
139+
break;
140+
case DifferenceViewMode.SideBySide:
141+
switch (diffWindow.DifferenceViewer.ActiveViewType)
142+
{
143+
case DifferenceViewType.LeftView:
144+
result.Add(diffWindow.DifferenceViewer.LeftView);
145+
result.Add(diffWindow.DifferenceViewer.RightView);
146+
break;
147+
case DifferenceViewType.RightView:
148+
result.Add(diffWindow.DifferenceViewer.RightView);
149+
result.Add(diffWindow.DifferenceViewer.LeftView);
150+
break;
151+
}
152+
result.Add(diffWindow.DifferenceViewer.LeftView);
153+
break;
154+
case DifferenceViewMode.RightViewOnly:
155+
result.Add(diffWindow.DifferenceViewer.RightView);
156+
break;
157+
}
160158
}
159+
else if (docView is IVsCodeWindow)
160+
{
161+
IVsTextView textView;
162+
if (ErrorHandler.Failed(((IVsCodeWindow)docView).GetPrimaryView(out textView)))
163+
{
164+
return result;
165+
}
161166

162-
var model = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));
163-
var adapterFactory = model.GetService<IVsEditorAdaptersFactoryService>();
164-
var wpfTextView = adapterFactory.GetWpfTextView(textView);
165-
yield return wpfTextView;
167+
var model = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));
168+
var adapterFactory = model.GetService<IVsEditorAdaptersFactoryService>();
169+
var wpfTextView = adapterFactory.GetWpfTextView(textView);
170+
result.Add(wpfTextView);
171+
}
172+
}
173+
catch (Exception e)
174+
{
175+
VsOutputLogger.WriteLine("Exception in InlineCommentNavigationCommand.GetCurrentTextViews(): {0}", e);
166176
}
177+
178+
return result;
167179
}
168180

169181
/// <summary>

src/GitHub.VisualStudio/UI/Views/PullRequestDetailView.xaml.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ async Task DoOpenFile(IPullRequestFileNode file, bool workingDirectory)
8787
var fullPath = ViewModel.GetLocalFilePath(file);
8888
var fileName = workingDirectory ? fullPath : await ViewModel.ExtractFile(file, true);
8989

90-
using (new NewDocumentStateScope(__VSNEWDOCUMENTSTATE.NDS_Provisional, VSConstants.NewDocumentStateReason.SolutionExplorer))
90+
using (workingDirectory ? null : OpenInProvisionalTab())
9191
{
9292
var window = Services.Dte.ItemOperations.OpenFile(fileName);
9393
window.Document.ReadOnly = !workingDirectory;
@@ -127,7 +127,7 @@ async Task DoDiffFile(IPullRequestFileNode file, bool workingDirectory)
127127
}
128128

129129
IVsWindowFrame frame;
130-
using (new NewDocumentStateScope(__VSNEWDOCUMENTSTATE.NDS_Provisional, VSConstants.NewDocumentStateReason.SolutionExplorer))
130+
using (OpenInProvisionalTab())
131131
{
132132
var tooltip = $"{leftLabel}\nvs.\n{rightLabel}";
133133

@@ -315,5 +315,12 @@ void OpenHyperlink(object sender, ExecutedRoutedEventArgs e)
315315
VisualStudioBrowser.OpenUrl(uri);
316316
}
317317
}
318+
319+
static IDisposable OpenInProvisionalTab()
320+
{
321+
return new NewDocumentStateScope
322+
(__VSNEWDOCUMENTSTATE.NDS_Provisional,
323+
VSConstants.NewDocumentStateReason.SolutionExplorer);
324+
}
318325
}
319326
}

0 commit comments

Comments
 (0)