提交 891b1805 编写于 作者: A Allison Chou

Get text synchronously instead

上级 712f475b
......@@ -37,8 +37,6 @@ private partial class SymbolInlineRenameInfo : IInlineRenameInfoWithFileRename
private Task<RenameLocations> _underlyingFindRenameLocationsTask;
private readonly string _triggerSpanText;
/// <summary>
/// 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; }
/// <summary>
......@@ -66,7 +64,6 @@ private partial class SymbolInlineRenameInfo : IInlineRenameInfoWithFileRename
SymbolAndProjectId renameSymbolAndProjectId,
bool forceRenameOverloads,
ImmutableArray<DocumentSpan> 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?
}
/// <summary>
......@@ -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<ISyntaxFactsService>().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()))
......
......@@ -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<IInlineRenameInfo> 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<string> 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<SyntaxToken> GetTriggerTokenAsync(Document document, int position, CancellationToken cancellationToken)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册