Highlight js code in jsdoc comment


Good day

Can somebody please help me to create “Place pattern” for language injection of js code in jsdoc comment.

I'v already installed PsiViewer and found out path to needed psi element which should be highlighted - it's JSDocDescription in JSDocTag with PsiElement(JS:DOC_TAG_NAME) equals `@body`

I can only guess that pattern could be like this

+ jsDocDescription(jsDocTag().withQualifiedName("@body"))

definitely there should be something else instead of withQualifiedName


Or maybe patter could be like this?

+ jsDocDescription().withStringValueIgnoringInterpolations(stringMatchesBrics(" *{.*} *"))

but I just find out that jsDocDescription is invalid pattern

Will give you example of what I want to achieve 

 * @example {user: db.user.pick('id', 'name')}

everything after @example should be highlighted as js code. Would be great if IDE will not run inspections on it, just syntax highlighting


Hi Sergii,

I can't find any patterns related to JS docs.

Instead of defining injections via XML, you can implement your custom injection logic programmatically. See:

If you must stick to IntelliLang and XMLs, then it seems you need to implement custom LanguageInjectionSupport and register your pattern (which you also need to implement) class with getPatternClasses.

See https://plugins.jetbrains.com/docs/intellij/language-injection.html#implementation and existing implementations in https://github.com/JetBrains/intellij-community or https://jb.gg/ipe.

Another way is to create a feature request which would allow defining such injections. https://youtrack.jetbrains.com/issues/WEB looks like a correct place for such an issue.


Please sign in to leave a comment.