提交 de8f461e 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #14705 from CyrusNajmabadi/navEvents

Sort same-named NavTo items to better ensure the topmost results are more in line with what the user wants.
......@@ -2,6 +2,7 @@
using System;
using System.Diagnostics;
using System.IO;
using Microsoft.CodeAnalysis.FindSymbols;
using Microsoft.CodeAnalysis.Navigation;
using Microsoft.CodeAnalysis.Shared.Extensions;
......@@ -37,7 +38,7 @@ private class SearchResult : INavigateToSearchResult
MatchKind = matchKind;
IsCaseSensitive = isCaseSensitive;
NavigableItem = navigableItem;
SecondarySort = ConstructSecondarySortString(declaredSymbolInfo);
SecondarySort = ConstructSecondarySortString(document, declaredSymbolInfo);
var declaredNavigableItem = navigableItem as NavigableItemFactory.DeclaredSymbolNavigableItem;
Debug.Assert(declaredNavigableItem != null);
......@@ -59,13 +60,32 @@ private class SearchResult : INavigateToSearchResult
});
}
private static string ConstructSecondarySortString(DeclaredSymbolInfo declaredSymbolInfo)
private static readonly char[] s_dotArray = { '.' };
private static string ConstructSecondarySortString(
Document document,
DeclaredSymbolInfo declaredSymbolInfo)
{
var secondarySortString = string.Concat(
declaredSymbolInfo.ParameterCount.ToString("X4"),
declaredSymbolInfo.TypeParameterCount.ToString("X4"),
declaredSymbolInfo.Name);
return secondarySortString;
var parts = ArrayBuilder<string>.GetInstance();
try
{
parts.Add(declaredSymbolInfo.ParameterCount.ToString("X4"));
parts.Add(declaredSymbolInfo.TypeParameterCount.ToString("X4"));
parts.Add(declaredSymbolInfo.Name);
// For partial types, we break up the file name into pieces. i.e. If we have
// Outer.cs and Outer.Inner.cs then we add "Outer" and "Outer Inner" to
// the secondary sort string. That way "Outer.cs" will be weighted above
// "Outer.Inner.cs"
var fileName = Path.GetFileNameWithoutExtension(document.FilePath ?? "");
parts.AddRange(fileName.Split(s_dotArray));
return string.Join(" ", parts);
}
finally
{
parts.Free();
}
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册