Disable warnings and errors for injected code
Answered
I am currently using a MultiHostInjector to provide syntax highlighting for Java code embedded inside string literals within a custom language. While this works great, the embedded Java literals should not necessarily receive error / warning highlighting. Is it possible to somehow disable this functionality of the MultiHostInjector?
Additionally, for my own understanding, which component is responsible for the syntax highlighting in this scenario? Does the InjectionRegistrar forward the task to the lexer and SyntaxHighlighter of the specified language or to the IntelliLang plugin?
Please sign in to leave a comment.
You can use com.intellij.codeInsight.highlighting.HighlightErrorFilter, see e.g. com.intellij.htmltools.xml.util.XHtmlErrorFilter as sample
Thank you so far. I tried registering a custom com.intellij.codeInsight.highlighting.HighlightErrorFilter at the corresponding extension point. However, com.intellij.codeInsight.highlighting.HighlightErrorFilter#shouldHighlightErrorElement is never called. Is this due to the fact that my custom language only defines its own file type. while specifying the contained language as Groovy?
Please show a screenshot of what you mean exactly with "error/warning highlighting". Are these from inspections?
Most common are errors within comments as seen in the first screenshot. However, there are also some warnings regarding the actual code (cf. second and third screenshot). Eventually, it would be great if all those highlightings could be disabled.
Ah OK, you'll need different extension points to suppress inspection highlighting. One from above is for parser errors.
com.intellij.codeInsight.daemon.impl.HighlightInfoFilter, see https://plugins.jetbrains.com/intellij-platform-explorer?extensions=com.intellij.daemon.highlightInfoFilter for additional samples. Please be very careful with determining whether your filter should be applied or not for context, otherwise it might suppress valid highlighting in other places.