in plugin-bazel/src/main/kotlin/org/jetbrains/bazel/golang/treeview/BazelGoTreeStructureProvider.kt [43:87]
override fun modify(
parent: AbstractTreeNode<*>,
children: Collection<AbstractTreeNode<*>>,
settings: ViewSettings,
): Collection<AbstractTreeNode<*>?> {
val project: Project = parent.project
if (!project.isBazelProject ||
!isGoBazelExternalLibraryRoot(parent)
) {
return children
}
val originalFileNodes = getOriginalFileNodesMap(children)
val fileToImportPathMap = BazelGoPackageFactory.getFileToImportPathMap(project)
val newChildren = TreeMap<String, AbstractTreeNode<*>>()
val importPathToFilesMap =
originalFileNodes.keys
.stream()
.collect(
ImmutableListMultimap.toImmutableListMultimap(
// Some nodes may, for some reason, not be in importPathMap, use the empty
// String as a guard character.
Function { virtualFile -> fileToImportPathMap.getOrDefault(VfsUtil.virtualToIoFile(virtualFile).toPath(), "") },
Function.identity(),
),
)
for (importPath in importPathToFilesMap.keySet()) {
if (importPath.isEmpty()) {
continue
}
generateTree(
settings,
project,
newChildren,
importPath,
importPathToFilesMap[importPath].toSet(),
originalFileNodes,
)
}
val directChildren = importPathToFilesMap[""].mapNotNull { originalFileNodes[it] }
return newChildren.values + directChildren
}