diff --git a/src/EditorFeatures/Core.Wpf/InlineRename/AbstractEditorInlineRenameService.SymbolRenameInfo.cs b/src/EditorFeatures/Core.Wpf/InlineRename/AbstractEditorInlineRenameService.SymbolRenameInfo.cs index 0f0cd8ebde0ed8eae829b0878d9db52f0550e44d..81152e74ff848c170e7f7fc51b9edfea29b92376 100644 --- a/src/EditorFeatures/Core.Wpf/InlineRename/AbstractEditorInlineRenameService.SymbolRenameInfo.cs +++ b/src/EditorFeatures/Core.Wpf/InlineRename/AbstractEditorInlineRenameService.SymbolRenameInfo.cs @@ -37,8 +37,6 @@ private partial class SymbolInlineRenameInfo : IInlineRenameInfoWithFileRename private Task _underlyingFindRenameLocationsTask; - private readonly string _triggerSpanText; - /// /// Whether or not we shortened the trigger span (say because we were renaming an attribute, /// and we didn't select the 'Attribute' portion of the name). @@ -49,7 +47,7 @@ private partial class SymbolInlineRenameInfo : IInlineRenameInfoWithFileRename public string LocalizedErrorMessage { get; } public TextSpan TriggerSpan { get; } public SymbolAndProjectId RenameSymbolAndProjectId { get; } - public bool HasOverloads { get; } + public bool HasOverloads { get; set; } public bool ForceRenameOverloads { get; } /// @@ -66,7 +64,6 @@ private partial class SymbolInlineRenameInfo : IInlineRenameInfoWithFileRename SymbolAndProjectId renameSymbolAndProjectId, bool forceRenameOverloads, ImmutableArray definitionLocations, - string triggerSpanText, CancellationToken cancellationToken) { this.CanRename = true; @@ -82,7 +79,6 @@ private partial class SymbolInlineRenameInfo : IInlineRenameInfoWithFileRename this.TriggerSpan = GetReferenceEditSpan(new InlineRenameLocation(document, triggerSpan), cancellationToken); this.DefinitionLocations = definitionLocations; - _triggerSpanText = triggerSpanText; } private bool CanRenameAttributePrefix(Document document, TextSpan triggerSpan, CancellationToken cancellationToken) @@ -99,7 +95,8 @@ private bool CanRenameAttributePrefix(Document document, TextSpan triggerSpan, C // we need to rename the entire attribute). var nameWithoutAttribute = GetWithoutAttributeSuffix(this.RenameSymbol.Name); - return _triggerSpanText.StartsWith(_triggerSpanText); // TODO: Always true? What was it supposed to do? + var triggerText = GetSpanText(document, triggerSpan, cancellationToken); + return triggerText.StartsWith(triggerText); // TODO: Always true? What was it supposed to do? } /// @@ -125,7 +122,8 @@ public TextSpan GetReferenceEditSpan(InlineRenameLocation location, Cancellation searchName = GetWithoutAttributeSuffix(this.RenameSymbol.Name); } - var index = _triggerSpanText.LastIndexOf(searchName, StringComparison.Ordinal); + var spanText = GetSpanText(location.Document, location.TextSpan, cancellationToken); + var index = spanText.LastIndexOf(searchName, StringComparison.Ordinal); if (index < 0) { @@ -140,13 +138,14 @@ public TextSpan GetReferenceEditSpan(InlineRenameLocation location, Cancellation public TextSpan? GetConflictEditSpan(InlineRenameLocation location, string replacementText, CancellationToken cancellationToken) { - var position = _triggerSpanText.LastIndexOf(replacementText, StringComparison.Ordinal); + var spanText = GetSpanText(location.Document, location.TextSpan, cancellationToken); + var position = spanText.LastIndexOf(replacementText, StringComparison.Ordinal); if (_isRenamingAttributePrefix) { // We're only renaming the attribute prefix part. We want to adjust the span of // the reference we've found to only update the prefix portion. - var index = _triggerSpanText.LastIndexOf(replacementText + AttributeSuffix, StringComparison.Ordinal); + var index = spanText.LastIndexOf(replacementText + AttributeSuffix, StringComparison.Ordinal); position = index >= 0 ? index : position; } @@ -164,6 +163,13 @@ private string GetWithoutAttributeSuffix(string value) private bool HasAttributeSuffix(string value) => value.TryGetWithoutAttributeSuffix(isCaseSensitive: _document.GetLanguageService().IsCaseSensitive, result: out var _); + private static string GetSpanText(Document document, TextSpan triggerSpan, CancellationToken cancellationToken) + { + var sourceText = document.GetTextSynchronously(cancellationToken); + var triggerText = sourceText.ToString(triggerSpan); + return triggerText; + } + internal bool IsRenamingAttributeTypeWithAttributeSuffix() { if (this.RenameSymbol.IsAttribute() || (this.RenameSymbol.Kind == SymbolKind.Alias && ((IAliasSymbol)this.RenameSymbol).Target.IsAttribute())) diff --git a/src/EditorFeatures/Core.Wpf/InlineRename/AbstractEditorInlineRenameService.cs b/src/EditorFeatures/Core.Wpf/InlineRename/AbstractEditorInlineRenameService.cs index b3b1c5fee0003e86e4655ede32afed9a164e8b5a..6ade21a40a0ba3aebcaab73081735c0141d12488 100644 --- a/src/EditorFeatures/Core.Wpf/InlineRename/AbstractEditorInlineRenameService.cs +++ b/src/EditorFeatures/Core.Wpf/InlineRename/AbstractEditorInlineRenameService.cs @@ -12,7 +12,6 @@ using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Rename; using Microsoft.CodeAnalysis.Shared.Extensions; -using Microsoft.CodeAnalysis.Text; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.Editor.Implementation.InlineRename @@ -192,18 +191,9 @@ public async Task GetRenameInfoAsync(Document document, int p } } - var triggerSpanText = await GetSpanTextAsync(document, triggerToken.Span, cancellationToken).ConfigureAwait(false); - return new SymbolInlineRenameInfo( refactorNotifyServices, document, triggerToken.Span, - symbolAndProjectId, forceRenameOverloads, documentSpans.ToImmutableAndFree(), triggerSpanText, cancellationToken); - - static async Task GetSpanTextAsync(Document document, TextSpan triggerSpan, CancellationToken cancellationToken) - { - var sourceText = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); - var triggerText = sourceText.ToString(triggerSpan); - return triggerText; - } + symbolAndProjectId, forceRenameOverloads, documentSpans.ToImmutableAndFree(), cancellationToken); } private async Task GetTriggerTokenAsync(Document document, int position, CancellationToken cancellationToken)