Skip to content

Commit

Permalink
Better titles for Find References windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mhutch committed Apr 17, 2024
1 parent d7d36a6 commit 2c199f6
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,31 @@ public bool FindReferences (ITextBuffer buffer, MSBuildResolveResult resolveResu
async Task FindReferencesAsync (ITextBuffer buffer, MSBuildResolveResult reference, ILogger logger)
{
var referenceName = reference.GetReferenceDisplayName ();

string searchTitle = reference.ReferenceKind switch {
MSBuildReferenceKind.Item => $"Item '{referenceName}' references",
MSBuildReferenceKind.Property => $"Property '{referenceName}' references",
MSBuildReferenceKind.Metadata => $"Metadata '{referenceName}' references",
MSBuildReferenceKind.Task => $"Task '{referenceName}' references",
MSBuildReferenceKind.TaskParameter => $"Task parameter '{referenceName}' references",
MSBuildReferenceKind.Keyword => $"Keyword '{referenceName}' references",
MSBuildReferenceKind.Target => $"Target '{referenceName}' references",
MSBuildReferenceKind.KnownValue => $"Value '{referenceName}' references",
MSBuildReferenceKind.NuGetID => $"NuGet package '{referenceName}' references",
MSBuildReferenceKind.TargetFramework => $"Target framework '{referenceName}' references",
MSBuildReferenceKind.ItemFunction => $"Item function '{referenceName}' references",
MSBuildReferenceKind.PropertyFunction => $"Property function '{referenceName}' references",
MSBuildReferenceKind.StaticPropertyFunction => $"Static '{referenceName}' references",
MSBuildReferenceKind.ClassName => $"Class '{referenceName}' references",
MSBuildReferenceKind.Enum => $"Enum '{referenceName}' references",
MSBuildReferenceKind.ConditionFunction => $"Condition function '{referenceName}' references",
MSBuildReferenceKind.FileOrFolder => $"Path '{referenceName}' references",
MSBuildReferenceKind.TargetFrameworkIdentifier => $"TargetFrameworkIdentifier '{referenceName}' references",
MSBuildReferenceKind.TargetFrameworkVersion => $"TargetFrameworkVersion '{referenceName}' references",
MSBuildReferenceKind.TargetFrameworkProfile => $"TargetFrameworkProfile '{referenceName}' references",
_ => logger.LogUnhandledCaseAndReturnDefaultValue ($"'{referenceName}' references", reference.ReferenceKind)
};

var searchCtx = Presenter.StartSearch ($"'{referenceName}' references", referenceName, true);

try {
Expand All @@ -227,7 +252,7 @@ async Task FindReferencesAsync (ITextBuffer buffer, MSBuildResolveResult referen

async Task FindTargetDefinitions (string targetName, ITextBuffer buffer)
{
var searchCtx = Presenter.StartSearch ($"'{targetName}' definitions", targetName, true);
var searchCtx = Presenter.StartSearch ($"Target '{targetName}' definitions", targetName, true);

try {
await FindReferences (searchCtx, (doc, text, logger, reporter) => new MSBuildTargetDefinitionCollector (doc, text, logger, targetName, reporter), buffer);
Expand Down
28 changes: 28 additions & 0 deletions MonoDevelop.MSBuild/Util/MSBuildLoggerExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#nullable enable

using System.Runtime.CompilerServices;

using Microsoft.Extensions.Logging;

namespace MonoDevelop.MSBuild;

// consider moving some of these down to the XML layer?
static partial class MSBuildLoggerExtensions
{
/// <summary>
/// Helper for switch expressions to log a message about missing cases when they can gracefully return a default value instead of throwing
/// </summary>
/// <remarks>This must be kept internal so that analyzers and fixes don't use it, as it does not sanitize the callsite for PII.</remarks>
internal static TReturn LogUnhandledCaseAndReturnDefaultValue<TReturn,TSwitchValue> (this ILogger logger, TReturn valueToReturn, TSwitchValue missingValue, [CallerMemberName] string methodName = null, [CallerFilePath] string filePath = null, [CallerLineNumber] int lineNumber = 0)
{
LogUnhandledCase(logger, missingValue, methodName, filePath, lineNumber);
return valueToReturn;
}

/// <remarks>This must be kept internal so that analyzers and fixes don't use it, as it does not sanitize the callsite for PII.</remarks>
[LoggerMessage (EventId = 0, Level = LogLevel.Warning, Message = "Unhandled case '{missingValue}' in method {methodName} at {filePath}:{lineNumber}'")]
static partial void LogUnhandledCase (ILogger logger, object missingValue, string methodName, string filePath, int lineNumber);
}

0 comments on commit 2c199f6

Please sign in to comment.