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

Commit fc9254e

Browse files
authored
Merge pull request #1188 from github/fixes/1186-projection-buffers
Handle inline comments in projection buffers.
2 parents d7db9e3 + 3e520e9 commit fc9254e

File tree

4 files changed

+53
-5
lines changed

4 files changed

+53
-5
lines changed

src/GitHub.InlineReviews/InlineCommentMarginProvider.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using GitHub.InlineReviews.Views;
1414
using GitHub.Services;
1515
using GitHub.Settings;
16+
using Microsoft.VisualStudio.Text.Projection;
1617

1718
namespace GitHub.InlineReviews
1819
{
@@ -108,6 +109,18 @@ bool IsMarginVisible(ITextBuffer buffer)
108109
}
109110
}
110111

112+
var projection = buffer as IProjectionBuffer;
113+
if (projection != null)
114+
{
115+
foreach (var source in projection.SourceBuffers)
116+
{
117+
if (IsMarginVisible(source))
118+
{
119+
return true;
120+
}
121+
}
122+
}
123+
111124
return false;
112125
}
113126
}

src/GitHub.InlineReviews/Services/PullRequestSessionManager.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,14 @@ public async Task<IPullRequestSession> GetSession(IPullRequestModel pullRequest)
8484
public PullRequestTextBufferInfo GetTextBufferInfo(ITextBuffer buffer)
8585
{
8686
var projectionBuffer = buffer as IProjectionBuffer;
87+
PullRequestTextBufferInfo result;
8788

88-
if (projectionBuffer == null)
89+
if (buffer.Properties.TryGetProperty(typeof(PullRequestTextBufferInfo), out result))
8990
{
90-
return buffer.Properties.GetProperty<PullRequestTextBufferInfo>(typeof(PullRequestTextBufferInfo), null);
91+
return result;
9192
}
92-
else
93+
94+
if (projectionBuffer != null)
9395
{
9496
foreach (var sourceBuffer in projectionBuffer.SourceBuffers)
9597
{

src/GitHub.InlineReviews/Tags/InlineCommentTagger.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ Task<byte[]> IEditorContentSource.GetContent()
160160

161161
void Initialize()
162162
{
163-
document = buffer.Properties.GetProperty<ITextDocument>(typeof(ITextDocument));
163+
document = TryGetDocument(buffer);
164164

165165
if (document == null)
166166
return;
@@ -195,6 +195,27 @@ void Initialize()
195195
initialized = true;
196196
}
197197

198+
static ITextDocument TryGetDocument(ITextBuffer buffer)
199+
{
200+
ITextDocument result;
201+
202+
if (buffer.Properties.TryGetProperty(typeof(ITextDocument), out result))
203+
return result;
204+
205+
var projection = buffer as IProjectionBuffer;
206+
207+
if (projection != null)
208+
{
209+
foreach (var source in projection.SourceBuffers)
210+
{
211+
if ((result = TryGetDocument(source)) != null)
212+
return result;
213+
}
214+
}
215+
216+
return null;
217+
}
218+
198219
static void ForgetWithLogging(Task task)
199220
{
200221
task.Catch(e => VsOutputLogger.WriteLine("Exception caught while executing background task: {0}", e)).Forget();
@@ -244,7 +265,8 @@ async Task SessionChanged(IPullRequestSession session)
244265
if (snapshot == null) return;
245266

246267
var repository = gitService.GetRepository(session.LocalRepository.LocalPath);
247-
file = await session.GetFile(relativePath, !leftHandSide ? this : null);
268+
var isContentSource = !leftHandSide && !(buffer is IProjectionBuffer);
269+
file = await session.GetFile(relativePath, isContentSource ? this : null);
248270

249271
if (file == null) return;
250272

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
using Task = System.Threading.Tasks.Task;
2727
using Microsoft.VisualStudio.TextManager.Interop;
2828
using System.Text;
29+
using Microsoft.VisualStudio.Text.Projection;
2930

3031
namespace GitHub.VisualStudio.UI.Views
3132
{
@@ -168,6 +169,16 @@ void AddBufferTag(ITextBuffer buffer, IPullRequestSession session, string path,
168169
buffer.Properties.GetOrCreateSingletonProperty(
169170
typeof(PullRequestTextBufferInfo),
170171
() => new PullRequestTextBufferInfo(session, path, isLeftBuffer));
172+
173+
var projection = buffer as IProjectionBuffer;
174+
175+
if (projection != null)
176+
{
177+
foreach (var source in projection.SourceBuffers)
178+
{
179+
AddBufferTag(source, session, path, isLeftBuffer);
180+
}
181+
}
171182
}
172183

173184
void ShowErrorInStatusBar(string message, Exception e)

0 commit comments

Comments
 (0)