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

Commit

Permalink
Merge pull request #1188 from github/fixes/1186-projection-buffers
Browse files Browse the repository at this point in the history
Handle inline comments in projection buffers.
  • Loading branch information
jcansdale authored Aug 23, 2017
2 parents d7db9e3 + 3e520e9 commit fc9254e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
13 changes: 13 additions & 0 deletions src/GitHub.InlineReviews/InlineCommentMarginProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using GitHub.InlineReviews.Views;
using GitHub.Services;
using GitHub.Settings;
using Microsoft.VisualStudio.Text.Projection;

namespace GitHub.InlineReviews
{
Expand Down Expand Up @@ -108,6 +109,18 @@ bool IsMarginVisible(ITextBuffer buffer)
}
}

var projection = buffer as IProjectionBuffer;
if (projection != null)
{
foreach (var source in projection.SourceBuffers)
{
if (IsMarginVisible(source))
{
return true;
}
}
}

return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,14 @@ public async Task<IPullRequestSession> GetSession(IPullRequestModel pullRequest)
public PullRequestTextBufferInfo GetTextBufferInfo(ITextBuffer buffer)
{
var projectionBuffer = buffer as IProjectionBuffer;
PullRequestTextBufferInfo result;

if (projectionBuffer == null)
if (buffer.Properties.TryGetProperty(typeof(PullRequestTextBufferInfo), out result))
{
return buffer.Properties.GetProperty<PullRequestTextBufferInfo>(typeof(PullRequestTextBufferInfo), null);
return result;
}
else

if (projectionBuffer != null)
{
foreach (var sourceBuffer in projectionBuffer.SourceBuffers)
{
Expand Down
26 changes: 24 additions & 2 deletions src/GitHub.InlineReviews/Tags/InlineCommentTagger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ Task<byte[]> IEditorContentSource.GetContent()

void Initialize()
{
document = buffer.Properties.GetProperty<ITextDocument>(typeof(ITextDocument));
document = TryGetDocument(buffer);

if (document == null)
return;
Expand Down Expand Up @@ -195,6 +195,27 @@ void Initialize()
initialized = true;
}

static ITextDocument TryGetDocument(ITextBuffer buffer)
{
ITextDocument result;

if (buffer.Properties.TryGetProperty(typeof(ITextDocument), out result))
return result;

var projection = buffer as IProjectionBuffer;

if (projection != null)
{
foreach (var source in projection.SourceBuffers)
{
if ((result = TryGetDocument(source)) != null)
return result;
}
}

return null;
}

static void ForgetWithLogging(Task task)
{
task.Catch(e => VsOutputLogger.WriteLine("Exception caught while executing background task: {0}", e)).Forget();
Expand Down Expand Up @@ -244,7 +265,8 @@ async Task SessionChanged(IPullRequestSession session)
if (snapshot == null) return;

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

if (file == null) return;

Expand Down
11 changes: 11 additions & 0 deletions src/GitHub.VisualStudio/UI/Views/PullRequestDetailView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using Task = System.Threading.Tasks.Task;
using Microsoft.VisualStudio.TextManager.Interop;
using System.Text;
using Microsoft.VisualStudio.Text.Projection;

namespace GitHub.VisualStudio.UI.Views
{
Expand Down Expand Up @@ -168,6 +169,16 @@ void AddBufferTag(ITextBuffer buffer, IPullRequestSession session, string path,
buffer.Properties.GetOrCreateSingletonProperty(
typeof(PullRequestTextBufferInfo),
() => new PullRequestTextBufferInfo(session, path, isLeftBuffer));

var projection = buffer as IProjectionBuffer;

if (projection != null)
{
foreach (var source in projection.SourceBuffers)
{
AddBufferTag(source, session, path, isLeftBuffer);
}
}
}

void ShowErrorInStatusBar(string message, Exception e)
Expand Down

0 comments on commit fc9254e

Please sign in to comment.