How to handle custom references when renaming the folder name?

I used `PsiReferenceContributor` and `PsiReferenceBase` to create a reference between the text (KtStringTemplateExpression) "folder/samplefile.txt" and the file "samplefile.txt" under the directory "folder".

`val template = "folder/samplefile.txt"`

When the user control clicks on "folder/samplefile.txt", the samplefile.txt will open in the editor. Works Fine!

I overrided `handleElementRename()` so that I can rename the filename and it reflects properly. Works Fine!

I overrided `bindToElement()` so that when I move the samplefile.txt from "folder" to "folder2", the reference is maintained. Works Fine!

But when I rename the directory "folder" to "folder2", `bindToElement()` is not getting called. How do I maintain the reference when the folder is renamed?


I guess, you need 2 references, one for 'folder' and one for 'samplefile'. You may look at `com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet` how the list of references is built.


Thank you so much Anna. I am working on creating 2 references and see how that goes.

But during this hunt, I found this link: . It talks about using FileRefereceSet and FileReference API to accomplish this. In it there was a mention about "Dummy PsiElement". 

Could you suggest any code where this is done, so I can refer that?


As far as I understand, you have kotlin string literal expression and you only need to pass provider, no dummy elements are required in your case. I am also not sure if this solution would be easier that doing everything manually as you initially started to do.



Please sign in to leave a comment.