From c56ab7d788bec67f94cefe97025be16b7e6adf2d Mon Sep 17 00:00:00 2001 From: Heejae Chang Date: Tue, 21 Apr 2015 05:31:09 -0700 Subject: [PATCH] show no changes when there is no change. --- .../Def/Implementation/Preview/ChangeList.cs | 5 +- .../Def/Implementation/Preview/FileChange.cs | 11 ++-- .../Implementation/Preview/PreviewEngine.cs | 58 +++++++++++++++++-- .../Core/Def/ServicesVSResources.Designer.cs | 9 +++ .../Core/Def/ServicesVSResources.resx | 3 + 5 files changed, 76 insertions(+), 10 deletions(-) diff --git a/src/VisualStudio/Core/Def/Implementation/Preview/ChangeList.cs b/src/VisualStudio/Core/Def/Implementation/Preview/ChangeList.cs index 78218657a41..58486a57a60 100644 --- a/src/VisualStudio/Core/Def/Implementation/Preview/ChangeList.cs +++ b/src/VisualStudio/Core/Def/Implementation/Preview/ChangeList.cs @@ -1,14 +1,15 @@ // 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()); + internal AbstractChange[] Changes { get; private set; } public ChangeList(AbstractChange[] changes) diff --git a/src/VisualStudio/Core/Def/Implementation/Preview/FileChange.cs b/src/VisualStudio/Core/Def/Implementation/Preview/FileChange.cs index b92ee5b15d4..6f43eb761d6 100644 --- a/src/VisualStudio/Core/Def/Implementation/Preview/FileChange.cs +++ b/src/VisualStudio/Core/Def/Implementation/Preview/FileChange.cs @@ -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 diff --git a/src/VisualStudio/Core/Def/Implementation/Preview/PreviewEngine.cs b/src/VisualStudio/Core/Def/Implementation/Preview/PreviewEngine.cs index 007b827dc11..8a91be68837 100644 --- a/src/VisualStudio/Core/Def/Implementation/Preview/PreviewEngine.cs +++ b/src/VisualStudio/Core/Def/Implementation/Preview/PreviewEngine.cs @@ -1,5 +1,6 @@ // 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 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() + { + } + } } } diff --git a/src/VisualStudio/Core/Def/ServicesVSResources.Designer.cs b/src/VisualStudio/Core/Def/ServicesVSResources.Designer.cs index fddbac64843..a4612e6a743 100644 --- a/src/VisualStudio/Core/Def/ServicesVSResources.Designer.cs +++ b/src/VisualStudio/Core/Def/ServicesVSResources.Designer.cs @@ -692,6 +692,15 @@ internal class ServicesVSResources { } } + /// + /// Looks up a localized string similar to No Changes. + /// + internal static string NoChanges { + get { + return ResourceManager.GetString("NoChanges", resourceCulture); + } + } + /// /// Looks up a localized string similar to Not a valid value. /// diff --git a/src/VisualStudio/Core/Def/ServicesVSResources.resx b/src/VisualStudio/Core/Def/ServicesVSResources.resx index ef218f48680..c53f942d84d 100644 --- a/src/VisualStudio/Core/Def/ServicesVSResources.resx +++ b/src/VisualStudio/Core/Def/ServicesVSResources.resx @@ -462,4 +462,7 @@ Use the dropdown to view and switch to other projects this file may belong to. Enable and ignore future errors + + No Changes + \ No newline at end of file -- GitLab