intellij-dlanguage icon indicating copy to clipboard operation
intellij-dlanguage copied to clipboard

syntax highlighting for diet templates

Open SingingBush opened this issue 8 years ago • 5 comments

when working on my webapp I use Intellij's Jade plugin and associate the .dt extension as being a jade file. However, this isn't ideal as diet templates also allow D code in the template.

As vibe.d is pretty much the goto library for any D web project would it be possible to add support for the diet template language it uses. At least providing the syntax highlighting that the Jade plugin provides or perhaps instead, if possible, to suggest installation of the Jade plugin and automatically do the file association if a diet template is detected and the plugin is not currently installed.

SingingBush avatar Mar 03 '16 17:03 SingingBush

For completeness, this screenshot shows how to associate diet templates as Jade. treatdietasjade

Is pretty handy as it ensures that indentation is done correctly.

SingingBush avatar Mar 03 '16 17:03 SingingBush

Yeah I will add it to my list - however I have found I need to do a lot of work around the references to enable full refactoring capability - so thats going to be first on my list and I think it will take a few weeks from when I start.

kingsleyh avatar Mar 03 '16 19:03 kingsleyh

I've been trying to find more information about the depends tag in plugin xml. I suspect we can specify the Pug (ex-Jade) plugin as an optional dependency and at least use it for syntax highlighting diet templates. As usual though documentation is less than ideal.

So far I've found that we should specify dependencies on other plugins in build.gradle:

    intellij {
        ...
        plugins ['com.jetbrains.plugins.jade:171.4073.15']
        // can specify built-in Intellij plugins that our plugin relies on such as 'copyright', 'coverage', or 'yaml'. alternatively we can refer to plugins in the repository using the full id.
    }

then specify an optional dependency in plugin.xml which refers to another plugin xml file that hooks references the bits of the plugin we want access to

<!-- diet template can be supported better if Pug (ex-Jade) plugin is installed
        https://plugins.jetbrains.com/plugin/7094-pug-ex-jade-                     -->
<depends optional="true" config-file="diet-plugin.xml">com.jetbrains.plugins.jade</depends>

so diet-plugin.xml would be something like:

<idea-plugin>
    <extensions defaultExtensionNs="com.intellij">
        <lang.syntaxHighlighterFactory language="pug" implementationClass="whatever.the.class.is.called"/>
    </extensions>
</idea-plugin>

This is just a rough idea of how I think it all works. I've not got anything working yet and it seems that the Pug (ex-Jade) plugin is not available for Intellij 2017.1 yet. I just wanted to share what I've found - hopefully someone can confirm if I've got the right idea or not.

SingingBush avatar Apr 14 '17 13:04 SingingBush

This will be worked on in https://github.com/intellij-dlanguage/intellij-diet

It's just work in progress at moment.

SingingBush avatar Jul 28 '17 21:07 SingingBush

it seems that diet support can be solved by implementing com.intellij.fileType.fileViewProviderFactory (see docs) and specifying .dt files as being a mix of D and Pug languages. Something like:

<extensions defaultExtensionNs="com.intellij">
  <fileType.fileViewProviderFactory
      filetype="DIET"
      implementationClass="o.github.intellij.dlanguage.diet.DietViewProviderFactory"/>
</extensions>

along with:

class DietFileViewProviderFactory : FileViewProviderFactory {

    override fun createFileViewProvider(file: VirtualFile, language: Language?, manager: PsiManager, eventSystemEnabled: Boolean): FileViewProvider {
        return DietFileViewProvider(manager, file, eventSystemEnabled)
    }
}

class DietFileViewProvider(manager: PsiManager, file: VirtualFile, eventSystemEnabled: Boolean = true)
                            : SingleRootFileViewProvider(manager, file, eventSystemEnabled, DLanguage) {
    
    override fun getBaseLanguage(): Language = DLanguage

    override fun getLanguages(): MutableSet<Language> = mutableSetOf(DLanguage, JadeLanguage.INSTANCE)
}

SingingBush avatar Jun 03 '22 22:06 SingingBush