Search in sources :

Example 11 with SyntaxHighlighter

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

the class SimpleEditorPreview method navigate.

private void navigate(boolean select, @NotNull final LogicalPosition pos) {
    int offset = myEditor.logicalPositionToOffset(pos);
    final SyntaxHighlighter highlighter = myPage.getHighlighter();
    String type;
    HighlightData highlightData = getDataFromOffset(offset);
    if (highlightData != null) {
        // tag-based navigation first
        type = RainbowHighlighter.isRainbowTempKey(highlightData.getHighlightKey()) ? RainbowHighlighter.RAINBOW_TYPE : highlightData.getHighlightType();
    } else {
        // if failed, try the highlighter-based navigation
        type = selectItem(myEditor.getHighlighter().createIterator(offset), highlighter);
    }
    setCursor(type == null ? Cursor.TEXT_CURSOR : Cursor.HAND_CURSOR);
    if (select && type != null) {
        myDispatcher.getMulticaster().selectionInPreviewChanged(type);
    }
}
Also used : HighlightData(com.intellij.application.options.colors.highlighting.HighlightData) SyntaxHighlighter(com.intellij.openapi.fileTypes.SyntaxHighlighter)

Example 12 with SyntaxHighlighter

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

the class LanguageConsoleImpl method printWithHighlighting.

public static String printWithHighlighting(@NotNull LanguageConsoleView console, @NotNull Editor inputEditor, @NotNull TextRange textRange) {
    String text;
    EditorHighlighter highlighter;
    if (inputEditor instanceof EditorWindow) {
        PsiFile file = ((EditorWindow) inputEditor).getInjectedFile();
        highlighter = HighlighterFactory.createHighlighter(file.getVirtualFile(), EditorColorsManager.getInstance().getGlobalScheme(), console.getProject());
        String fullText = InjectedLanguageUtil.getUnescapedText(file, null, null);
        highlighter.setText(fullText);
        text = textRange.substring(fullText);
    } else {
        text = inputEditor.getDocument().getText(textRange);
        highlighter = ((EditorEx) inputEditor).getHighlighter();
    }
    SyntaxHighlighter syntax = highlighter instanceof LexerEditorHighlighter ? ((LexerEditorHighlighter) highlighter).getSyntaxHighlighter() : null;
    ((LanguageConsoleImpl) console).doAddPromptToHistory();
    if (syntax != null) {
        ConsoleViewUtil.printWithHighlighting(console, text, syntax);
    } else {
        console.print(text, ConsoleViewContentType.USER_INPUT);
    }
    console.print("\n", ConsoleViewContentType.NORMAL_OUTPUT);
    return text;
}
Also used : PsiFile(com.intellij.psi.PsiFile) SyntaxHighlighter(com.intellij.openapi.fileTypes.SyntaxHighlighter) LexerEditorHighlighter(com.intellij.openapi.editor.ex.util.LexerEditorHighlighter) LexerEditorHighlighter(com.intellij.openapi.editor.ex.util.LexerEditorHighlighter) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter) EditorWindow(com.intellij.injected.editor.EditorWindow)

Example 13 with SyntaxHighlighter

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

the class MultiHostRegistrarImpl method obtainHighlightTokensFromLexer.

// returns lexer element types with corresponding ranges in encoded (injection host based) PSI
private static List<Trinity<IElementType, SmartPsiElementPointer<PsiLanguageInjectionHost>, TextRange>> obtainHighlightTokensFromLexer(Language language, StringBuilder outChars, List<LiteralTextEscaper<? extends PsiLanguageInjectionHost>> escapers, Place shreds, VirtualFileWindow virtualFile, Project project) {
    List<Trinity<IElementType, SmartPsiElementPointer<PsiLanguageInjectionHost>, TextRange>> tokens = new ArrayList<>(10);
    SyntaxHighlighter syntaxHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(language, project, (VirtualFile) virtualFile);
    Lexer lexer = syntaxHighlighter.getHighlightingLexer();
    lexer.start(outChars);
    int hostNum = -1;
    int prevHostEndOffset = 0;
    SmartPsiElementPointer<PsiLanguageInjectionHost> host = null;
    LiteralTextEscaper<? extends PsiLanguageInjectionHost> escaper = null;
    int prefixLength = 0;
    int suffixLength = 0;
    TextRange rangeInsideHost = null;
    int shredEndOffset = -1;
    for (IElementType tokenType = lexer.getTokenType(); tokenType != null; lexer.advance(), tokenType = lexer.getTokenType()) {
        TextRange range = new ProperTextRange(lexer.getTokenStart(), lexer.getTokenEnd());
        while (range != null && !range.isEmpty()) {
            if (range.getStartOffset() >= shredEndOffset) {
                hostNum++;
                PsiLanguageInjectionHost.Shred shred = shreds.get(hostNum);
                shredEndOffset = shred.getRange().getEndOffset();
                prevHostEndOffset = range.getStartOffset();
                host = ((ShredImpl) shred).getSmartPointer();
                escaper = escapers.get(hostNum);
                rangeInsideHost = shred.getRangeInsideHost();
                prefixLength = shred.getPrefix().length();
                suffixLength = shred.getSuffix().length();
            }
            //in prefix/suffix or spills over to next fragment
            if (range.getStartOffset() < prevHostEndOffset + prefixLength) {
                range = new UnfairTextRange(prevHostEndOffset + prefixLength, range.getEndOffset());
            }
            TextRange spilled = null;
            if (range.getEndOffset() > shredEndOffset - suffixLength) {
                spilled = new UnfairTextRange(shredEndOffset, range.getEndOffset());
                range = new UnfairTextRange(range.getStartOffset(), shredEndOffset - suffixLength);
            }
            if (!range.isEmpty()) {
                int start = escaper.getOffsetInHost(range.getStartOffset() - prevHostEndOffset - prefixLength, rangeInsideHost);
                if (start == -1)
                    start = rangeInsideHost.getStartOffset();
                int end = escaper.getOffsetInHost(range.getEndOffset() - prevHostEndOffset - prefixLength, rangeInsideHost);
                if (end == -1) {
                    end = rangeInsideHost.getEndOffset();
                    prevHostEndOffset = shredEndOffset;
                }
                TextRange rangeInHost = new ProperTextRange(start, end);
                tokens.add(Trinity.create(tokenType, host, rangeInHost));
            }
            range = spilled;
        }
    }
    return tokens;
}
Also used : ArrayList(java.util.ArrayList) SyntaxHighlighter(com.intellij.openapi.fileTypes.SyntaxHighlighter) IElementType(com.intellij.psi.tree.IElementType) Lexer(com.intellij.lexer.Lexer)

Example 14 with SyntaxHighlighter

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

the class LanguagePanel method updateHighlighters.

void updateHighlighters() {
    final EditorImpl editor = ((EditorImpl) myPrefix.getEditor());
    if (editor == null)
        return;
    final EditorImpl editor2 = ((EditorImpl) mySuffix.getEditor());
    assert editor2 != null;
    final Language language = InjectedLanguage.findLanguageById(getLanguage());
    if (language == null) {
        editor.setHighlighter(new LexerEditorHighlighter(new PlainSyntaxHighlighter(), editor.getColorsScheme()));
        editor2.setHighlighter(new LexerEditorHighlighter(new PlainSyntaxHighlighter(), editor.getColorsScheme()));
    } else {
        final SyntaxHighlighter s1 = SyntaxHighlighterFactory.getSyntaxHighlighter(language, myProject, null);
        final SyntaxHighlighter s2 = SyntaxHighlighterFactory.getSyntaxHighlighter(language, myProject, null);
        editor.setHighlighter(new LexerEditorHighlighter(s1, editor.getColorsScheme()));
        editor2.setHighlighter(new LexerEditorHighlighter(s2, editor2.getColorsScheme()));
    }
}
Also used : Language(com.intellij.lang.Language) InjectedLanguage(org.intellij.plugins.intelliLang.inject.InjectedLanguage) EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) LexerEditorHighlighter(com.intellij.openapi.editor.ex.util.LexerEditorHighlighter) PlainSyntaxHighlighter(com.intellij.openapi.fileTypes.PlainSyntaxHighlighter) SyntaxHighlighter(com.intellij.openapi.fileTypes.SyntaxHighlighter) PlainSyntaxHighlighter(com.intellij.openapi.fileTypes.PlainSyntaxHighlighter)

Example 15 with SyntaxHighlighter

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

the class GroovyEditorHighlighter method registerGroovydocHighlighter.

private void registerGroovydocHighlighter() {
    // Register GroovyDoc Highlighter
    SyntaxHighlighter groovyDocHighlighter = new GroovyDocSyntaxHighlighter();
    final LayerDescriptor groovyDocLayer = new LayerDescriptor(groovyDocHighlighter, "\n", GroovySyntaxHighlighter.DOC_COMMENT_CONTENT);
    registerLayer(GroovyDocElementTypes.GROOVY_DOC_COMMENT, groovyDocLayer);
}
Also used : GroovyDocSyntaxHighlighter(org.jetbrains.plugins.groovy.lang.groovydoc.highlighter.GroovyDocSyntaxHighlighter) SyntaxHighlighter(com.intellij.openapi.fileTypes.SyntaxHighlighter) GroovyDocSyntaxHighlighter(org.jetbrains.plugins.groovy.lang.groovydoc.highlighter.GroovyDocSyntaxHighlighter) LayerDescriptor(com.intellij.openapi.editor.ex.util.LayerDescriptor)

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