Search in sources :

Example 16 with SyntaxHighlighter

use of com.intellij.openapi.fileTypes.SyntaxHighlighter in project intellij-community by JetBrains.

the class HtmlHighlightingLexer method setEmbeddedLexer.

private void setEmbeddedLexer() {
    Lexer newLexer = null;
    if (hasSeenStyle()) {
        Lexer styleLexer = styleLexers.get(styleType);
        if (styleLexer == null) {
            if (hasSeenTag()) {
                IElementType currentStylesheetElementType = getCurrentStylesheetElementType();
                if (currentStylesheetElementType != null) {
                    Language language = currentStylesheetElementType.getLanguage();
                    styleLexer = SyntaxHighlighterFactory.getSyntaxHighlighter(language, null, null).getHighlightingLexer();
                } else if (ourStyleFileType != null) {
                    SyntaxHighlighter highlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(ourStyleFileType, null, null);
                    LOG.assertTrue(highlighter != null, ourStyleFileType);
                    styleLexer = highlighter.getHighlightingLexer();
                } else {
                    styleLexer = null;
                }
                styleLexers.put(styleType, styleLexer);
            } else if (hasSeenAttribute()) {
                if (ourStyleFileType == null) {
                    styleLexer = null;
                } else {
                    SyntaxHighlighter highlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(ourStyleFileType, null, null);
                    LOG.assertTrue(highlighter != null, ourStyleFileType);
                    styleLexer = highlighter.getHighlightingLexer();
                }
            }
        }
        newLexer = styleLexer;
    } else if (hasSeenScript()) {
        Lexer scriptLexer = scriptLexers.get(scriptType);
        if (scriptLexer == null) {
            if (hasSeenTag()) {
                HtmlScriptContentProvider provider = findScriptContentProvider(scriptType);
                if (provider != null) {
                    scriptLexer = provider.getHighlightingLexer();
                } else {
                    scriptLexer = SyntaxHighlighterFactory.getSyntaxHighlighter(PlainTextLanguage.INSTANCE, null, null).getHighlightingLexer();
                }
            } else if (hasSeenAttribute()) {
                SyntaxHighlighter syntaxHighlighter = ourInlineScriptFileType != null ? SyntaxHighlighterFactory.getSyntaxHighlighter(ourInlineScriptFileType, null, null) : null;
                scriptLexer = syntaxHighlighter != null ? syntaxHighlighter.getHighlightingLexer() : null;
            }
            scriptLexers.put(scriptType, scriptLexer);
        }
        newLexer = scriptLexer;
    } else {
        newLexer = createELLexer(newLexer);
    }
    if (newLexer != null) {
        embeddedLexer = newLexer;
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) Language(com.intellij.lang.Language) PlainTextLanguage(com.intellij.openapi.fileTypes.PlainTextLanguage) HtmlScriptContentProvider(com.intellij.lang.HtmlScriptContentProvider) SyntaxHighlighter(com.intellij.openapi.fileTypes.SyntaxHighlighter)

Aggregations

SyntaxHighlighter (com.intellij.openapi.fileTypes.SyntaxHighlighter)16 Language (com.intellij.lang.Language)7 LexerEditorHighlighter (com.intellij.openapi.editor.ex.util.LexerEditorHighlighter)5 EditorHighlighter (com.intellij.openapi.editor.highlighter.EditorHighlighter)5 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)4 NotNull (org.jetbrains.annotations.NotNull)4 EditorWindow (com.intellij.injected.editor.EditorWindow)3 TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)3 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)3 TextRange (com.intellij.openapi.util.TextRange)3 IElementType (com.intellij.psi.tree.IElementType)3 Lexer (com.intellij.lexer.Lexer)2 EditorEx (com.intellij.openapi.editor.ex.EditorEx)2 FileType (com.intellij.openapi.fileTypes.FileType)2 PlainSyntaxHighlighter (com.intellij.openapi.fileTypes.PlainSyntaxHighlighter)2 Project (com.intellij.openapi.project.Project)2 HighlightData (com.intellij.application.options.colors.highlighting.HighlightData)1 HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)1 HintManager (com.intellij.codeInsight.hint.HintManager)1 TemplateContextType (com.intellij.codeInsight.template.TemplateContextType)1