From e93843623312903351514643be724a1c6d68c737 Mon Sep 17 00:00:00 2001 From: tmat Date: Fri, 28 Jan 2022 11:35:35 -0800 Subject: [PATCH 1/6] Add external access API for find usages --- ...oDefinitionServiceFactoryImplementation.cs | 13 +++ .../Api/IVSTypeScriptFindUsagesContext.cs | 106 ++++++++++++++---- .../Api/IVSTypeScriptGoToDefinitionService.cs | 16 +++ ...oDefinitionServiceFactoryImplementation.cs | 13 +++ ...peScriptGoToSymbolServiceImplementation.cs | 13 +++ ...STypeScriptStreamingFindUsagesPresenter.cs | 19 ++++ .../Api/VSTypeScriptDocumentSpan.cs | 8 ++ .../Api/VSTypeScriptFindUsagesContext.cs | 36 ++++++ .../Api/VSTypeScriptGoToSymbolContext.cs | 31 +++++ .../Api/VSTypeScriptWellKnownSymbolTypes.cs | 13 +++ .../VSTypeScriptFindUsagesService.cs | 53 +++------ ...STypeScriptGoToDefinitionServiceFactory.cs | 49 ++++++++ .../VSTypeScriptGoToSymbolService.cs | 26 +++++ ...STypeScriptStreamingFindUsagesPresenter.cs | 41 +++++++ .../VSTypeScriptStreamingProgressTracker.cs | 27 +++++ .../Core/FindUsages/IFindUsagesService.cs | 1 - .../Core/GoToDefinition/GoToSymbolContext.cs | 15 ++- .../GoToDefinition/WellKnownSymbolTypes.cs | 4 +- ...ateToSearchService.WrappedNavigableItem.cs | 40 +++++++ .../VSTypeScriptNavigateToSearchService.cs | 33 +----- .../DefinitionItem.DefaultDefinitionItem.cs | 4 +- .../Portable/FindUsages/DefinitionItem.cs | 20 ++-- 22 files changed, 463 insertions(+), 118 deletions(-) create mode 100644 src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/ITypeScriptGoToDefinitionServiceFactoryImplementation.cs create mode 100644 src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionService.cs create mode 100644 src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionServiceFactoryImplementation.cs create mode 100644 src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToSymbolServiceImplementation.cs create mode 100644 src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptStreamingFindUsagesPresenter.cs create mode 100644 src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/VSTypeScriptFindUsagesContext.cs create mode 100644 src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/VSTypeScriptGoToSymbolContext.cs create mode 100644 src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/VSTypeScriptWellKnownSymbolTypes.cs create mode 100644 src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptGoToDefinitionServiceFactory.cs create mode 100644 src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptGoToSymbolService.cs create mode 100644 src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptStreamingFindUsagesPresenter.cs create mode 100644 src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptStreamingProgressTracker.cs create mode 100644 src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptNavigateToSearchService.WrappedNavigableItem.cs diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/ITypeScriptGoToDefinitionServiceFactoryImplementation.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/ITypeScriptGoToDefinitionServiceFactoryImplementation.cs new file mode 100644 index 0000000000000..03d7813de6eb7 --- /dev/null +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/ITypeScriptGoToDefinitionServiceFactoryImplementation.cs @@ -0,0 +1,13 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Microsoft.CodeAnalysis.Host; + +namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api +{ + internal interface ITypeScriptGoToDefinitionServiceFactoryImplementation + { + ILanguageService CreateLanguageService(HostLanguageServices languageServices); + } +} diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptFindUsagesContext.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptFindUsagesContext.cs index cee552048774a..1230f31936fc4 100644 --- a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptFindUsagesContext.cs +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptFindUsagesContext.cs @@ -2,9 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; using System.Collections.Immutable; using System.Threading; using System.Threading.Tasks; +using Microsoft.CodeAnalysis.FindUsages; namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api { @@ -36,8 +38,29 @@ internal interface IVSTypeScriptStreamingProgressTracker ValueTask ItemCompletedAsync(CancellationToken cancellationToken); } - internal class VSTypeScriptDefinitionItem + internal sealed class VSTypeScriptDefinitionItem { + internal readonly DefinitionItem UnderlyingObject; + + internal VSTypeScriptDefinitionItem(DefinitionItem underlyingObject) + => UnderlyingObject = underlyingObject; + + public static VSTypeScriptDefinitionItem Create( + ImmutableArray tags, + ImmutableArray displayParts, + ImmutableArray sourceSpans, + ImmutableArray nameDisplayParts = default, + bool displayIfNoReferences = true) + { + return new(DefinitionItem.Create( + tags, displayParts, sourceSpans.SelectAsArray(span => span.ToDocumentSpan()), nameDisplayParts, + properties: null, displayableProperties: ImmutableDictionary.Empty, displayIfNoReferences: displayIfNoReferences)); + } + + public static VSTypeScriptDefinitionItem Create(VSTypeScriptDefinitionItemBase item) + => new(item); + + [Obsolete] public VSTypeScriptDefinitionItem( ImmutableArray tags, ImmutableArray displayParts, @@ -47,38 +70,77 @@ public VSTypeScriptDefinitionItem( ImmutableDictionary? displayableProperties = null, bool displayIfNoReferences = true) { - Tags = tags; - DisplayParts = displayParts; - SourceSpans = sourceSpans; - NameDisplayParts = nameDisplayParts; - Properties = properties; - DisplayableProperties = displayableProperties; - DisplayIfNoReferences = displayIfNoReferences; + UnderlyingObject = new DefinitionItem.DefaultDefinitionItem( + tags, displayParts, nameDisplayParts, originationParts: ImmutableArray.Empty, sourceSpans, properties, displayableProperties, displayIfNoReferences); } - public ImmutableArray Tags { get; } - public ImmutableArray DisplayParts { get; } - public ImmutableArray SourceSpans { get; } - public ImmutableArray NameDisplayParts { get; } - public ImmutableDictionary? Properties { get; } - public ImmutableDictionary? DisplayableProperties { get; } - public bool DisplayIfNoReferences { get; } + public ImmutableArray Tags => UnderlyingObject.Tags; + public ImmutableArray DisplayParts => UnderlyingObject.DisplayParts; + + [Obsolete] + public ImmutableArray SourceSpans => UnderlyingObject.SourceSpans; + + public ImmutableArray GetSourceSpans() + => UnderlyingObject.SourceSpans.SelectAsArray(span => new VSTypeScriptDocumentSpan(span)); + + public Task CanNavigateToAsync(Workspace workspace, CancellationToken cancellationToken) + => UnderlyingObject.CanNavigateToAsync(workspace, cancellationToken); + + public Task TryNavigateToAsync(Workspace workspace, bool showInPreviewTab, bool activateTab, CancellationToken cancellationToken) + => UnderlyingObject.TryNavigateToAsync(workspace, showInPreviewTab, activateTab, cancellationToken); } - internal class VSTypeScriptSourceReferenceItem + internal sealed class VSTypeScriptSourceReferenceItem { + internal readonly SourceReferenceItem UnderlyingObject; + + public VSTypeScriptSourceReferenceItem( + VSTypeScriptDefinitionItem definition, + VSTypeScriptDocumentSpan sourceSpan, + VSTypeScriptSymbolUsageInfo symbolUsageInfo) + { + UnderlyingObject = new SourceReferenceItem(definition.UnderlyingObject, sourceSpan.ToDocumentSpan(), symbolUsageInfo.UnderlyingObject); + } + + [Obsolete] public VSTypeScriptSourceReferenceItem( VSTypeScriptDefinitionItem definition, DocumentSpan sourceSpan, SymbolUsageInfo symbolUsageInfo) { - Definition = definition; - SourceSpan = sourceSpan; - SymbolUsageInfo = symbolUsageInfo; + UnderlyingObject = new SourceReferenceItem(definition.UnderlyingObject, sourceSpan, symbolUsageInfo); } - public VSTypeScriptDefinitionItem Definition { get; } - public DocumentSpan SourceSpan { get; } - public SymbolUsageInfo SymbolUsageInfo { get; } + public VSTypeScriptDocumentSpan GetSourceSpan() + => new(UnderlyingObject.SourceSpan); + + [Obsolete] + public DocumentSpan SourceSpan + => UnderlyingObject.SourceSpan; + } + + internal readonly struct VSTypeScriptSymbolUsageInfo + { + internal readonly SymbolUsageInfo UnderlyingObject; + + private VSTypeScriptSymbolUsageInfo(SymbolUsageInfo underlyingObject) + => UnderlyingObject = underlyingObject; + + public static VSTypeScriptSymbolUsageInfo Create(VSTypeScriptValueUsageInfo valueUsageInfo) + => new(SymbolUsageInfo.Create((ValueUsageInfo)valueUsageInfo)); + } + + [Flags] + internal enum VSTypeScriptValueUsageInfo + { + None = ValueUsageInfo.None, + Read = ValueUsageInfo.Read, + Write = ValueUsageInfo.Write, + Reference = ValueUsageInfo.Reference, + Name = ValueUsageInfo.Name, + ReadWrite = ValueUsageInfo.ReadWrite, + ReadableReference = ValueUsageInfo.ReadableReference, + WritableReference = ValueUsageInfo.WritableReference, + ReadableWritableReference = ValueUsageInfo.ReadableWritableReference } } diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionService.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionService.cs new file mode 100644 index 0000000000000..cb8785f71d675 --- /dev/null +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionService.cs @@ -0,0 +1,16 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Threading; +using System.Threading.Tasks; +using System.Collections.Generic; + +namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api +{ + internal interface IVSTypeScriptGoToDefinitionService + { + Task?> FindDefinitionsAsync(Document document, int position, CancellationToken cancellationToken); + bool TryGoToDefinition(Document document, int position, CancellationToken cancellationToken); + } +} diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionServiceFactoryImplementation.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionServiceFactoryImplementation.cs new file mode 100644 index 0000000000000..f9c7e5777716a --- /dev/null +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionServiceFactoryImplementation.cs @@ -0,0 +1,13 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Microsoft.CodeAnalysis.Host; + +namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api +{ + internal interface IVSTypeScriptGoToDefinitionServiceFactoryImplementation + { + IVSTypeScriptGoToDefinitionService CreateLanguageService(HostLanguageServices languageServices); + } +} diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToSymbolServiceImplementation.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToSymbolServiceImplementation.cs new file mode 100644 index 0000000000000..3849cd9367bf4 --- /dev/null +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToSymbolServiceImplementation.cs @@ -0,0 +1,13 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Threading.Tasks; + +namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api +{ + internal interface IVSTypeScriptGoToSymbolServiceImplementation + { + Task GetSymbolsAsync(VSTypeScriptGoToSymbolContext context); + } +} diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptStreamingFindUsagesPresenter.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptStreamingFindUsagesPresenter.cs new file mode 100644 index 0000000000000..4b5b45268a26f --- /dev/null +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptStreamingFindUsagesPresenter.cs @@ -0,0 +1,19 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Threading; + +namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api +{ + internal interface IVSTypeScriptStreamingFindUsagesPresenter + { + (VSTypeScriptFindUsagesContext context, CancellationToken cancellationToken) StartSearch( + string title, bool supportsReferences); + + (VSTypeScriptFindUsagesContext context, CancellationToken cancellationToken) StartSearchWithCustomColumns( + string title, bool supportsReferences, bool includeContainingTypeAndMemberColumns, bool includeKindColumn); + + void ClearAll(); + } +} diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/VSTypeScriptDocumentSpan.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/VSTypeScriptDocumentSpan.cs index 2af32609217b3..9aa9cc2e5a526 100644 --- a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/VSTypeScriptDocumentSpan.cs +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/VSTypeScriptDocumentSpan.cs @@ -18,5 +18,13 @@ public VSTypeScriptDocumentSpan(Document document, TextSpan sourceSpan) Document = document; SourceSpan = sourceSpan; } + + internal VSTypeScriptDocumentSpan(DocumentSpan span) + : this(span.Document, span.SourceSpan) + { + } + + internal DocumentSpan ToDocumentSpan() + => new(Document, SourceSpan); } } diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/VSTypeScriptFindUsagesContext.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/VSTypeScriptFindUsagesContext.cs new file mode 100644 index 0000000000000..c8388c75ec7df --- /dev/null +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/VSTypeScriptFindUsagesContext.cs @@ -0,0 +1,36 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Threading; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis.FindUsages; + +namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api +{ + internal sealed class VSTypeScriptFindUsagesContext : IVSTypeScriptFindUsagesContext + { + internal readonly FindUsagesContext UnderlyingObject; + + public VSTypeScriptFindUsagesContext(FindUsagesContext underlyingObject) + => UnderlyingObject = underlyingObject; + + public IVSTypeScriptStreamingProgressTracker ProgressTracker + => new VSTypeScriptStreamingProgressTracker(UnderlyingObject.ProgressTracker); + + public ValueTask ReportMessageAsync(string message, CancellationToken cancellationToken) + => UnderlyingObject.ReportMessageAsync(message, cancellationToken); + + public ValueTask SetSearchTitleAsync(string title, CancellationToken cancellationToken) + => UnderlyingObject.SetSearchTitleAsync(title, cancellationToken); + + public ValueTask OnDefinitionFoundAsync(VSTypeScriptDefinitionItem definition, CancellationToken cancellationToken) + => UnderlyingObject.OnDefinitionFoundAsync(definition.UnderlyingObject, cancellationToken); + + public ValueTask OnReferenceFoundAsync(VSTypeScriptSourceReferenceItem reference, CancellationToken cancellationToken) + => UnderlyingObject.OnReferenceFoundAsync(reference.UnderlyingObject, cancellationToken); + + public ValueTask OnCompletedAsync(CancellationToken cancellationToken) + => UnderlyingObject.OnCompletedAsync(cancellationToken); + } +} diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/VSTypeScriptGoToSymbolContext.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/VSTypeScriptGoToSymbolContext.cs new file mode 100644 index 0000000000000..ddde670b0cb32 --- /dev/null +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/VSTypeScriptGoToSymbolContext.cs @@ -0,0 +1,31 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Threading; +using Microsoft.CodeAnalysis.Text; +using Microsoft.CodeAnalysis.Editor.GoToDefinition; + +namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api +{ + internal sealed class VSTypeScriptGoToSymbolContext + { + internal readonly GoToSymbolContext UnderlyingObject; + + internal VSTypeScriptGoToSymbolContext(GoToSymbolContext underlyingObject) + => UnderlyingObject = underlyingObject; + + public Document Document => UnderlyingObject.Document; + public int Position => UnderlyingObject.Position; + public CancellationToken CancellationToken => UnderlyingObject.CancellationToken; + + public TextSpan Span + { + get => UnderlyingObject.Span; + set => UnderlyingObject.Span = value; + } + + public void AddItem(string key, VSTypeScriptDefinitionItem item) + => UnderlyingObject.AddItem(key, item.UnderlyingObject); + } +} diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/VSTypeScriptWellKnownSymbolTypes.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/VSTypeScriptWellKnownSymbolTypes.cs new file mode 100644 index 0000000000000..aa9e05e30ec6f --- /dev/null +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/VSTypeScriptWellKnownSymbolTypes.cs @@ -0,0 +1,13 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Microsoft.CodeAnalysis.Editor.GoToDefinition; + +namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api +{ + internal static class VSTypeScriptWellKnownSymbolTypes + { + public const string Definition = WellKnownSymbolTypes.Definition; + } +} diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptFindUsagesService.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptFindUsagesService.cs index caa32af454098..473117cdf4edb 100644 --- a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptFindUsagesService.cs +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptFindUsagesService.cs @@ -3,8 +3,8 @@ // See the LICENSE file in the project root for more information. using System; -using System.Collections.Generic; using System.Composition; +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Editor.FindUsages; @@ -13,10 +13,10 @@ using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.Shared.Utilities; -namespace Microsoft.CodeAnalysis.Editor.ExternalAccess.VSTypeScript +namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript { [ExportLanguageService(typeof(IFindUsagesService), InternalLanguageNames.TypeScript), Shared] - internal class VSTypeScriptFindUsagesService : IFindUsagesService + internal sealed class VSTypeScriptFindUsagesService : IFindUsagesService { private readonly IVSTypeScriptFindUsagesService _underlyingService; @@ -28,22 +28,22 @@ public VSTypeScriptFindUsagesService(IVSTypeScriptFindUsagesService underlyingSe } public Task FindReferencesAsync(Document document, int position, IFindUsagesContext context, CancellationToken cancellationToken) - => _underlyingService.FindReferencesAsync(document, position, new VSTypeScriptFindUsagesContext(context), cancellationToken); + => _underlyingService.FindReferencesAsync(document, position, new Context(context), cancellationToken); public Task FindImplementationsAsync(Document document, int position, IFindUsagesContext context, CancellationToken cancellationToken) - => _underlyingService.FindImplementationsAsync(document, position, new VSTypeScriptFindUsagesContext(context), cancellationToken); + => _underlyingService.FindImplementationsAsync(document, position, new Context(context), cancellationToken); - private class VSTypeScriptFindUsagesContext : IVSTypeScriptFindUsagesContext + private sealed class Context : IVSTypeScriptFindUsagesContext { private readonly IFindUsagesContext _context; - private readonly Dictionary _definitionItemMap = new(); - public VSTypeScriptFindUsagesContext(IFindUsagesContext context) + public Context(IFindUsagesContext context) { _context = context; } - public IVSTypeScriptStreamingProgressTracker ProgressTracker => new VSTypeScriptStreamingProgressTracker(_context.ProgressTracker); + public IVSTypeScriptStreamingProgressTracker ProgressTracker + => new ProgressTracker(_context.ProgressTracker); public ValueTask ReportMessageAsync(string message, CancellationToken cancellationToken) => _context.ReportMessageAsync(message, cancellationToken); @@ -51,45 +51,18 @@ public ValueTask ReportMessageAsync(string message, CancellationToken cancellati public ValueTask SetSearchTitleAsync(string title, CancellationToken cancellationToken) => _context.SetSearchTitleAsync(title, cancellationToken); - private DefinitionItem GetOrCreateDefinitionItem(VSTypeScriptDefinitionItem item) - { - lock (_definitionItemMap) - { - if (!_definitionItemMap.TryGetValue(item, out var result)) - { - result = DefinitionItem.Create( - item.Tags, - item.DisplayParts, - item.SourceSpans, - item.NameDisplayParts, - item.Properties, - item.DisplayableProperties, - item.DisplayIfNoReferences); - _definitionItemMap.Add(item, result); - } - - return result; - } - } - public ValueTask OnDefinitionFoundAsync(VSTypeScriptDefinitionItem definition, CancellationToken cancellationToken) - { - var item = GetOrCreateDefinitionItem(definition); - return _context.OnDefinitionFoundAsync(item, cancellationToken); - } + => _context.OnDefinitionFoundAsync(definition.UnderlyingObject, cancellationToken); public ValueTask OnReferenceFoundAsync(VSTypeScriptSourceReferenceItem reference, CancellationToken cancellationToken) - { - var item = GetOrCreateDefinitionItem(reference.Definition); - return _context.OnReferenceFoundAsync(new SourceReferenceItem(item, reference.SourceSpan, reference.SymbolUsageInfo), cancellationToken); - } + => _context.OnReferenceFoundAsync(reference.UnderlyingObject, cancellationToken); } - private class VSTypeScriptStreamingProgressTracker : IVSTypeScriptStreamingProgressTracker + private sealed class ProgressTracker : IVSTypeScriptStreamingProgressTracker { private readonly IStreamingProgressTracker _progressTracker; - public VSTypeScriptStreamingProgressTracker(IStreamingProgressTracker progressTracker) + public ProgressTracker(IStreamingProgressTracker progressTracker) { _progressTracker = progressTracker; } diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptGoToDefinitionServiceFactory.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptGoToDefinitionServiceFactory.cs new file mode 100644 index 0000000000000..60d7bd601c264 --- /dev/null +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptGoToDefinitionServiceFactory.cs @@ -0,0 +1,49 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Generic; +using System.Composition; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis.Editor; +using Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api; +using Microsoft.CodeAnalysis.Host; +using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.CodeAnalysis.Navigation; + +namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript +{ + [ExportLanguageServiceFactory(typeof(IGoToDefinitionService), InternalLanguageNames.TypeScript), Shared] + internal sealed class VSTypeScriptGoToDefinitionServiceFactory : ILanguageServiceFactory + { + private readonly IVSTypeScriptGoToDefinitionServiceFactoryImplementation _impl; + + [ImportingConstructor] + [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] + public VSTypeScriptGoToDefinitionServiceFactory(IVSTypeScriptGoToDefinitionServiceFactoryImplementation impl) + => _impl = impl; + + public ILanguageService CreateLanguageService(HostLanguageServices languageServices) + => new ServiceWrapper(_impl.CreateLanguageService(languageServices)); + + private sealed class ServiceWrapper : IGoToDefinitionService + { + private readonly IVSTypeScriptGoToDefinitionService _service; + + public ServiceWrapper(IVSTypeScriptGoToDefinitionService service) + => _service = service; + + public async Task?> FindDefinitionsAsync(Document document, int position, CancellationToken cancellationToken) + { + var items = await _service.FindDefinitionsAsync(document, position, cancellationToken).ConfigureAwait(false); + return items.Select(item => new VSTypeScriptNavigableItem(item)); + } + + public bool TryGoToDefinition(Document document, int position, CancellationToken cancellationToken) + => _service.TryGoToDefinition(document, position, cancellationToken); + } + } +} diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptGoToSymbolService.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptGoToSymbolService.cs new file mode 100644 index 0000000000000..813dbe29c5dac --- /dev/null +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptGoToSymbolService.cs @@ -0,0 +1,26 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Composition; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis.Editor.GoToDefinition; +using Microsoft.CodeAnalysis.Host.Mef; + +namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api +{ + [ExportLanguageService(typeof(IGoToSymbolService), InternalLanguageNames.TypeScript), Shared] + internal sealed class VSTypeScriptGoToSymbolService : IGoToSymbolService + { + private readonly IVSTypeScriptGoToSymbolServiceImplementation _impl; + + [ImportingConstructor] + [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] + public VSTypeScriptGoToSymbolService(IVSTypeScriptGoToSymbolServiceImplementation impl) + => _impl = impl; + + public Task GetSymbolsAsync(GoToSymbolContext context) + => _impl.GetSymbolsAsync(new VSTypeScriptGoToSymbolContext(context)); + } +} diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptStreamingFindUsagesPresenter.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptStreamingFindUsagesPresenter.cs new file mode 100644 index 0000000000000..1be2aa3dd75ca --- /dev/null +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptStreamingFindUsagesPresenter.cs @@ -0,0 +1,41 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Composition; +using System.Threading; +using Microsoft.CodeAnalysis.Editor.Host; +using Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api; +using Microsoft.CodeAnalysis.Host.Mef; + +namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript +{ + [Export(typeof(IVSTypeScriptStreamingFindUsagesPresenter)), Shared] + internal sealed class VSTypeScriptStreamingFindUsagesPresenter : IVSTypeScriptStreamingFindUsagesPresenter + { + private readonly IStreamingFindUsagesPresenter _underlyingObject; + + [ImportingConstructor] + [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] + public VSTypeScriptStreamingFindUsagesPresenter(IStreamingFindUsagesPresenter underlyingObject) + => _underlyingObject = underlyingObject; + + public (VSTypeScriptFindUsagesContext context, CancellationToken cancellationToken) StartSearch( + string title, bool supportsReferences) + { + var (context, cancellationToken) = _underlyingObject.StartSearch(title, supportsReferences); + return (new(context), cancellationToken); + } + + public (VSTypeScriptFindUsagesContext context, CancellationToken cancellationToken) StartSearchWithCustomColumns( + string title, bool supportsReferences, bool includeContainingTypeAndMemberColumns, bool includeKindColumn) + { + var (context, cancellationToken) = _underlyingObject.StartSearchWithCustomColumns(title, supportsReferences, includeContainingTypeAndMemberColumns, includeKindColumn); + return (new(context), cancellationToken); + } + + public void ClearAll() + => _underlyingObject.ClearAll(); + } +} diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptStreamingProgressTracker.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptStreamingProgressTracker.cs new file mode 100644 index 0000000000000..788798ceb7d24 --- /dev/null +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptStreamingProgressTracker.cs @@ -0,0 +1,27 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Threading; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api; +using Microsoft.CodeAnalysis.Shared.Utilities; + +namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript +{ + internal sealed class VSTypeScriptStreamingProgressTracker : IVSTypeScriptStreamingProgressTracker + { + private readonly IStreamingProgressTracker _progressTracker; + + public VSTypeScriptStreamingProgressTracker(IStreamingProgressTracker progressTracker) + { + _progressTracker = progressTracker; + } + + public ValueTask AddItemsAsync(int count, CancellationToken cancellationToken) + => _progressTracker.AddItemsAsync(count, cancellationToken); + + public ValueTask ItemCompletedAsync(CancellationToken cancellationToken) + => _progressTracker.ItemCompletedAsync(cancellationToken); + } +} diff --git a/src/EditorFeatures/Core/FindUsages/IFindUsagesService.cs b/src/EditorFeatures/Core/FindUsages/IFindUsagesService.cs index e6c247e4bd999..8cb6b1e35f8b4 100644 --- a/src/EditorFeatures/Core/FindUsages/IFindUsagesService.cs +++ b/src/EditorFeatures/Core/FindUsages/IFindUsagesService.cs @@ -4,7 +4,6 @@ using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.FindUsages; using Microsoft.CodeAnalysis.Host; namespace Microsoft.CodeAnalysis.Editor.FindUsages diff --git a/src/EditorFeatures/Core/GoToDefinition/GoToSymbolContext.cs b/src/EditorFeatures/Core/GoToDefinition/GoToSymbolContext.cs index e5059aac8191a..7d34ebdd106b6 100644 --- a/src/EditorFeatures/Core/GoToDefinition/GoToSymbolContext.cs +++ b/src/EditorFeatures/Core/GoToDefinition/GoToSymbolContext.cs @@ -12,12 +12,17 @@ namespace Microsoft.CodeAnalysis.Editor.GoToDefinition { - internal class GoToSymbolContext + internal sealed class GoToSymbolContext { private readonly object _gate = new(); - private readonly MultiDictionary _items = new(); + public Document Document { get; } + public int Position { get; } + public CancellationToken CancellationToken { get; } + + public TextSpan Span { get; set; } + public GoToSymbolContext(Document document, int position, CancellationToken cancellationToken) { Document = document; @@ -25,12 +30,6 @@ public GoToSymbolContext(Document document, int position, CancellationToken canc CancellationToken = cancellationToken; } - public Document Document { get; } - public int Position { get; } - public CancellationToken CancellationToken { get; } - - public TextSpan Span { get; set; } - internal bool TryGetItems(string key, out IEnumerable items) { if (_items.ContainsKey(key)) diff --git a/src/EditorFeatures/Core/GoToDefinition/WellKnownSymbolTypes.cs b/src/EditorFeatures/Core/GoToDefinition/WellKnownSymbolTypes.cs index 3dbcc93bf35b3..5401c9e65f304 100644 --- a/src/EditorFeatures/Core/GoToDefinition/WellKnownSymbolTypes.cs +++ b/src/EditorFeatures/Core/GoToDefinition/WellKnownSymbolTypes.cs @@ -2,11 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - namespace Microsoft.CodeAnalysis.Editor.GoToDefinition { - internal class WellKnownSymbolTypes + internal static class WellKnownSymbolTypes { public const string Definition = nameof(Definition); } diff --git a/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptNavigateToSearchService.WrappedNavigableItem.cs b/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptNavigateToSearchService.WrappedNavigableItem.cs new file mode 100644 index 0000000000000..c40edb8043196 --- /dev/null +++ b/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptNavigateToSearchService.WrappedNavigableItem.cs @@ -0,0 +1,40 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.Immutable; +using Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api; +using Microsoft.CodeAnalysis.Navigation; +using Microsoft.CodeAnalysis.Text; + +namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript +{ + internal sealed class VSTypeScriptNavigableItem : INavigableItem + { + private readonly IVSTypeScriptNavigableItem _navigableItem; + + public VSTypeScriptNavigableItem(IVSTypeScriptNavigableItem navigableItem) + { + _navigableItem = navigableItem; + } + + public Glyph Glyph => _navigableItem.Glyph; + + public ImmutableArray DisplayTaggedParts => _navigableItem.DisplayTaggedParts; + + public bool DisplayFileLocation => _navigableItem.DisplayFileLocation; + + public bool IsImplicitlyDeclared => _navigableItem.IsImplicitlyDeclared; + + public Document Document => _navigableItem.Document; + + public TextSpan SourceSpan => _navigableItem.SourceSpan; + + public bool IsStale => false; + + public ImmutableArray ChildItems + => _navigableItem.ChildItems.IsDefault + ? default + : _navigableItem.ChildItems.SelectAsArray(i => (INavigableItem)new VSTypeScriptNavigableItem(i)); + } +} diff --git a/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptNavigateToSearchService.cs b/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptNavigateToSearchService.cs index ae9f87a777e0a..2d4cd2b097175 100644 --- a/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptNavigateToSearchService.cs +++ b/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptNavigateToSearchService.cs @@ -19,7 +19,7 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript { [ExportLanguageService(typeof(INavigateToSearchService), InternalLanguageNames.TypeScript), Shared] - internal class VSTypeScriptNavigateToSearchService : INavigateToSearchService + internal partial class VSTypeScriptNavigateToSearchService : INavigateToSearchService { private readonly IVSTypeScriptNavigateToSearchService? _searchService; @@ -132,36 +132,7 @@ public NavigateToMatchKind MatchKind public string Summary => _result.Summary; - public INavigableItem? NavigableItem => _result.NavigableItem == null ? null : new WrappedNavigableItem(_result.NavigableItem); - } - - private class WrappedNavigableItem : INavigableItem - { - private readonly IVSTypeScriptNavigableItem _navigableItem; - - public WrappedNavigableItem(IVSTypeScriptNavigableItem navigableItem) - { - _navigableItem = navigableItem; - } - - public Glyph Glyph => _navigableItem.Glyph; - - public ImmutableArray DisplayTaggedParts => _navigableItem.DisplayTaggedParts; - - public bool DisplayFileLocation => _navigableItem.DisplayFileLocation; - - public bool IsImplicitlyDeclared => _navigableItem.IsImplicitlyDeclared; - - public Document Document => _navigableItem.Document; - - public TextSpan SourceSpan => _navigableItem.SourceSpan; - - public bool IsStale => false; - - public ImmutableArray ChildItems - => _navigableItem.ChildItems.IsDefault - ? default - : _navigableItem.ChildItems.SelectAsArray(i => (INavigableItem)new WrappedNavigableItem(i)); + public INavigableItem? NavigableItem => _result.NavigableItem == null ? null : new VSTypeScriptNavigableItem(_result.NavigableItem); } } } diff --git a/src/Features/Core/Portable/FindUsages/DefinitionItem.DefaultDefinitionItem.cs b/src/Features/Core/Portable/FindUsages/DefinitionItem.DefaultDefinitionItem.cs index ec13d642ee034..d7a9f8346b96a 100644 --- a/src/Features/Core/Portable/FindUsages/DefinitionItem.DefaultDefinitionItem.cs +++ b/src/Features/Core/Portable/FindUsages/DefinitionItem.DefaultDefinitionItem.cs @@ -29,8 +29,8 @@ public DefaultDefinitionItem( ImmutableArray nameDisplayParts, ImmutableArray originationParts, ImmutableArray sourceSpans, - ImmutableDictionary properties, - ImmutableDictionary displayableProperties, + ImmutableDictionary? properties, + ImmutableDictionary? displayableProperties, bool displayIfNoReferences) : base(tags, displayParts, nameDisplayParts, originationParts, sourceSpans, properties, displayableProperties, displayIfNoReferences) diff --git a/src/Features/Core/Portable/FindUsages/DefinitionItem.cs b/src/Features/Core/Portable/FindUsages/DefinitionItem.cs index 06c21ede36a09..4240c70abcfa1 100644 --- a/src/Features/Core/Portable/FindUsages/DefinitionItem.cs +++ b/src/Features/Core/Portable/FindUsages/DefinitionItem.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System; using System.Collections.Immutable; using System.Linq; @@ -118,7 +116,7 @@ protected DefinitionItem( ImmutableArray nameDisplayParts, ImmutableArray originationParts, ImmutableArray sourceSpans, - ImmutableDictionary properties, + ImmutableDictionary? properties, bool displayIfNoReferences) : this( tags, @@ -138,8 +136,8 @@ protected DefinitionItem( ImmutableArray nameDisplayParts, ImmutableArray originationParts, ImmutableArray sourceSpans, - ImmutableDictionary properties, - ImmutableDictionary displayableProperties, + ImmutableDictionary? properties, + ImmutableDictionary? displayableProperties, bool displayIfNoReferences) { Tags = tags; @@ -207,7 +205,7 @@ public static DefinitionItem Create( ImmutableArray displayParts, ImmutableArray sourceSpans, ImmutableArray nameDisplayParts = default, - ImmutableDictionary properties = null, + ImmutableDictionary? properties = null, bool displayIfNoReferences = true) { return Create(tags, displayParts, sourceSpans, nameDisplayParts, properties, ImmutableDictionary.Empty, displayIfNoReferences); @@ -218,8 +216,8 @@ public static DefinitionItem Create( ImmutableArray displayParts, ImmutableArray sourceSpans, ImmutableArray nameDisplayParts = default, - ImmutableDictionary properties = null, - ImmutableDictionary displayableProperties = null, + ImmutableDictionary? properties = null, + ImmutableDictionary? displayableProperties = null, bool displayIfNoReferences = true) { if (sourceSpans.Length == 0) @@ -242,7 +240,7 @@ internal static DefinitionItem CreateMetadataDefinition( ImmutableArray nameDisplayParts, Solution solution, ISymbol symbol, - ImmutableDictionary properties = null, + ImmutableDictionary? properties = null, bool displayIfNoReferences = true) { properties ??= ImmutableDictionary.Empty; @@ -254,7 +252,7 @@ internal static DefinitionItem CreateMetadataDefinition( properties = properties.Add(MetadataSymbolKey, symbolKey) .Add(MetadataSymbolOriginatingProjectIdGuid, projectId.Id.ToString()) - .Add(MetadataSymbolOriginatingProjectIdDebugName, projectId.DebugName); + .Add(MetadataSymbolOriginatingProjectIdDebugName, projectId.DebugName ?? ""); var originationParts = GetOriginationParts(symbol); return new DefaultDefinitionItem( @@ -281,7 +279,7 @@ public static DefinitionItem CreateNonNavigableItem( ImmutableArray tags, ImmutableArray displayParts, ImmutableArray originationParts = default, - ImmutableDictionary properties = null, + ImmutableDictionary? properties = null, bool displayIfNoReferences = true) { properties ??= ImmutableDictionary.Empty; From 4b64bd79d3c438adf9ef948012556fe8ee68f502 Mon Sep 17 00:00:00 2001 From: tmat Date: Fri, 28 Jan 2022 11:48:12 -0800 Subject: [PATCH 2/6] Fix --- .../VSTypeScript/VSTypeScriptNavigateToSearchService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptNavigateToSearchService.cs b/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptNavigateToSearchService.cs index 2d4cd2b097175..ef5f448fe82c5 100644 --- a/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptNavigateToSearchService.cs +++ b/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptNavigateToSearchService.cs @@ -19,7 +19,7 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript { [ExportLanguageService(typeof(INavigateToSearchService), InternalLanguageNames.TypeScript), Shared] - internal partial class VSTypeScriptNavigateToSearchService : INavigateToSearchService + internal sealed class VSTypeScriptNavigateToSearchService : INavigateToSearchService { private readonly IVSTypeScriptNavigateToSearchService? _searchService; From 1ff97c4829fcc40550fa82ba0c47200ddc118fd4 Mon Sep 17 00:00:00 2001 From: tmat Date: Fri, 28 Jan 2022 11:56:48 -0800 Subject: [PATCH 3/6] Fix --- src/EditorFeatures/Core/FindUsages/IFindUsagesService.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/EditorFeatures/Core/FindUsages/IFindUsagesService.cs b/src/EditorFeatures/Core/FindUsages/IFindUsagesService.cs index 8cb6b1e35f8b4..0661ab5ba8cc5 100644 --- a/src/EditorFeatures/Core/FindUsages/IFindUsagesService.cs +++ b/src/EditorFeatures/Core/FindUsages/IFindUsagesService.cs @@ -5,6 +5,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Host; +using Microsoft.CodeAnalysis.FindUsages; namespace Microsoft.CodeAnalysis.Editor.FindUsages { From 802d666d8ed74f5217ca714a129392d2f51eca0b Mon Sep 17 00:00:00 2001 From: tmat Date: Fri, 28 Jan 2022 15:22:35 -0800 Subject: [PATCH 4/6] Feedback --- .../VSTypeScriptGoToDefinitionServiceFactory.cs | 2 +- .../VSTypeScript/VSTypeScriptGoToSymbolService.cs | 3 ++- .../Core/FindUsages/IFindUsagesService.cs | 2 +- .../Core/GoToDefinition/GoToSymbolContext.cs | 15 ++++++++------- ...tem.cs => VSTypeScriptNavigableItemWrapper.cs} | 6 +++--- .../VSTypeScriptNavigateToSearchService.cs | 2 +- 6 files changed, 16 insertions(+), 14 deletions(-) rename src/Features/Core/Portable/ExternalAccess/VSTypeScript/{VSTypeScriptNavigateToSearchService.WrappedNavigableItem.cs => VSTypeScriptNavigableItemWrapper.cs} (85%) diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptGoToDefinitionServiceFactory.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptGoToDefinitionServiceFactory.cs index 60d7bd601c264..4f9904cac0182 100644 --- a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptGoToDefinitionServiceFactory.cs +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptGoToDefinitionServiceFactory.cs @@ -39,7 +39,7 @@ public ServiceWrapper(IVSTypeScriptGoToDefinitionService service) public async Task?> FindDefinitionsAsync(Document document, int position, CancellationToken cancellationToken) { var items = await _service.FindDefinitionsAsync(document, position, cancellationToken).ConfigureAwait(false); - return items.Select(item => new VSTypeScriptNavigableItem(item)); + return items.Select(item => new VSTypeScriptNavigableItemWrapper(item)); } public bool TryGoToDefinition(Document document, int position, CancellationToken cancellationToken) diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptGoToSymbolService.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptGoToSymbolService.cs index 813dbe29c5dac..51eb2a888996a 100644 --- a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptGoToSymbolService.cs +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptGoToSymbolService.cs @@ -7,8 +7,9 @@ using System.Threading.Tasks; using Microsoft.CodeAnalysis.Editor.GoToDefinition; using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api; -namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api +namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript { [ExportLanguageService(typeof(IGoToSymbolService), InternalLanguageNames.TypeScript), Shared] internal sealed class VSTypeScriptGoToSymbolService : IGoToSymbolService diff --git a/src/EditorFeatures/Core/FindUsages/IFindUsagesService.cs b/src/EditorFeatures/Core/FindUsages/IFindUsagesService.cs index 0661ab5ba8cc5..e6c247e4bd999 100644 --- a/src/EditorFeatures/Core/FindUsages/IFindUsagesService.cs +++ b/src/EditorFeatures/Core/FindUsages/IFindUsagesService.cs @@ -4,8 +4,8 @@ using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.FindUsages; +using Microsoft.CodeAnalysis.Host; namespace Microsoft.CodeAnalysis.Editor.FindUsages { diff --git a/src/EditorFeatures/Core/GoToDefinition/GoToSymbolContext.cs b/src/EditorFeatures/Core/GoToDefinition/GoToSymbolContext.cs index 7d34ebdd106b6..e5059aac8191a 100644 --- a/src/EditorFeatures/Core/GoToDefinition/GoToSymbolContext.cs +++ b/src/EditorFeatures/Core/GoToDefinition/GoToSymbolContext.cs @@ -12,16 +12,11 @@ namespace Microsoft.CodeAnalysis.Editor.GoToDefinition { - internal sealed class GoToSymbolContext + internal class GoToSymbolContext { private readonly object _gate = new(); - private readonly MultiDictionary _items = new(); - public Document Document { get; } - public int Position { get; } - public CancellationToken CancellationToken { get; } - - public TextSpan Span { get; set; } + private readonly MultiDictionary _items = new(); public GoToSymbolContext(Document document, int position, CancellationToken cancellationToken) { @@ -30,6 +25,12 @@ public GoToSymbolContext(Document document, int position, CancellationToken canc CancellationToken = cancellationToken; } + public Document Document { get; } + public int Position { get; } + public CancellationToken CancellationToken { get; } + + public TextSpan Span { get; set; } + internal bool TryGetItems(string key, out IEnumerable items) { if (_items.ContainsKey(key)) diff --git a/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptNavigateToSearchService.WrappedNavigableItem.cs b/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptNavigableItemWrapper.cs similarity index 85% rename from src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptNavigateToSearchService.WrappedNavigableItem.cs rename to src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptNavigableItemWrapper.cs index c40edb8043196..17b596a41950b 100644 --- a/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptNavigateToSearchService.WrappedNavigableItem.cs +++ b/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptNavigableItemWrapper.cs @@ -9,11 +9,11 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript { - internal sealed class VSTypeScriptNavigableItem : INavigableItem + internal sealed class VSTypeScriptNavigableItemWrapper : INavigableItem { private readonly IVSTypeScriptNavigableItem _navigableItem; - public VSTypeScriptNavigableItem(IVSTypeScriptNavigableItem navigableItem) + public VSTypeScriptNavigableItemWrapper(IVSTypeScriptNavigableItem navigableItem) { _navigableItem = navigableItem; } @@ -35,6 +35,6 @@ public VSTypeScriptNavigableItem(IVSTypeScriptNavigableItem navigableItem) public ImmutableArray ChildItems => _navigableItem.ChildItems.IsDefault ? default - : _navigableItem.ChildItems.SelectAsArray(i => (INavigableItem)new VSTypeScriptNavigableItem(i)); + : _navigableItem.ChildItems.SelectAsArray(i => (INavigableItem)new VSTypeScriptNavigableItemWrapper(i)); } } diff --git a/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptNavigateToSearchService.cs b/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptNavigateToSearchService.cs index ef5f448fe82c5..96bc98042d78d 100644 --- a/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptNavigateToSearchService.cs +++ b/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptNavigateToSearchService.cs @@ -132,7 +132,7 @@ public NavigateToMatchKind MatchKind public string Summary => _result.Summary; - public INavigableItem? NavigableItem => _result.NavigableItem == null ? null : new VSTypeScriptNavigableItem(_result.NavigableItem); + public INavigableItem? NavigableItem => _result.NavigableItem == null ? null : new VSTypeScriptNavigableItemWrapper(_result.NavigableItem); } } } From db61efe1372a3147137222529c085a125290dece Mon Sep 17 00:00:00 2001 From: tmat Date: Mon, 31 Jan 2022 15:59:59 -0800 Subject: [PATCH 5/6] Feedback --- ...peScriptStreamingFindUsagesPresenterAccessor.cs} | 5 +---- ...peScriptStreamingFindUsagesPresenterAccessor.cs} | 13 +++---------- 2 files changed, 4 insertions(+), 14 deletions(-) rename src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/{IVSTypeScriptStreamingFindUsagesPresenter.cs => IVSTypeScriptStreamingFindUsagesPresenterAccessor.cs} (70%) rename src/EditorFeatures/Core/ExternalAccess/VSTypeScript/{VSTypeScriptStreamingFindUsagesPresenter.cs => VSTypeScriptStreamingFindUsagesPresenterAccessor.cs} (62%) diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptStreamingFindUsagesPresenter.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptStreamingFindUsagesPresenterAccessor.cs similarity index 70% rename from src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptStreamingFindUsagesPresenter.cs rename to src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptStreamingFindUsagesPresenterAccessor.cs index 4b5b45268a26f..18e5d44ffaec0 100644 --- a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptStreamingFindUsagesPresenter.cs +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptStreamingFindUsagesPresenterAccessor.cs @@ -6,14 +6,11 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api { - internal interface IVSTypeScriptStreamingFindUsagesPresenter + internal interface IVSTypeScriptStreamingFindUsagesPresenterAccessor { (VSTypeScriptFindUsagesContext context, CancellationToken cancellationToken) StartSearch( string title, bool supportsReferences); - (VSTypeScriptFindUsagesContext context, CancellationToken cancellationToken) StartSearchWithCustomColumns( - string title, bool supportsReferences, bool includeContainingTypeAndMemberColumns, bool includeKindColumn); - void ClearAll(); } } diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptStreamingFindUsagesPresenter.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptStreamingFindUsagesPresenterAccessor.cs similarity index 62% rename from src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptStreamingFindUsagesPresenter.cs rename to src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptStreamingFindUsagesPresenterAccessor.cs index 1be2aa3dd75ca..07cb65c0f3247 100644 --- a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptStreamingFindUsagesPresenter.cs +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptStreamingFindUsagesPresenterAccessor.cs @@ -11,14 +11,14 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript { - [Export(typeof(IVSTypeScriptStreamingFindUsagesPresenter)), Shared] - internal sealed class VSTypeScriptStreamingFindUsagesPresenter : IVSTypeScriptStreamingFindUsagesPresenter + [Export(typeof(IVSTypeScriptStreamingFindUsagesPresenterAccessor)), Shared] + internal sealed class VSTypeScriptStreamingFindUsagesPresenterAccessor : IVSTypeScriptStreamingFindUsagesPresenterAccessor { private readonly IStreamingFindUsagesPresenter _underlyingObject; [ImportingConstructor] [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public VSTypeScriptStreamingFindUsagesPresenter(IStreamingFindUsagesPresenter underlyingObject) + public VSTypeScriptStreamingFindUsagesPresenterAccessor(IStreamingFindUsagesPresenter underlyingObject) => _underlyingObject = underlyingObject; public (VSTypeScriptFindUsagesContext context, CancellationToken cancellationToken) StartSearch( @@ -28,13 +28,6 @@ public VSTypeScriptStreamingFindUsagesPresenter(IStreamingFindUsagesPresenter un return (new(context), cancellationToken); } - public (VSTypeScriptFindUsagesContext context, CancellationToken cancellationToken) StartSearchWithCustomColumns( - string title, bool supportsReferences, bool includeContainingTypeAndMemberColumns, bool includeKindColumn) - { - var (context, cancellationToken) = _underlyingObject.StartSearchWithCustomColumns(title, supportsReferences, includeContainingTypeAndMemberColumns, includeKindColumn); - return (new(context), cancellationToken); - } - public void ClearAll() => _underlyingObject.ClearAll(); } From edbe9bf52836b2af91c3499b6d8685f5967c6d0f Mon Sep 17 00:00:00 2001 From: tmat Date: Mon, 31 Jan 2022 17:11:18 -0800 Subject: [PATCH 6/6] Hide VSTypeScriptFindUsagesContext --- .../VSTypeScript/Api/IVSTypeScriptFindUsagesContext.cs | 2 ++ .../Api/IVSTypeScriptStreamingFindUsagesPresenterAccessor.cs | 2 +- .../VSTypeScript/{Api => }/VSTypeScriptFindUsagesContext.cs | 3 ++- .../VSTypeScript/VSTypeScriptFindUsagesService.cs | 4 ++++ .../VSTypeScriptStreamingFindUsagesPresenterAccessor.cs | 4 ++-- 5 files changed, 11 insertions(+), 4 deletions(-) rename src/EditorFeatures/Core/ExternalAccess/VSTypeScript/{Api => }/VSTypeScriptFindUsagesContext.cs (93%) diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptFindUsagesContext.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptFindUsagesContext.cs index 1230f31936fc4..1b49a61971ab1 100644 --- a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptFindUsagesContext.cs +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptFindUsagesContext.cs @@ -30,6 +30,8 @@ internal interface IVSTypeScriptFindUsagesContext ValueTask OnDefinitionFoundAsync(VSTypeScriptDefinitionItem definition, CancellationToken cancellationToken); ValueTask OnReferenceFoundAsync(VSTypeScriptSourceReferenceItem reference, CancellationToken cancellationToken); + + ValueTask OnCompletedAsync(CancellationToken cancellationToken); } internal interface IVSTypeScriptStreamingProgressTracker diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptStreamingFindUsagesPresenterAccessor.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptStreamingFindUsagesPresenterAccessor.cs index 18e5d44ffaec0..ab3b09da58289 100644 --- a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptStreamingFindUsagesPresenterAccessor.cs +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptStreamingFindUsagesPresenterAccessor.cs @@ -8,7 +8,7 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api { internal interface IVSTypeScriptStreamingFindUsagesPresenterAccessor { - (VSTypeScriptFindUsagesContext context, CancellationToken cancellationToken) StartSearch( + (IVSTypeScriptFindUsagesContext context, CancellationToken cancellationToken) StartSearch( string title, bool supportsReferences); void ClearAll(); diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/VSTypeScriptFindUsagesContext.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptFindUsagesContext.cs similarity index 93% rename from src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/VSTypeScriptFindUsagesContext.cs rename to src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptFindUsagesContext.cs index c8388c75ec7df..1da49573dac3c 100644 --- a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/VSTypeScriptFindUsagesContext.cs +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptFindUsagesContext.cs @@ -5,8 +5,9 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.FindUsages; +using Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api; -namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api +namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript { internal sealed class VSTypeScriptFindUsagesContext : IVSTypeScriptFindUsagesContext { diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptFindUsagesService.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptFindUsagesService.cs index 473117cdf4edb..12b090b4f3bb4 100644 --- a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptFindUsagesService.cs +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptFindUsagesService.cs @@ -12,6 +12,7 @@ using Microsoft.CodeAnalysis.FindUsages; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.Shared.Utilities; +using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript { @@ -56,6 +57,9 @@ public ValueTask OnDefinitionFoundAsync(VSTypeScriptDefinitionItem definition, C public ValueTask OnReferenceFoundAsync(VSTypeScriptSourceReferenceItem reference, CancellationToken cancellationToken) => _context.OnReferenceFoundAsync(reference.UnderlyingObject, cancellationToken); + + public ValueTask OnCompletedAsync(CancellationToken cancellationToken) + => ValueTaskFactory.CompletedTask; } private sealed class ProgressTracker : IVSTypeScriptStreamingProgressTracker diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptStreamingFindUsagesPresenterAccessor.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptStreamingFindUsagesPresenterAccessor.cs index 07cb65c0f3247..503284f5d06dc 100644 --- a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptStreamingFindUsagesPresenterAccessor.cs +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptStreamingFindUsagesPresenterAccessor.cs @@ -21,11 +21,11 @@ internal sealed class VSTypeScriptStreamingFindUsagesPresenterAccessor : IVSType public VSTypeScriptStreamingFindUsagesPresenterAccessor(IStreamingFindUsagesPresenter underlyingObject) => _underlyingObject = underlyingObject; - public (VSTypeScriptFindUsagesContext context, CancellationToken cancellationToken) StartSearch( + public (IVSTypeScriptFindUsagesContext context, CancellationToken cancellationToken) StartSearch( string title, bool supportsReferences) { var (context, cancellationToken) = _underlyingObject.StartSearch(title, supportsReferences); - return (new(context), cancellationToken); + return (new VSTypeScriptFindUsagesContext(context), cancellationToken); } public void ClearAll()