Custom Project FIle/Directory Path Completion Contributor and Provider for YAML Files
I'm trying to create a custom completion contributor and provider where I can make it so certain YAML keys have completion with available file/directory paths in the current project.
E.g. If I have the following project directory structure:
dir1/
dir2/
file1
somefile.yaml
then if I have a “path” key in the in somefile.yaml:
someparentkey:
path: <...>
then autocomplete after “path: ” should have completion results of “dir1/” and “file1”, and if I choose “dir1/” then it should next provide completion results of “dir2/” and all other directories/files in that directory, etc.
Are there any resources on how to do this? I saw there was a FilePathCompletionContributor class but it doesn't entirely fit my needs since its Provider is not public, so I can't use it
Also, I was wondering if there was a way to have this contributor only apply when a certain condition is met (e.g., if the file has a specific name)?
Please sign in to leave a comment.
Hi Marcus,
See: https://intellij-support.jetbrains.com/hc/en-us/community/posts/206756005-Is-There-A-Standard-CompletionContributor-Which-Provides-Path-File-Completion
Hi Karol Lewandowski ,
Thank you for the reply! I had come across that post but I wasn't sure if it was out of date since it's a decade old, and I didn't quite understand some of the follow up replies at the end since the examples are no longer available.
Just to confirm, is the following reply still accurate:
that is, it's likely more feasible to hand-coding a completion contributor by traversing the project structure to show a list of files/directories?
Hi Marcus,
I understand it might look outdated, but it doesn't seem so in this case.
Regarding the pasted examples, you can find them in older Git branches. As the answer containing examples was posted in January 2017, I suggest checking the 171 branch (171 means version 2017.1):
I'm not sure if it is the easiest approach in your case - using
PathReferenceManager
orFileReferenceSet
. I would try with the simpler one, which seems to bePathReferenceManager
and see if it's sufficient.Okay, understood, thank you so much Karol, I'll look into the resources you provided!