Is There A Standard CompletionContributor Which Provides Path/File Completion
Hi,
this is a follow-up of another thread. I am trying to implement a plugin which provides basic path/file autocompletion. For the time being, the autocompletion should simply suggest the files and folders relative to the file location. Hence, given this structure:
dir1
dir2
file
mycustomfile
If the file mycustomfile is opened, the autocompletion should suggest "dir1". If one enters "dir1/", it should suggest "dir2" etc. Is there any standard CompletionContributor which provides such a functionality or do I have to code that by hand?
Cheers
Simon
Please sign in to leave a comment.
The short answer is no, there is no such standard completion contributor.
There is a standard mechanism for path completion, using the FileReference/FileReferenceSet classes, but you need to do a little more work in order to use it (you need to implement the getReferences() method in your dummy PSI element, locate the dummy identifier inserted into your file by the completion mechanism, and return the references collected from a FileReferenceSet created at that location). Depending on your requirements, this approach may or may not be easier than simply hand-coding a completion contributor.
I think it's even easier now:
1. Implement a PsiReferenceProvider using the PathReferenceManager to collect the files. For an example see
https://github.com/JetBrains/intellij-plugins/blob/master/markdown/src/org/intellij/plugins/markdown/lang/references/MarkdownReferenceProvider.java
2. Use it when overriding getReferences in your PsiElement-impl:
https://github.com/JetBrains/intellij-plugins/blob/master/markdown/src/org/intellij/plugins/markdown/lang/psi/impl/MarkdownLinkDestinationImpl.java#L25-L25
3. in the plugin.xml declare:
<psi.referenceContributor implementation="org.intellij.plugins.markdown.lang.references.MarkdownReferenceProvider"/>
This worked well for me.
@Dimitry:
1. Is it possible to collect file-references recursively also including sub-directories when using `PathReferenceManager.getInstance().createReferences`?
2. Is it possible to show completion options in this context also without typing a first letter?
Thanks,
Holger
Maybe my questions were too hidden in my last posting:
1. Is it possible to collect file-references recursively also including sub-directories when using `PathReferenceManager.getInstance().createReferences`?
2. Is it possible to show completion options in this context also without typing a first letter?
Thanks,
Holger