提交 d17c4102 编写于 作者: D David Poeschl

Merge pull request #773 from dpoeschl/RenameTrackingTriggerDiagnosticDescriptor

Use TriggerDiagnosticDescriptor in RenameTracking
......@@ -1600,15 +1600,6 @@ internal class EditorFeaturesResources {
}
}
/// <summary>
/// Looks up a localized string similar to Rename Tracking.
/// </summary>
internal static string RenameTracking {
get {
return ResourceManager.GetString("RenameTracking", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Renaming anonymous type members is not yet supported..
/// </summary>
......@@ -1843,15 +1834,6 @@ internal class EditorFeaturesResources {
}
}
/// <summary>
/// Looks up a localized string similar to with preview....
/// </summary>
internal static string WithPreview {
get {
return ResourceManager.GetString("WithPreview", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to XML End Tag Completion.
/// </summary>
......
......@@ -342,9 +342,6 @@
<data name="DocumentIsNotCurrentlyBeingTracked" xml:space="preserve">
<value>document is not currently being tracked</value>
</data>
<data name="RenameTracking" xml:space="preserve">
<value>Rename Tracking</value>
</data>
<data name="ComputingRenameInformation" xml:space="preserve">
<value>Computing Rename information...</value>
</data>
......@@ -624,9 +621,6 @@
<data name="RenameToWithPreview" xml:space="preserve">
<value>Rename '{0}' to '{1}' with preview...</value>
</data>
<data name="WithPreview" xml:space="preserve">
<value> with preview...</value>
</data>
<data name="PreviewChanges" xml:space="preserve">
<value>Preview Changes</value>
</data>
......
......@@ -10,20 +10,12 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.RenameTracking
internal sealed class RenameTrackingDiagnosticAnalyzer : DiagnosticAnalyzer, IBuiltInAnalyzer
{
public const string DiagnosticId = "RenameTracking";
private static LocalizableString s_localizableTitle = new LocalizableResourceString(nameof(EditorFeaturesResources.RenameTracking), EditorFeaturesResources.ResourceManager, typeof(EditorFeaturesResources));
private static LocalizableString s_localizableMessage = new LocalizableResourceString(nameof(EditorFeaturesResources.RenameTo), EditorFeaturesResources.ResourceManager, typeof(EditorFeaturesResources));
public static DiagnosticDescriptor DiagnosticDescriptor = new TriggerDiagnosticDescriptor(
DiagnosticId,
customTags: DiagnosticCustomTags.Microsoft.Append(WellKnownDiagnosticTags.NotConfigurable));
// TODO: Ideally we'd use a TriggerDiagnosticDescriptor here. However, this analyzer uses the message to communicate
// with it's fixer about what has changed. This analysis is not trivial to do for the fixer because of the temporal nature
// of this diagnostic. We should consider adding a field on diagnostic that is for extra data. If we have that we can
// turn this into a trigger diagnostic. For now, this just has the "NotConfigurable" tag to not show in the ruleset editor.
public static DiagnosticDescriptor DiagnosticDescriptor = new DiagnosticDescriptor(DiagnosticId,
s_localizableTitle,
s_localizableMessage,
"",
DiagnosticSeverity.Hidden,
isEnabledByDefault: true,
customTags: DiagnosticCustomTags.Microsoft.Append(WellKnownDiagnosticTags.NotConfigurable));
internal const string RenameFromPropertyKey = "RenameFrom";
internal const string RenameToPropertyKey = "RenameTo";
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
{
......
......@@ -15,6 +15,7 @@
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.Text;
using Roslyn.Utilities;
using System.Collections.Immutable;
namespace Microsoft.CodeAnalysis.Editor.Implementation.RenameTracking
{
......@@ -251,10 +252,16 @@ internal async Task<IEnumerable<Diagnostic>> GetDiagnostic(SyntaxTree tree, Diag
{
SnapshotSpan snapshotSpan = trackingSession.TrackingSpan.GetSpan(Buffer.CurrentSnapshot);
var textSpan = snapshotSpan.Span.ToTextSpan();
var builder = ImmutableDictionary.CreateBuilder<string, string>();
builder.Add(RenameTrackingDiagnosticAnalyzer.RenameFromPropertyKey, trackingSession.OriginalName);
builder.Add(RenameTrackingDiagnosticAnalyzer.RenameToPropertyKey, snapshotSpan.GetText());
var properties = builder.ToImmutable();
var diagnostic = Diagnostic.Create(diagnosticDescriptor,
tree.GetLocation(textSpan),
trackingSession.OriginalName,
snapshotSpan.GetText());
properties);
return SpecializedCollections.SingletonEnumerable(diagnostic);
}
......
......@@ -137,12 +137,12 @@ internal static async Task<IEnumerable<Diagnostic>> GetDiagnosticsAsync(SyntaxTr
bool showPreview)
{
// This can run on a background thread.
string message = diagnostic.GetMessage();
if (showPreview)
{
message += EditorFeaturesResources.WithPreview;
}
var renameToResourceString = showPreview ? EditorFeaturesResources.RenameToWithPreview : EditorFeaturesResources.RenameTo;
var message = string.Format(
renameToResourceString,
diagnostic.Properties[RenameTrackingDiagnosticAnalyzer.RenameFromPropertyKey],
diagnostic.Properties[RenameTrackingDiagnosticAnalyzer.RenameToPropertyKey]);
return new RenameTrackingCodeAction(document, message, refactorNotifyServices, undoHistoryRegistry, showPreview);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册