GetUniqueVirtualFilePath does not consider library files inside FindDialog

Answered

Hi,

in our internal plugin we use IDEA to index an archive of zip files to provide references and documentation for a framework. This archives are added as library root entries to the project to enable indexing and full text search of the contained files.

The references and index all work fine but recently we discovered that the "Find in Path" function does not correctly distinguish between files with the same name that are contained in different archives. This can be seen in the screenshot below, where a search with the scope "Project and Libraries" was performed that results in a lot of different "package.xml" files from different library entries (plus one extracted archive folder that did also match).

 

This makes it hard to distinguish between the different files. After some debugging I found that the com.intellij.openapi.fileEditor.impl.UniqueVFilePathBuilderImpl#getUniqueVirtualFilePath method does not consider library files even if used inside the Find in Path search with scope "Project and Libraries". The affected code (from UniqueVFilePathBuilderImpl.java:85) can be seen below, which uses the ProjectScope regardless of the search settings.

final UniqueNameBuilder<VirtualFile> builder = filesWithTheSameName(
fileName,
project,
skipNonOpenedFiles,
ProjectScope.getProjectScope(project)
);

Relevant call from FindDialog:1731 :

@NotNull
private String getFilePath(@NotNull UsageInfo2UsageAdapter ua) {
String uniquePath =
UniqueVFilePathBuilder.getInstance().getUniqueVirtualFilePath(ua.getUsageInfo().getProject(), ua.getFile());
return myOmitFileExtension ? StringUtil.trimExtension(uniquePath) : uniquePath;
}

 

I know however that the UniqueVFilePathBuilder is used in various other places throughout the editor and is not directly search specific, so that this would require a more complex change.

My question is now: Is there any way this behavior can be customized by plugins at the current moment or would this require changes to the IDEA core? Concretely I would like to enlarge the search scope for the UniqueVFilePathBuilder if it is used in a search with a larger scope i.e. "Project and Libraries" which includes the required library files.

Thanks in advance for looking into this

Please sign in to leave a comment.