in resharper/resharper-unity/src/Unity.Rider/Integration/AsmDef/Feature/Usages/UnityAsmDefCustomGroupingProjectItemProvider.cs [33:93]
public override RdUsageGroupTextAndIcon? GetUsageGroup(IOccurrence occurrence, ProjectItemKind kind, bool takeParent)
{
if (occurrence is ReferenceOccurrence referenceOccurrence &&
referenceOccurrence.Kinds.Contains(AsmDefOccurrenceKindProvider.AssemblyDefinitionReference) &&
referenceOccurrence.PrimaryReference is AsmDefNameReference reference)
{
var sourceLocation = reference.GetTreeNode().GetSourceFile()?.GetLocation();
if (sourceLocation == null || sourceLocation.IsEmpty)
return null;
// If the .asmdef belongs to a real project, let the default grouping handle it
var isProjectItem = mySolution.FindProjectItemsByLocation(sourceLocation)
.Any(pi => !pi.IsMiscProjectItem());
if (isProjectItem)
return null;
switch (kind)
{
case ProjectItemKind.PHYSICAL_FILE:
var filePath = GetPresentablePath(sourceLocation, mySolution.SolutionDirectory);
if (filePath != null)
{
return new RdUsageGroupTextAndIcon(ExternalPackagesPrefix + filePath.FullPath,
myIconHost.Transform(UnityFileTypeThemedIcons.AsmdefPackage.Id));
}
break;
case ProjectItemKind.PHYSICAL_DIRECTORY:
var directoryPath = GetPresentablePath(sourceLocation.Directory, mySolution.SolutionDirectory);
if (directoryPath != null)
{
return new RdUsageGroupTextAndIcon(ExternalPackagesPrefix + directoryPath.FullPath,
myIconHost.Transform(myProjectModelIcons.DirectoryIcon));
}
break;
case ProjectItemKind.PROJECT:
if (takeParent)
{
// If takeParent is true, it means it's a solution folder(s). We'll invent an external
// packages folder to group our external files
return new RdUsageGroupTextAndIcon(ExternalPackages,
myIconHost.Transform(UnityObjectTypeThemedIcons.UnityPackages.Id));
}
else
{
// Group by package
directoryPath = GetPresentablePath(sourceLocation, mySolution.SolutionDirectory);
if (directoryPath != null)
{
return new RdUsageGroupTextAndIcon(
ExternalPackagesPrefix + directoryPath.Components.FirstOrEmpty,
myIconHost.Transform(UnityFileTypeThemedIcons.FolderPackageReferenced.Id));
}
}
return new RdUsageGroupTextAndIcon(string.Empty, myIconHost.Transform(UnityFileTypeThemedIcons.FileUnity.Id));
}
}
return null;
}