Search in sources :

Example 1 with ProperTextRange

use of com.intellij.openapi.util.ProperTextRange in project intellij-community by JetBrains.

the class DomUIFactoryImpl method createDomHighlighter.

@Override
public BackgroundEditorHighlighter createDomHighlighter(final Project project, final PerspectiveFileEditor editor, final DomElement element) {
    return new BackgroundEditorHighlighter() {

        @Override
        @NotNull
        public HighlightingPass[] createPassesForEditor() {
            if (!element.isValid())
                return HighlightingPass.EMPTY_ARRAY;
            final XmlFile psiFile = DomUtil.getFile(element);
            final PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project);
            final Document document = psiDocumentManager.getDocument(psiFile);
            if (document == null)
                return HighlightingPass.EMPTY_ARRAY;
            editor.commit();
            GeneralHighlightingPass ghp = new GeneralHighlightingPass(project, psiFile, document, 0, document.getTextLength(), true, new ProperTextRange(0, document.getTextLength()), null, new DefaultHighlightInfoProcessor());
            LocalInspectionsPass lip = new LocalInspectionsPass(psiFile, document, 0, document.getTextLength(), LocalInspectionsPass.EMPTY_PRIORITY_RANGE, true, new DefaultHighlightInfoProcessor());
            return new HighlightingPass[] { ghp, lip };
        }

        @Override
        @NotNull
        public HighlightingPass[] createPassesForVisibleArea() {
            return createPassesForEditor();
        }
    };
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) LocalInspectionsPass(com.intellij.codeInsight.daemon.impl.LocalInspectionsPass) ProperTextRange(com.intellij.openapi.util.ProperTextRange) BackgroundEditorHighlighter(com.intellij.codeHighlighting.BackgroundEditorHighlighter) Document(com.intellij.openapi.editor.Document) DefaultHighlightInfoProcessor(com.intellij.codeInsight.daemon.impl.DefaultHighlightInfoProcessor) HighlightingPass(com.intellij.codeHighlighting.HighlightingPass) GeneralHighlightingPass(com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass) PsiDocumentManager(com.intellij.psi.PsiDocumentManager) GeneralHighlightingPass(com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass)

Example 2 with ProperTextRange

use of com.intellij.openapi.util.ProperTextRange in project intellij-community by JetBrains.

the class ChameleonSyntaxHighlightingPass method collectHighlights.

private void collectHighlights(@NotNull PsiElement element, @NotNull List<HighlightInfo> inside, @NotNull List<HighlightInfo> outside, @NotNull ProperTextRange priorityRange) {
    EditorColorsScheme scheme = ObjectUtils.notNull(getColorsScheme(), EditorColorsManager.getInstance().getGlobalScheme());
    TextAttributes defaultAttrs = scheme.getAttributes(HighlighterColors.TEXT);
    Language language = ILazyParseableElementType.LANGUAGE_KEY.get(element.getNode());
    if (language == null)
        return;
    SyntaxHighlighter syntaxHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(language, myProject, myFile.getVirtualFile());
    for (PsiElement token : psiTraverser(element).traverse(TreeTraversal.LEAVES_DFS)) {
        TextRange tr = token.getTextRange();
        if (tr.isEmpty())
            continue;
        IElementType type = PsiUtilCore.getElementType(token);
        TextAttributesKey[] keys = syntaxHighlighter.getTokenHighlights(type);
        // force attribute colors to override host' ones
        TextAttributes attributes = null;
        for (TextAttributesKey key : keys) {
            TextAttributes attrs2 = scheme.getAttributes(key);
            if (attrs2 != null) {
                attributes = attributes == null ? attrs2 : TextAttributes.merge(attributes, attrs2);
            }
        }
        TextAttributes forcedAttributes;
        if (attributes == null || attributes.isEmpty() || attributes.equals(defaultAttrs)) {
            forcedAttributes = TextAttributes.ERASE_MARKER;
        } else {
            HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.INJECTED_LANGUAGE_FRAGMENT).range(tr).textAttributes(TextAttributes.ERASE_MARKER).createUnconditionally();
            (priorityRange.contains(tr) ? inside : outside).add(info);
            forcedAttributes = new TextAttributes(attributes.getForegroundColor(), attributes.getBackgroundColor(), attributes.getEffectColor(), attributes.getEffectType(), attributes.getFontType());
        }
        HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.INJECTED_LANGUAGE_FRAGMENT).range(tr).textAttributes(forcedAttributes).createUnconditionally();
        (priorityRange.contains(tr) ? inside : outside).add(info);
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) Language(com.intellij.lang.Language) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) ProperTextRange(com.intellij.openapi.util.ProperTextRange) TextRange(com.intellij.openapi.util.TextRange) SyntaxHighlighter(com.intellij.openapi.fileTypes.SyntaxHighlighter) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) PsiElement(com.intellij.psi.PsiElement)

Example 3 with ProperTextRange

use of com.intellij.openapi.util.ProperTextRange in project intellij-community by JetBrains.

the class GeneralHighlightingPassFactory method createHighlightingPass.

@Override
@Nullable
public TextEditorHighlightingPass createHighlightingPass(@NotNull PsiFile file, @NotNull final Editor editor) {
    TextRange textRange = FileStatusMap.getDirtyTextRange(editor, Pass.UPDATE_ALL);
    if (textRange == null)
        return new EmptyPass(myProject, editor.getDocument());
    ProperTextRange visibleRange = VisibleHighlightingPassFactory.calculateVisibleRange(editor);
    return new GeneralHighlightingPass(myProject, file, editor.getDocument(), textRange.getStartOffset(), textRange.getEndOffset(), true, visibleRange, editor, new DefaultHighlightInfoProcessor());
}
Also used : EmptyPass(com.intellij.codeInsight.daemon.impl.ProgressableTextEditorHighlightingPass.EmptyPass) ProperTextRange(com.intellij.openapi.util.ProperTextRange) ProperTextRange(com.intellij.openapi.util.ProperTextRange) TextRange(com.intellij.openapi.util.TextRange) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with ProperTextRange

use of com.intellij.openapi.util.ProperTextRange in project intellij-community by JetBrains.

the class InjectedGeneralHighlightingPassFactory method createHighlightingPass.

@Override
@Nullable
public TextEditorHighlightingPass createHighlightingPass(@NotNull PsiFile file, @NotNull final Editor editor) {
    TextRange textRange = FileStatusMap.getDirtyTextRange(editor, Pass.UPDATE_ALL);
    if (textRange == null)
        return new ProgressableTextEditorHighlightingPass.EmptyPass(myProject, editor.getDocument());
    ProperTextRange visibleRange = VisibleHighlightingPassFactory.calculateVisibleRange(editor);
    return new InjectedGeneralHighlightingPass(myProject, file, editor.getDocument(), textRange.getStartOffset(), textRange.getEndOffset(), true, visibleRange, editor, new DefaultHighlightInfoProcessor());
}
Also used : ProperTextRange(com.intellij.openapi.util.ProperTextRange) ProperTextRange(com.intellij.openapi.util.ProperTextRange) TextRange(com.intellij.openapi.util.TextRange) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with ProperTextRange

use of com.intellij.openapi.util.ProperTextRange in project intellij-community by JetBrains.

the class LineMarkersPassFactory method createHighlightingPass.

@Override
@Nullable
public TextEditorHighlightingPass createHighlightingPass(@NotNull PsiFile file, @NotNull final Editor editor) {
    TextRange restrictRange = FileStatusMap.getDirtyTextRange(editor, Pass.LINE_MARKERS);
    Document document = editor.getDocument();
    if (restrictRange == null)
        return new ProgressableTextEditorHighlightingPass.EmptyPass(myProject, document);
    ProperTextRange visibleRange = VisibleHighlightingPassFactory.calculateVisibleRange(editor);
    return new LineMarkersPass(myProject, file, document, expandRangeToCoverWholeLines(document, visibleRange), expandRangeToCoverWholeLines(document, restrictRange));
}
Also used : ProperTextRange(com.intellij.openapi.util.ProperTextRange) ProperTextRange(com.intellij.openapi.util.ProperTextRange) TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ProperTextRange (com.intellij.openapi.util.ProperTextRange)31 TextRange (com.intellij.openapi.util.TextRange)14 com.intellij.codeInsight.hint (com.intellij.codeInsight.hint)4 PsiElement (com.intellij.psi.PsiElement)4 RelativePoint (com.intellij.ui.awt.RelativePoint)4 NotNull (org.jetbrains.annotations.NotNull)4 Nullable (org.jetbrains.annotations.Nullable)4 Document (com.intellij.openapi.editor.Document)2 Segment (com.intellij.openapi.util.Segment)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 List (java.util.List)2 BackgroundEditorHighlighter (com.intellij.codeHighlighting.BackgroundEditorHighlighter)1 HighlightingPass (com.intellij.codeHighlighting.HighlightingPass)1 EditorInfo (com.intellij.codeInsight.EditorInfo)1 DefaultHighlightInfoProcessor (com.intellij.codeInsight.daemon.impl.DefaultHighlightInfoProcessor)1 GeneralHighlightingPass (com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass)1 LocalInspectionsPass (com.intellij.codeInsight.daemon.impl.LocalInspectionsPass)1 EmptyPass (com.intellij.codeInsight.daemon.impl.ProgressableTextEditorHighlightingPass.EmptyPass)1 GenericElementSignatureProvider (com.intellij.codeInsight.folding.impl.GenericElementSignatureProvider)1 InspectionManager (com.intellij.codeInspection.InspectionManager)1