Skip to content

Commit

Permalink
Remove OptionSet and Workspace from TypeScript Inline Rename interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat committed Dec 19, 2021
1 parent 3c59022 commit 8bd26b5
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#nullable disable

using System;
using System.Threading;
using System.Threading.Tasks;

Expand All @@ -12,8 +13,17 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api
/// <summary>
/// Language service that allows a language to participate in the editor's inline rename feature.
/// </summary>
[Obsolete]
internal interface IVSTypeScriptEditorInlineRenameService
{
Task<IVSTypeScriptInlineRenameInfo> GetRenameInfoAsync(Document document, int position, CancellationToken cancellationToken);
}

/// <summary>
/// Language service that allows a language to participate in the editor's inline rename feature.
/// </summary>
internal abstract class VSTypeScriptEditorInlineRenameServiceImplementation
{
public abstract Task<VSTypeScriptInlineRenameInfo> GetRenameInfoAsync(Document document, int position, CancellationToken cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#nullable disable

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading;
Expand All @@ -13,6 +14,7 @@

namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api
{
[Obsolete]
internal interface IVSTypeScriptInlineRenameInfo
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@

#nullable disable

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor;
using Microsoft.CodeAnalysis.Options;

namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api
{
[Obsolete]
internal interface IVSTypeScriptInlineRenameLocationSet
{
/// <summary>
Expand All @@ -28,4 +32,28 @@ internal interface IVSTypeScriptInlineRenameLocationSet
/// </summary>
Task<IVSTypeScriptInlineRenameReplacementInfo> GetReplacementsAsync(string replacementText, OptionSet optionSet, CancellationToken cancellationToken);
}

internal abstract class VSTypeScriptInlineRenameLocationSet : IInlineRenameLocationSet
{
/// <summary>
/// The set of locations that need to be updated with the replacement text that the user
/// has entered in the inline rename session. These are the locations are all relative
/// to the solution when the inline rename session began.
/// </summary>
public abstract IList<VSTypeScriptInlineRenameLocationWrapper> Locations { get; }

IList<InlineRenameLocation> IInlineRenameLocationSet.Locations
=> Locations?.Select(x => new InlineRenameLocation(x.Document, x.TextSpan)).ToList();

/// <summary>
/// Returns the set of replacements and their possible resolutions if the user enters the
/// provided replacement text and options. Replacements are keyed by their document id
/// and TextSpan in the original solution, and specify their new span and possible conflict
/// resolution.
/// </summary>
public abstract Task<VSTypeScriptInlineRenameReplacementInfo> GetReplacementsAsync(string replacementText, CancellationToken cancellationToken);

async Task<IInlineRenameReplacementInfo> IInlineRenameLocationSet.GetReplacementsAsync(string replacementText, OptionSet optionSet, CancellationToken cancellationToken)
=> await GetReplacementsAsync(replacementText, cancellationToken).ConfigureAwait(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

#nullable disable

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis.Editor;

namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api

{
[Obsolete]
internal interface IVSTypeScriptInlineRenameReplacementInfo
{
/// <summary>
Expand All @@ -31,4 +34,30 @@ internal interface IVSTypeScriptInlineRenameReplacementInfo
/// </summary>
IEnumerable<VSTypeScriptInlineRenameReplacementWrapper> GetReplacements(DocumentId documentId);
}

internal abstract class VSTypeScriptInlineRenameReplacementInfo : IInlineRenameReplacementInfo
{
/// <summary>
/// The solution obtained after resolving all conflicts.
/// </summary>
public abstract Solution NewSolution { get; }

/// <summary>
/// Whether or not the replacement text entered by the user is valid.
/// </summary>
public abstract bool ReplacementTextValid { get; }

/// <summary>
/// The documents that need to be updated.
/// </summary>
public abstract IEnumerable<DocumentId> DocumentIds { get; }

/// <summary>
/// Returns all the replacements that need to be performed for the specified document.
/// </summary>
public abstract IEnumerable<VSTypeScriptInlineRenameReplacementWrapper> GetReplacements(DocumentId documentId);

IEnumerable<InlineRenameReplacement> IInlineRenameReplacementInfo.GetReplacements(DocumentId documentId)
=> GetReplacements(documentId).Select(r => r.UnderlyingObject);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,77 +4,54 @@

#nullable disable

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Rename;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api
{
internal sealed class VSTypeScriptInlineRenameInfo : IInlineRenameInfo
internal abstract class VSTypeScriptInlineRenameInfo : IInlineRenameInfo
{
private readonly IVSTypeScriptInlineRenameInfo _info;

public VSTypeScriptInlineRenameInfo(IVSTypeScriptInlineRenameInfo info)
{
Contract.ThrowIfNull(info);
_info = info;
}

public bool CanRename => _info.CanRename;

public string LocalizedErrorMessage => _info.LocalizedErrorMessage;

public TextSpan TriggerSpan => _info.TriggerSpan;

public bool HasOverloads => _info.HasOverloads;

public bool ForceRenameOverloads => _info.ForceRenameOverloads;

public string DisplayName => _info.DisplayName;

public string FullDisplayName => _info.FullDisplayName;

public Glyph Glyph => VSTypeScriptGlyphHelpers.ConvertTo(_info.Glyph);

public ImmutableArray<DocumentSpan> DefinitionLocations => _info.DefinitionLocations;

public async Task<IInlineRenameLocationSet> FindRenameLocationsAsync(OptionSet optionSet, CancellationToken cancellationToken)
{
var set = await _info.FindRenameLocationsAsync(optionSet, cancellationToken).ConfigureAwait(false);
if (set != null)
{
return new VSTypeScriptInlineRenameLocationSet(set);
}
else
{
return null;
}
}

public TextSpan? GetConflictEditSpan(InlineRenameLocation location, string triggerText, string replacementText, CancellationToken cancellationToken)
{
return _info.GetConflictEditSpan(new VSTypeScriptInlineRenameLocationWrapper(
public abstract bool CanRename { get; }
public abstract string DisplayName { get; }
public abstract string FullDisplayName { get; }
public abstract VSTypeScriptGlyph Glyph { get; }
public abstract bool HasOverloads { get; }
public abstract bool ForceRenameOverloads { get; }
public abstract string LocalizedErrorMessage { get; }
public abstract TextSpan TriggerSpan { get; }
public abstract ImmutableArray<DocumentSpan> DefinitionLocations { get; }
public abstract Task<VSTypeScriptInlineRenameLocationSet> FindRenameLocationsAsync(bool renameInStrings, bool renameInComments, CancellationToken cancellationToken);
public abstract TextSpan? GetConflictEditSpan(VSTypeScriptInlineRenameLocationWrapper location, string replacementText, CancellationToken cancellationToken);
public abstract string GetFinalSymbolName(string replacementText);
public abstract TextSpan GetReferenceEditSpan(VSTypeScriptInlineRenameLocationWrapper location, CancellationToken cancellationToken);

Glyph IInlineRenameInfo.Glyph => VSTypeScriptGlyphHelpers.ConvertTo(Glyph);

async Task<IInlineRenameLocationSet> IInlineRenameInfo.FindRenameLocationsAsync(OptionSet optionSet, CancellationToken cancellationToken)
=> await FindRenameLocationsAsync(
optionSet.GetOption(RenameOptions.RenameInStrings),
optionSet.GetOption(RenameOptions.RenameInComments),
cancellationToken).ConfigureAwait(false);

TextSpan? IInlineRenameInfo.GetConflictEditSpan(InlineRenameLocation location, string triggerText, string replacementText, CancellationToken cancellationToken)
=> GetConflictEditSpan(new VSTypeScriptInlineRenameLocationWrapper(
new InlineRenameLocation(location.Document, location.TextSpan)), replacementText, cancellationToken);
}

public string GetFinalSymbolName(string replacementText)
=> _info.GetFinalSymbolName(replacementText);

public TextSpan GetReferenceEditSpan(InlineRenameLocation location, string triggerText, CancellationToken cancellationToken)
{
return _info.GetReferenceEditSpan(new VSTypeScriptInlineRenameLocationWrapper(
TextSpan IInlineRenameInfo.GetReferenceEditSpan(InlineRenameLocation location, string triggerText, CancellationToken cancellationToken)
=> GetReferenceEditSpan(new VSTypeScriptInlineRenameLocationWrapper(
new InlineRenameLocation(location.Document, location.TextSpan)), cancellationToken);
}

public bool TryOnAfterGlobalSymbolRenamed(Workspace workspace, IEnumerable<DocumentId> changedDocumentIDs, string replacementText)
=> _info.TryOnAfterGlobalSymbolRenamed(workspace, changedDocumentIDs, replacementText);
bool IInlineRenameInfo.TryOnAfterGlobalSymbolRenamed(Workspace workspace, IEnumerable<DocumentId> changedDocumentIDs, string replacementText)
=> true;

public bool TryOnBeforeGlobalSymbolRenamed(Workspace workspace, IEnumerable<DocumentId> changedDocumentIDs, string replacementText)
=> _info.TryOnBeforeGlobalSymbolRenamed(workspace, changedDocumentIDs, replacementText);
bool IInlineRenameInfo.TryOnBeforeGlobalSymbolRenamed(Workspace workspace, IEnumerable<DocumentId> changedDocumentIDs, string replacementText)
=> true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api
{
internal readonly struct VSTypeScriptInlineRenameReplacementWrapper
{
private readonly InlineRenameReplacement _underlyingObject;
internal readonly InlineRenameReplacement UnderlyingObject;

public VSTypeScriptInlineRenameReplacementWrapper(InlineRenameReplacement underlyingObject)
=> _underlyingObject = underlyingObject;
=> UnderlyingObject = underlyingObject;

public VSTypeScriptInlineRenameReplacementKind Kind => VSTypeScriptInlineRenameReplacementKindHelpers.ConvertFrom(_underlyingObject.Kind);
public TextSpan OriginalSpan => _underlyingObject.OriginalSpan;
public TextSpan NewSpan => _underlyingObject.NewSpan;
public VSTypeScriptInlineRenameReplacementKind Kind => VSTypeScriptInlineRenameReplacementKindHelpers.ConvertFrom(UnderlyingObject.Kind);
public TextSpan OriginalSpan => UnderlyingObject.OriginalSpan;
public TextSpan NewSpan => UnderlyingObject.NewSpan;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,37 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript
[ExportLanguageService(typeof(IEditorInlineRenameService), InternalLanguageNames.TypeScript)]
internal sealed class VSTypeScriptEditorInlineRenameService : IEditorInlineRenameService
{
private readonly Lazy<IVSTypeScriptEditorInlineRenameService> _service;
[Obsolete]
private readonly Lazy<IVSTypeScriptEditorInlineRenameService> _legacyService;

private readonly Lazy<VSTypeScriptEditorInlineRenameServiceImplementation> _service;

[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public VSTypeScriptEditorInlineRenameService(Lazy<IVSTypeScriptEditorInlineRenameService> service)
public VSTypeScriptEditorInlineRenameService(
[Import(AllowDefault = true)] Lazy<IVSTypeScriptEditorInlineRenameService> legacyService,
[Import(AllowDefault = true)] Lazy<VSTypeScriptEditorInlineRenameServiceImplementation> service)
{
Contract.ThrowIfNull(service);
_service = service;
_legacyService = legacyService;
}

public async Task<IInlineRenameInfo> GetRenameInfoAsync(Document document, int position, CancellationToken cancellationToken)
{
var info = await _service.Value.GetRenameInfoAsync(document, position, cancellationToken).ConfigureAwait(false);
if (info != null)
#pragma warning disable CS0612 // Type or member is obsolete
if (_legacyService != null)
{
return new VSTypeScriptInlineRenameInfo(info);
var info = await _legacyService.Value.GetRenameInfoAsync(document, position, cancellationToken).ConfigureAwait(false);
return (info is null) ? null : new VSTypeScriptInlineRenameInfoLegacyWrapper(info);
}
else
#pragma warning restore

if (_service != null)
{
return null;
return await _service.Value.GetRenameInfoAsync(document, position, cancellationToken).ConfigureAwait(false);
}

return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// 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.

#nullable disable

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor;
using Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript
{
[Obsolete]
internal sealed class VSTypeScriptInlineRenameInfoLegacyWrapper : IInlineRenameInfo
{
private readonly IVSTypeScriptInlineRenameInfo _info;

public VSTypeScriptInlineRenameInfoLegacyWrapper(IVSTypeScriptInlineRenameInfo info)
{
Contract.ThrowIfNull(info);
_info = info;
}

public bool CanRename => _info.CanRename;

public string LocalizedErrorMessage => _info.LocalizedErrorMessage;

public TextSpan TriggerSpan => _info.TriggerSpan;

public bool HasOverloads => _info.HasOverloads;

public bool ForceRenameOverloads => _info.ForceRenameOverloads;

public string DisplayName => _info.DisplayName;

public string FullDisplayName => _info.FullDisplayName;

public Glyph Glyph => VSTypeScriptGlyphHelpers.ConvertTo(_info.Glyph);

public ImmutableArray<DocumentSpan> DefinitionLocations => _info.DefinitionLocations;

public async Task<IInlineRenameLocationSet> FindRenameLocationsAsync(OptionSet optionSet, CancellationToken cancellationToken)
{
var set = await _info.FindRenameLocationsAsync(optionSet, cancellationToken).ConfigureAwait(false);
if (set != null)
{
return new VSTypeScriptInlineRenameLocationSetLegacyWrapper(set);
}
else
{
return null;
}
}

public TextSpan? GetConflictEditSpan(InlineRenameLocation location, string triggerText, string replacementText, CancellationToken cancellationToken)
{
return _info.GetConflictEditSpan(new VSTypeScriptInlineRenameLocationWrapper(
new InlineRenameLocation(location.Document, location.TextSpan)), replacementText, cancellationToken);
}

public string GetFinalSymbolName(string replacementText)
=> _info.GetFinalSymbolName(replacementText);

public TextSpan GetReferenceEditSpan(InlineRenameLocation location, string triggerText, CancellationToken cancellationToken)
{
return _info.GetReferenceEditSpan(new VSTypeScriptInlineRenameLocationWrapper(
new InlineRenameLocation(location.Document, location.TextSpan)), cancellationToken);
}

public bool TryOnAfterGlobalSymbolRenamed(Workspace workspace, IEnumerable<DocumentId> changedDocumentIDs, string replacementText)
=> _info.TryOnAfterGlobalSymbolRenamed(workspace, changedDocumentIDs, replacementText);

public bool TryOnBeforeGlobalSymbolRenamed(Workspace workspace, IEnumerable<DocumentId> changedDocumentIDs, string replacementText)
=> _info.TryOnBeforeGlobalSymbolRenamed(workspace, changedDocumentIDs, replacementText);
}
}
Loading

0 comments on commit 8bd26b5

Please sign in to comment.