Completion based on the content of external files
已回答
I need to implement the completion based on the content of external files (currently local files only, but I'd like to support remote files in the future). The idea:
- The plugin has a config file which's located in the project root and contains the list of the external files which should be used for the completion.
- At startup or on the first request from the completion contributor, the plugin should build an index for each external file. The index will be used to lookup candidates based on a given prefix.
- The indexes should be rebuilt based on changes in the content of the external files. Ideally, the indexes should be persisted between the restarts.
I guess, the idea isn't new at all, so I'm looking for some existing implementations which I could get some inspiration from. Questions:
- Is there any existing API which I could use to store the indexes? Should the file-based indexes help me? If so, does it support the prefix-based search?
- I guess, I can use the Virtual File System to monitor the changes in the external files. Right?
Thank you in advance!
请先登录再写评论。
Could you elaborate what kind of data will be stored, does it depend only on content of these files? What exactly means "remote" in "remote files"?
Hi Yann! The index should contain a list of strings and should provide an efficient prefix-based search over this list. The list of strings is computed from the content of an external file. An external file is a local file outside of a IDEA project. A remote external file means that it should be accessed over HTTP(S) protocol.
Sounds like FileBasedIndex could work for this case. Prefix-based matching can be built on top of that by iterating all registered keys and then process/collect matching data.
To monitor them for changes, they must not be accessed via HTTP protocol though. Maybe download them automatically to some temp directory (e.g. on project open or provide some explicit synchronization action) and use them from there instead.
Yes, looks like FileBasedIndex should help, but as I understand it indexes only files within the project directory, right? Is there a way to ask an implementation of the FileBasedIndexExtension to index and monitor a file outside of the project directory?
Yes, see com.intellij.util.indexing.IndexableSetContributor.