How to search global library without module attachment
Hi,
I'd like to search a global library which is not attached to the module in which the source file is located.
When the global library is attached everything works nicely via
LibraryTable.ModifiableModel model = LibraryTablesRegistrar.getInstance().getLibraryTable().getModifiableModel();
Library library = model.getLibraryByName(LibraryUtil.R_SKELETONS);
Collection<RAssignmentStatement> assignmentStatements = RAssignmentNameIndex.find(name, project, new LibraryScope(project, library));
However, when I remove/ the library from the module I can still get a reference to the library as before, but RAssignmentNameIndex.find returns an empty result set. Is there a different scope impl I would need to use here?
Previously I attached the R package index library to every module be default, but one of the JB engineers suggested that this is bad practice, so I'd like to change it.
请先登录再写评论。
Clarification: there is nothing wrong in having the R package in dependencies of a module. The bad practice is adding the dependency to all modules - even to those which don't have a single R file in it.
I'd recommend the approach used in Kotlin plugin: subscribing to file creation events and suggesting to add the dependency to a module in which R file was created.
Content of a global library is indexed only if the libraries is added to the dependencies list of some module. So if it isn't attached to any module RAssignmentNameIndex won't contain values from it.
It's possible to specify additional directories which content needs to be indexed, but probably the way suggested by Roman is better: you can add the library to dependencies in New Module Wizard for your module type and suggest to configure the library in an existing module if R file is found in it.
Thanks gentleman!
I would love to change it to behave more like the kotlin plugin. Could I also listen for file open-event instead of *just* creations? So whenever a user opens an R file in a module the plugin would attach the r library to the module.
Once this is working, I try to make it opt-in via some suggestion UI.
Could you point me to the API which allows to listen for such file events?
You may subscribe to `FileEditorManagerListener#FILE_EDITOR_MANAGER` topic.