Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add external access API for find usages #59144

Merged
merged 6 commits into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -28,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
Expand All @@ -36,8 +40,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<string> tags,
ImmutableArray<TaggedText> displayParts,
ImmutableArray<VSTypeScriptDocumentSpan> sourceSpans,
ImmutableArray<TaggedText> nameDisplayParts = default,
bool displayIfNoReferences = true)
{
return new(DefinitionItem.Create(
tags, displayParts, sourceSpans.SelectAsArray(span => span.ToDocumentSpan()), nameDisplayParts,
properties: null, displayableProperties: ImmutableDictionary<string, string>.Empty, displayIfNoReferences: displayIfNoReferences));
}

public static VSTypeScriptDefinitionItem Create(VSTypeScriptDefinitionItemBase item)
=> new(item);

[Obsolete]
public VSTypeScriptDefinitionItem(
ImmutableArray<string> tags,
ImmutableArray<TaggedText> displayParts,
Expand All @@ -47,38 +72,77 @@ public VSTypeScriptDefinitionItem(
ImmutableDictionary<string, string>? 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<TaggedText>.Empty, sourceSpans, properties, displayableProperties, displayIfNoReferences);
}

public ImmutableArray<string> Tags { get; }
public ImmutableArray<TaggedText> DisplayParts { get; }
public ImmutableArray<DocumentSpan> SourceSpans { get; }
public ImmutableArray<TaggedText> NameDisplayParts { get; }
public ImmutableDictionary<string, string>? Properties { get; }
public ImmutableDictionary<string, string>? DisplayableProperties { get; }
public bool DisplayIfNoReferences { get; }
public ImmutableArray<string> Tags => UnderlyingObject.Tags;
public ImmutableArray<TaggedText> DisplayParts => UnderlyingObject.DisplayParts;

[Obsolete]
public ImmutableArray<DocumentSpan> SourceSpans => UnderlyingObject.SourceSpans;

public ImmutableArray<VSTypeScriptDocumentSpan> GetSourceSpans()
=> UnderlyingObject.SourceSpans.SelectAsArray(span => new VSTypeScriptDocumentSpan(span));

public Task<bool> CanNavigateToAsync(Workspace workspace, CancellationToken cancellationToken)
=> UnderlyingObject.CanNavigateToAsync(workspace, cancellationToken);

public Task<bool> 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
}
}
Original file line number Diff line number Diff line change
@@ -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<IEnumerable<IVSTypeScriptNavigableItem>?> FindDefinitionsAsync(Document document, int position, CancellationToken cancellationToken);
bool TryGoToDefinition(Document document, int position, CancellationToken cancellationToken);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;

namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api
{
internal interface IVSTypeScriptStreamingFindUsagesPresenterAccessor
{
(IVSTypeScriptFindUsagesContext context, CancellationToken cancellationToken) StartSearch(
string title, bool supportsReferences);

void ClearAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 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;
using Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api;

namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript
{
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);
}
}
Loading