AdditionalLibraryRootsProvider.getRootsToWatch does not include subdirectories

Answered

Hi,
I have implemented custom AdditionalLibraryRootsProvider to add root directory X to External Libraries. I also overridden getRootsToWatch method to watch directory X for changes. On startup everything works as should be, in External Libraries tab I see root X with all its content, however If I add new directory inside X, in the file tree, the new directory is seen without its content.

Ex.: 
Creating Folder Y with files a, b inside X root.
expected view in file tree:

  External Libraries:
    X:
       Y:
           a
           b
Actual view (files a, b are missing):
  External Libraries:
    X:
        Y:


After restarting IDE Everything is presented as expected. What I am doing incorrectly? How can force to watch new folders recursively?

My AdditionalLibraryRootsProvider implementation:

class NpmSourcesLibraryRootProvider : AdditionalLibraryRootsProvider() {

override fun getAdditionalProjectLibraries(project: Project): MutableCollection<SyntheticLibrary> {
val rootDirectoryFile = SourceCacheDirectory.getSourceCacheDirectoryFile()
val library = NpmSourcesSyntheticLibrary(rootDirectoryFile)
return mutableListOf(library)
}

override fun getRootsToWatch(project: Project): MutableCollection<VirtualFile> {
val rootDirectoryFile = SourceCacheDirectory.getSourceCacheDirectoryFile()
return mutableListOf(rootDirectoryFile)
}
}

class NpmSourcesSyntheticLibrary(private val libraryRootDirectory: VirtualFile) : SyntheticLibrary(), ItemPresentation {

override fun getPresentableText(): String = "npm sources"

override fun getIcon(unused: Boolean): Icon? = null

override fun getSourceRoots(): Collection<VirtualFile> = libraryRootDirectory.children.toList()

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as NpmSourcesSyntheticLibrary

if (libraryRootDirectory != other.libraryRootDirectory) return false

return true
}

override fun hashCode(): Int = libraryRootDirectory.hashCode()
}

 

0
2 comments

Hi Tadaso,

Why your:

override fun getSourceRoots(): Collection<VirtualFile> = libraryRootDirectory.children.toList()

returns children of root directory? Maybe this is the reason - only children of the root directory are refreshed, not the root directory itself. Please change it to:

override fun getSourceRoots(): Collection<VirtualFile> = listOf(libraryRootDirectory)

and see if it solved the issue.

1

Hey Karol,

that indeed solved my issue. Thanks for the help! 

0

Please sign in to leave a comment.