diff --git a/src/EditorFeatures/Core/Implementation/FindReferences/AbstractFindReferencesService.ProgressAdapter.cs b/src/EditorFeatures/Core/Implementation/FindReferences/AbstractFindReferencesService.ProgressAdapter.cs index c84ceea8bb6671f887b5519600b1a19e1644b628..71f83530edc3021fc173bd85691752367a515223 100644 --- a/src/EditorFeatures/Core/Implementation/FindReferences/AbstractFindReferencesService.ProgressAdapter.cs +++ b/src/EditorFeatures/Core/Implementation/FindReferences/AbstractFindReferencesService.ProgressAdapter.cs @@ -39,12 +39,15 @@ public ProgressAdapter(Solution solution, FindReferencesContext context) _definitionFactory = s => s.ToDefinitionItem(solution); } + // Do nothing functions. The streaming far service doesn't care about + // any of these. + public void OnStarted() { } + public void OnCompleted() { } + public void OnFindInDocumentStarted(Document document) { } + public void OnFindInDocumentCompleted(Document document) { } + // Simple context forwarding functions. - public void OnStarted() => _context.OnStarted(); - public void OnCompleted() => _context.OnCompleted(); public void ReportProgress(int current, int maximum) => _context.ReportProgress(current, maximum); - public void OnFindInDocumentStarted(Document document) => _context.OnFindInDocumentStarted(document); - public void OnFindInDocumentCompleted(Document document) => _context.OnFindInDocumentCompleted(document); // More complicated forwarding functions. These need to map from the symbols // used by the FAR engine to the INavigableItems used by the streaming FAR diff --git a/src/EditorFeatures/Core/Implementation/FindReferences/FindReferencesCommandHandler.cs b/src/EditorFeatures/Core/Implementation/FindReferences/FindReferencesCommandHandler.cs index 8135b2ce14b61de80b066d123195d801951d5d07..9c8b4218a456abf2984a2b6aee2a660339ec2ce4 100644 --- a/src/EditorFeatures/Core/Implementation/FindReferences/FindReferencesCommandHandler.cs +++ b/src/EditorFeatures/Core/Implementation/FindReferences/FindReferencesCommandHandler.cs @@ -8,6 +8,7 @@ using Microsoft.CodeAnalysis.Editor.Host; using Microsoft.CodeAnalysis.Editor.Shared.Extensions; using Microsoft.CodeAnalysis.Editor.Shared.Options; +using Microsoft.CodeAnalysis.ErrorReporting; using Microsoft.CodeAnalysis.FindReferences; using Microsoft.CodeAnalysis.Internal.Log; using Microsoft.CodeAnalysis.Shared.TestHooks; @@ -103,12 +104,25 @@ private bool TryExecuteCommand(int caretPosition, Document document) Document document, IStreamingFindReferencesService service, IStreamingFindReferencesPresenter presenter, int caretPosition) { - using (var token = _asyncListener.BeginAsyncOperation(nameof(StreamingFindReferences))) + try + { + using (var token = _asyncListener.BeginAsyncOperation(nameof(StreamingFindReferences))) + { + // Let the presented know we're starging a search. It will give us back + // the context object that the FAR service will push results into. + var context = presenter.StartSearch(); + await service.FindReferencesAsync(document, caretPosition, context).ConfigureAwait(false); + + // Note: we don't need to put this in a finally. The only time we might not hit + // this is if cancellation or another error gets thrown. In the former case, + // that means that a new search has started. We don't care about telling the + // context it has completed. In the latter case somethign wrong has happened + // and we don't want to run any more code code in this particular context. + context.OnCompleted(); + } + } + catch (Exception e) when (FatalError.ReportUnlessCanceled(e)) { - // Let the presented know we're starging a search. It will give us back - // the context object that the FAR service will push results into. - var context = presenter.StartSearch(); - await service.FindReferencesAsync(document, caretPosition, context).ConfigureAwait(false); } } diff --git a/src/EditorFeatures/Core/Implementation/FindReferences/FindReferencesContext.cs b/src/EditorFeatures/Core/Implementation/FindReferences/FindReferencesContext.cs index aa62ef32064bc0102da51831865525da7566ac16..b32389ae1d653b68219af8b1fb5dc838d8c84a82 100644 --- a/src/EditorFeatures/Core/Implementation/FindReferences/FindReferencesContext.cs +++ b/src/EditorFeatures/Core/Implementation/FindReferences/FindReferencesContext.cs @@ -18,22 +18,10 @@ public virtual void SetSearchLabel(string displayName) { } - public virtual void OnStarted() - { - } - public virtual void OnCompleted() { } - public virtual void OnFindInDocumentStarted(Document document) - { - } - - public virtual void OnFindInDocumentCompleted(Document document) - { - } - public virtual void OnDefinitionFound(DefinitionItem definition) { } diff --git a/src/EditorFeatures/Core/Implementation/IntelliSense/QuickInfo/DeferredContent/ElisionBufferDeferredContent.cs b/src/EditorFeatures/Core/Implementation/IntelliSense/QuickInfo/DeferredContent/ElisionBufferDeferredContent.cs index 7c38c59645dc2966721422d83072964d46b89b90..ed6ead8bcf5f21a2373827f2669335498130e81a 100644 --- a/src/EditorFeatures/Core/Implementation/IntelliSense/QuickInfo/DeferredContent/ElisionBufferDeferredContent.cs +++ b/src/EditorFeatures/Core/Implementation/IntelliSense/QuickInfo/DeferredContent/ElisionBufferDeferredContent.cs @@ -1,14 +1,14 @@ // 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.Windows; +using System.Windows.Controls; +using System.Windows.Media; using Microsoft.CodeAnalysis.Editor.Shared.Extensions; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text.Editor; using Microsoft.VisualStudio.Text.Projection; using Microsoft.VisualStudio.Utilities; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Media; namespace Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.QuickInfo { diff --git a/src/EditorFeatures/Core/Implementation/Preview/PreviewReferenceHighlightingTaggerProvider.cs b/src/EditorFeatures/Core/Implementation/Preview/PreviewReferenceHighlightingTaggerProvider.cs index a854dda474ec1ebdc092095b2c3d48ced516b667..a850f958b558ea4be2af5b9b78b5eab156f30644 100644 --- a/src/EditorFeatures/Core/Implementation/Preview/PreviewReferenceHighlightingTaggerProvider.cs +++ b/src/EditorFeatures/Core/Implementation/Preview/PreviewReferenceHighlightingTaggerProvider.cs @@ -8,6 +8,10 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.Preview { + /// + /// Special tagger we use for previews that is told precisely which spans to + /// reference highlight. + /// [Export(typeof(ITaggerProvider))] [TagType(typeof(NavigableHighlightTag))] [ContentType(ContentTypeNames.RoslynContentType)] diff --git a/src/EditorFeatures/Core/Shared/Extensions/GlyphExtensions.cs b/src/EditorFeatures/Core/Shared/Extensions/GlyphExtensions.cs index f83921f02cdd7129cc3f7619706122e7a38cbe11..c4a6355a20bbf51764b63a501bd39063b6a0812c 100644 --- a/src/EditorFeatures/Core/Shared/Extensions/GlyphExtensions.cs +++ b/src/EditorFeatures/Core/Shared/Extensions/GlyphExtensions.cs @@ -383,6 +383,9 @@ public static ImageMoniker GetImageMoniker(this Glyph glyph) case Glyph.CompletionWarning: return KnownMonikers.IntellisenseWarning; + case Glyph.StatusInformation: + return KnownMonikers.StatusInformation; + case Glyph.NuGet: return KnownMonikers.NuGet; @@ -629,6 +632,9 @@ public static Glyph GetGlyph(this ImmutableArray tags) case CompletionTags.Warning: return Glyph.CompletionWarning; + + case CompletionTags.StatusInformation: + return Glyph.StatusInformation; } } diff --git a/src/Features/Core/Portable/Common/Glyph.cs b/src/Features/Core/Portable/Common/Glyph.cs index d538425b46d076d0f64ebe74f776ada73635f428..35681606c3432b370b78c2cdf51997ce3fa0dd91 100644 --- a/src/Features/Core/Portable/Common/Glyph.cs +++ b/src/Features/Core/Portable/Common/Glyph.cs @@ -35,6 +35,7 @@ internal enum Glyph EnumMember, Error, + StatusInformation, EventPublic, EventProtected, diff --git a/src/Features/Core/Portable/Completion/CompletionTags.cs b/src/Features/Core/Portable/Completion/CompletionTags.cs index a1d70931414ad1647da1c8cdf81397024f08a96b..cc5d8d9e5c4346e8fbe7c3d2b718b5a1453dabd4 100644 --- a/src/Features/Core/Portable/Completion/CompletionTags.cs +++ b/src/Features/Core/Portable/Completion/CompletionTags.cs @@ -50,6 +50,7 @@ public static class CompletionTags public const string Snippet = nameof(Snippet); public const string Error = nameof(Error); public const string Warning = nameof(Warning); + internal const string StatusInformation = nameof(StatusInformation); // Currently needed, but removed from Dev15. Internal so no one accidently takes a // dependency on them. diff --git a/src/Features/Core/Portable/Completion/GlyphTags.cs b/src/Features/Core/Portable/Completion/GlyphTags.cs index 1673f7d415345fb7bf37942db572aa5f5e4bee6a..2efe9dd9e6d189a14edb3cc5a9d3337c925e2006 100644 --- a/src/Features/Core/Portable/Completion/GlyphTags.cs +++ b/src/Features/Core/Portable/Completion/GlyphTags.cs @@ -146,6 +146,8 @@ public static ImmutableArray GetTags(Glyph glyph) return Snippet; case Glyph.CompletionWarning: return Warning; + case Glyph.StatusInformation: + return StatusInformation; default: return ImmutableArray.Empty; } @@ -216,6 +218,7 @@ public static ImmutableArray GetTags(Glyph glyph) private static readonly ImmutableArray Error = ImmutableArray.Create(CompletionTags.Error); private static readonly ImmutableArray Warning = ImmutableArray.Create(CompletionTags.Warning); + private static readonly ImmutableArray StatusInformation = ImmutableArray.Create(CompletionTags.StatusInformation); private static readonly ImmutableArray CSharpFile = ImmutableArray.Create(CompletionTags.File, LanguageNames.CSharp); private static readonly ImmutableArray VisualBasicFile = ImmutableArray.Create(CompletionTags.File, LanguageNames.VisualBasic); diff --git a/src/VisualStudio/Core/Def.Next/FindReferences/StreamingFindReferencesPresenter.NoneFoundReferenceEntry.cs b/src/VisualStudio/Core/Def.Next/FindReferences/StreamingFindReferencesPresenter.NoneFoundReferenceEntry.cs deleted file mode 100644 index 694a8b8b45a7bbed6e1df4037996a5e18073b38c..0000000000000000000000000000000000000000 --- a/src/VisualStudio/Core/Def.Next/FindReferences/StreamingFindReferencesPresenter.NoneFoundReferenceEntry.cs +++ /dev/null @@ -1,27 +0,0 @@ -using Microsoft.CodeAnalysis; -using Microsoft.VisualStudio.Shell.TableManager; - -namespace Microsoft.VisualStudio.LanguageServices.FindReferences -{ - internal partial class StreamingFindReferencesPresenter - { - private class NoneFoundReferenceEntry : ReferenceEntry - { - public NoneFoundReferenceEntry(RoslynDefinitionBucket definitionBucket) - : base(definitionBucket) - { - } - - protected override object GetValueWorker(string keyName) - { - switch (keyName) - { - case StandardTableKeyNames.Text: - return $"No references found to '{DefinitionBucket.DefinitionItem.DisplayParts.JoinText()}'"; - } - - return null; - } - } - } -} diff --git a/src/VisualStudio/Core/Def.Next/FindReferences/StreamingFindReferencesPresenter.SimpleMessageReferenceEntry.cs b/src/VisualStudio/Core/Def.Next/FindReferences/StreamingFindReferencesPresenter.SimpleMessageReferenceEntry.cs new file mode 100644 index 0000000000000000000000000000000000000000..1f49216840b1f12d2c79bea73eacaa2fb5283ec6 --- /dev/null +++ b/src/VisualStudio/Core/Def.Next/FindReferences/StreamingFindReferencesPresenter.SimpleMessageReferenceEntry.cs @@ -0,0 +1,41 @@ +using System.Threading.Tasks; +using Microsoft.CodeAnalysis; +using Microsoft.VisualStudio.Shell.TableManager; + +namespace Microsoft.VisualStudio.LanguageServices.FindReferences +{ + internal partial class StreamingFindReferencesPresenter + { + private class SimpleMessageReferenceEntry : ReferenceEntry + { + private readonly string _message; + + private SimpleMessageReferenceEntry( + RoslynDefinitionBucket definitionBucket, + string message) + : base(definitionBucket) + { + _message = message; + } + + public static Task CreateAsync( + RoslynDefinitionBucket definitionBucket, + string message) + { + var referenceEntry = new SimpleMessageReferenceEntry(definitionBucket, message); + return Task.FromResult(referenceEntry); + } + + protected override object GetValueWorker(string keyName) + { + switch (keyName) + { + case StandardTableKeyNames.Text: + return _message; + } + + return null; + } + } + } +} diff --git a/src/VisualStudio/Core/Def.Next/FindReferences/StreamingFindReferencesPresenter.TableDataSourceFindReferencesContext.cs b/src/VisualStudio/Core/Def.Next/FindReferences/StreamingFindReferencesPresenter.TableDataSourceFindReferencesContext.cs index 93596d89ecc8c091bda7abf516433f50bb4d8a59..7395f5db320258c4afe337fdaae340f982ca802b 100644 --- a/src/VisualStudio/Core/Def.Next/FindReferences/StreamingFindReferencesPresenter.TableDataSourceFindReferencesContext.cs +++ b/src/VisualStudio/Core/Def.Next/FindReferences/StreamingFindReferencesPresenter.TableDataSourceFindReferencesContext.cs @@ -1,7 +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.Concurrent; using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; @@ -17,9 +16,9 @@ using Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem; using Microsoft.VisualStudio.Shell.FindAllReferences; using Microsoft.VisualStudio.Shell.TableManager; -using Microsoft.CodeAnalysis.Editor.Shared.Preview; -using Microsoft.VisualStudio.Text; using Roslyn.Utilities; +using Microsoft.CodeAnalysis.Completion; +using System.Diagnostics; namespace Microsoft.VisualStudio.LanguageServices.FindReferences { @@ -30,7 +29,7 @@ private class TableDataSourceFindReferencesContext : { private readonly CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource(); - private readonly ConcurrentBag _subscriptions = new ConcurrentBag(); + private ITableDataSink _tableDataSink; public readonly StreamingFindReferencesPresenter Presenter; private readonly IFindAllReferencesWindow _findReferencesWindow; @@ -76,6 +75,10 @@ private class TableDataSourceFindReferencesContext : // And add ourselves as the source of results for the window. findReferencesWindow.Manager.AddSource(this); + + // After adding us as the source, the manager should immediately call into us to + // tell us what the data sink is. + Debug.Assert(_tableDataSink != null); } private void CancelSearch() @@ -101,12 +104,15 @@ internal void OnSubscriptionDisposed() public IDisposable Subscribe(ITableDataSink sink) { - var subscription = new Subscription(this, sink); - _subscriptions.Add(subscription); + Presenter.AssertIsForeground(); - sink.AddFactory(this, removeAllFactories: true); + Debug.Assert(_tableDataSink == null); + _tableDataSink = sink; - return subscription; + _tableDataSink.AddFactory(this, removeAllFactories: true); + _tableDataSink.IsStable = false; + + return this; } #endregion @@ -122,25 +128,41 @@ public override void SetSearchLabel(string displayName) } } - public override void OnStarted() + public override void OnCompleted() { - foreach (var subscription in _subscriptions) - { - subscription.TableDataSink.IsStable = false; - } + // Now that we know the search is over, create and display any error messages + // for definitions that were not found. + CreateMissingReferenceEntriesIfNecessary(); + CreateNoResultsFoundEntryIfNecessary(); + + _tableDataSink.IsStable = true; } - public override void OnCompleted() + private void CreateNoResultsFoundEntryIfNecessary() { - CreateMissingReferenceEntries(); + bool noDefinitions; + lock(_gate) + { + noDefinitions = this._definitions.Count == 0; + } - foreach (var subscription in _subscriptions) + if (noDefinitions) { - subscription.TableDataSink.IsStable = true; + // Create a fake definition/reference called "search found no results" + this.OnReferenceFound(NoResultsDefinitionItem, + (db, c) => SimpleMessageReferenceEntry.CreateAsync( + db, ServicesVisualStudioNextResources.Search_found_no_results)); } } - private void CreateMissingReferenceEntries() + private static DefinitionItem NoResultsDefinitionItem = + DefinitionItem.CreateNonNavigableItem( + GlyphTags.GetTags(Glyph.StatusInformation), + ImmutableArray.Create(new TaggedText( + TextTags.Text, + ServicesVisualStudioNextResources.Search_found_no_results))); + + private void CreateMissingReferenceEntriesIfNecessary() { // Go through and add dummy entries for any definitions that // that we didn't find any references for. @@ -148,8 +170,14 @@ private void CreateMissingReferenceEntries() var definitions = GetDefinitionsToCreateMissingReferenceItemsFor(); foreach (var definition in definitions) { + // Create a fake reference to this definition that says + // "no references found to ". + var message = string.Format( + ServicesVisualStudioNextResources.No_references_found_to_0, + definition.DisplayParts.JoinText()); OnReferenceFound(definition, - (db, c) => Task.FromResult(new NoneFoundReferenceEntry(db))); + (db, c) => SimpleMessageReferenceEntry.CreateAsync( + db, message)); } } @@ -234,7 +262,7 @@ public override void OnReferenceFound(SourceReferenceItem reference) } // Let all our subscriptions know that we've updated. - NotifySinksOfChangedVersion(); + _tableDataSink.FactorySnapshotChanged(this); } private async Task CreateReferenceEntryAsync( @@ -323,14 +351,6 @@ private RoslynDefinitionBucket GetOrCreateDefinitionBucket(DefinitionItem defini } } - private void NotifySinksOfChangedVersion() - { - foreach (var subscription in _subscriptions) - { - subscription.TableDataSink.FactorySnapshotChanged(this); - } - } - public override void ReportProgress(int current, int maximum) { //var progress = maximum == 0 ? 0 : ((double)current / maximum); @@ -374,7 +394,7 @@ public ITableEntriesSnapshot GetSnapshot(int versionNumber) // We didn't have this version. Notify the sinks that something must have changed // so that they call back into us with the latest version. - NotifySinksOfChangedVersion(); + _tableDataSink.FactorySnapshotChanged(this); return null; } diff --git a/src/VisualStudio/Core/Def.Next/ServicesVisualStudio.Next.csproj b/src/VisualStudio/Core/Def.Next/ServicesVisualStudio.Next.csproj index b5a679a2777483e86db0151ed0c613356ec824ff..3f896595396a3b82a5f0ce5a7278ed9bce722c33 100644 --- a/src/VisualStudio/Core/Def.Next/ServicesVisualStudio.Next.csproj +++ b/src/VisualStudio/Core/Def.Next/ServicesVisualStudio.Next.csproj @@ -30,7 +30,7 @@ - + @@ -38,6 +38,11 @@ + + True + True + ServicesVisualStudioNextResources.resx + @@ -138,6 +143,12 @@ + + + ResXFileCodeGenerator + ServicesVisualStudioNextResources.Designer.cs + + diff --git a/src/VisualStudio/Core/Def.Next/ServicesVisualStudioNextResources.Designer.cs b/src/VisualStudio/Core/Def.Next/ServicesVisualStudioNextResources.Designer.cs new file mode 100644 index 0000000000000000000000000000000000000000..c6f148a9ea979f719fe137ba942cbdf59f460181 --- /dev/null +++ b/src/VisualStudio/Core/Def.Next/ServicesVisualStudioNextResources.Designer.cs @@ -0,0 +1,81 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Microsoft.VisualStudio.LanguageServices { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class ServicesVisualStudioNextResources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal ServicesVisualStudioNextResources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.VisualStudio.LanguageServices.ServicesVisualStudioNextResources", typeof(ServicesVisualStudioNextResources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to No references found to '{0}'. + /// + internal static string No_references_found_to_0 { + get { + return ResourceManager.GetString("No_references_found_to_0", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Search found no results. + /// + internal static string Search_found_no_results { + get { + return ResourceManager.GetString("Search_found_no_results", resourceCulture); + } + } + } +} diff --git a/src/VisualStudio/Core/Def.Next/ServicesVisualStudioNextResources.resx b/src/VisualStudio/Core/Def.Next/ServicesVisualStudioNextResources.resx new file mode 100644 index 0000000000000000000000000000000000000000..ab9aac2ccca240e0e11f9e7bdfbe390cbba3b924 --- /dev/null +++ b/src/VisualStudio/Core/Def.Next/ServicesVisualStudioNextResources.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + No references found to '{0}' + + + Search found no results + + \ No newline at end of file