提交 c56ab7d7 编写于 作者: H Heejae Chang

show no changes when there is no change.

上级 84e8e3b9
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis;
using System;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.VisualStudio.LanguageServices.Implementation.Utilities;
using Microsoft.VisualStudio.Shell.Interop;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Preview
{
internal partial class ChangeList : ForegroundThreadAffinitizedObject, IVsPreviewChangesList, IVsLiteTreeList
{
public readonly static ChangeList Empty = new ChangeList(Array.Empty<AbstractChange>());
internal AbstractChange[] Changes { get; private set; }
public ChangeList(AbstractChange[] changes)
......
......@@ -83,8 +83,8 @@ private ChangeList ComputeChildren(TextDocument left, TextDocument right, Cancel
var diff = ComputeDiffSpans(diffService, left, right, cancellationToken);
if (diff.Differences.Count == 0)
{
// There are no changes. Just show the whole document.
return GetEntireDocumentAsSpanChange(left);
// There are no changes.
return ChangeList.Empty;
}
return GetChangeList(diff, right.Id, oldText, newText);
......@@ -240,8 +240,11 @@ private static IHierarchicalDifferenceCollection ComputeDiffSpans(ITextDifferenc
var oldText = left.GetTextAsync(cancellationToken).WaitAndGetResult(cancellationToken);
var newText = right.GetTextAsync(cancellationToken).WaitAndGetResult(cancellationToken);
var oldString = oldText.ToString();
var newString = newText.ToString();
// first try, cheapest way.
var diffResult = diffService.DiffStrings(oldText.ToString(), newText.ToString(), new StringDifferenceOptions()
var diffResult = diffService.DiffStrings(oldString, newString, new StringDifferenceOptions()
{
DifferenceType = StringDifferenceTypes.Line | StringDifferenceTypes.Word,
WordSplitBehavior = WordSplitBehavior.WhiteSpaceAndPunctuation
......@@ -253,7 +256,7 @@ private static IHierarchicalDifferenceCollection ComputeDiffSpans(ITextDifferenc
}
// second, try a bit more expansive way
return diffService.DiffStrings(oldText.ToString(), newText.ToString(), new StringDifferenceOptions()
return diffService.DiffStrings(oldString, newString, new StringDifferenceOptions()
{
DifferenceType = StringDifferenceTypes.Word,
WordSplitBehavior = WordSplitBehavior.WhiteSpaceAndPunctuation
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
......@@ -10,6 +11,7 @@
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio.Editor;
using Microsoft.VisualStudio.Language.Intellisense;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Text.Differencing;
using Microsoft.VisualStudio.Text.Editor;
......@@ -36,7 +38,7 @@ internal class PreviewEngine : ForegroundThreadAffinitizedObject, IVsPreviewChan
private PreviewUpdater _updater;
public Solution FinalSolution { get; private set; }
public readonly bool ShowCheckBoxes;
public bool ShowCheckBoxes { get; private set; }
public PreviewEngine(string title, string helpString, string description, string topLevelItemName, Glyph topLevelGlyph, Solution newSolution, Solution oldSolution, IComponentModel componentModel, bool showCheckBoxes = true) :
this(title, helpString, description, topLevelItemName, topLevelGlyph, newSolution, oldSolution, componentModel, null, showCheckBoxes)
......@@ -134,8 +136,14 @@ public int GetRootChangesList(out object ppIUnknownPreviewChangesList)
// References (metadata/project/analyzer)
ReferenceChange.AppendReferenceChanges(projectChanges, this, builder);
_topLevelChange.Children = new ChangeList(builder.ToArray());
ppIUnknownPreviewChangesList = new ChangeList(new[] { _topLevelChange });
_topLevelChange.Children = builder.Count == 0 ? ChangeList.Empty : new ChangeList(builder.ToArray());
ppIUnknownPreviewChangesList = _topLevelChange.Children.Changes.Length == 0 ? new ChangeList(new[] { new NoChange(this) }) : new ChangeList(new[] { _topLevelChange });
if (_topLevelChange.Children.Changes.Length == 0)
{
this.ShowCheckBoxes = false;
}
return VSConstants.S_OK;
}
......@@ -169,7 +177,11 @@ private void AppendFileChanges(IEnumerable<DocumentId> changedDocuments, ArrayBu
linkedDocumentIds.AddRange(rightDocument.GetLinkedDocumentIds());
}
builder.Add(new FileChange(left, right, _componentModel, _topLevelChange, this, _imageService));
var fileChange = new FileChange(left, right, _componentModel, _topLevelChange, this, _imageService);
if (fileChange.Children.Changes.Length > 0)
{
builder.Add(fileChange);
}
}
}
......@@ -261,5 +273,43 @@ private static void EditBufferToInitialize(IVsTextView adapter)
Marshal.ThrowExceptionForHR(lines.ReplaceLines(0, 0, piLineIndex, piLineLength, newTextPtr, newText.Length, changes));
}
private class NoChange : AbstractChange
{
public NoChange(PreviewEngine engine) : base(engine)
{
}
public override int GetText(out VSTREETEXTOPTIONS tto, out string ppszText)
{
tto = VSTREETEXTOPTIONS.TTO_DEFAULT;
ppszText = ServicesVSResources.NoChanges;
return VSConstants.S_OK;
}
public override int GetTipText(out VSTREETOOLTIPTYPE eTipType, out string ppszText)
{
eTipType = VSTREETOOLTIPTYPE.TIPTYPE_DEFAULT;
ppszText = null;
return VSConstants.E_FAIL;
}
public override int CanRecurse => 0;
public override int IsExpandable => 0;
internal override void GetDisplayData(VSTREEDISPLAYDATA[] pData)
{
pData[0].Image = pData[0].SelectedImage = (ushort)StandardGlyphGroup.GlyphInformation;
}
public override int OnRequestSource(object pIUnknownTextView)
{
return VSConstants.S_OK;
}
public override void UpdatePreview()
{
}
}
}
}
......@@ -692,6 +692,15 @@ internal class ServicesVSResources {
}
}
/// <summary>
/// Looks up a localized string similar to No Changes.
/// </summary>
internal static string NoChanges {
get {
return ResourceManager.GetString("NoChanges", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Not a valid value.
/// </summary>
......
......@@ -462,4 +462,7 @@ Use the dropdown to view and switch to other projects this file may belong to.</
<data name="EnableAndIgnore" xml:space="preserve">
<value>Enable and ignore future errors</value>
</data>
<data name="NoChanges" xml:space="preserve">
<value>No Changes</value>
</data>
</root>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册