How can I add a custom freemarker FtlControllerDirective '<#controller "path/to/file'>"

We are using Freemarker.

I’d like to add custom directive support for auto-complete and File reference resolution.

Requirements:

  • Work on Intellij Ultimate with the Bundled Freemarker plugin.
  • Allow me to use `<#controller “path/to/controllers.ftlh”`
  • The plugin will provide the path to that file, and be able to read the <#macro>’s defined in it similar to how <#include …> does it.

I have spend a lot of time trying to make this happen, but I can get the psiElement(..) registration to trigger no matter what I do.

I was focusing on:

  • FtlStringLiteral
  • FtlDirective
  • UNKNOWN_DIRECTIVE
  • A lot of time in the freemarker.jar to figure out how to integrate, and PsiViewer.

Is this even possible?

Can someone give me some pointers?

I think the TLDR is:

Mimic the FtlIncludeDirective to provide support a new directive that will resolve the pathes a bit different with it’s own Reference Contributor

Thanks!