Search in sources :

Example 16 with ProperTextRange

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

the class EditorMarkupModelImpl method repaint.

// startOffset == -1 || endOffset == -1 means whole document
void repaint(int startOffset, int endOffset) {
    ProperTextRange range = offsetsToYPositions(startOffset, endOffset);
    markDirtied(range);
    if (startOffset == -1 || endOffset == -1) {
        myDirtyYPositions = WHOLE_DOCUMENT;
    }
    JScrollBar bar = myEditor.getVerticalScrollBar();
    bar.repaint(0, range.getStartOffset(), bar.getWidth(), range.getLength() + myMinMarkHeight);
}
Also used : ProperTextRange(com.intellij.openapi.util.ProperTextRange)

Example 17 with ProperTextRange

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

the class EditorMarkupModelImpl method getNearestHighlighters.

private void getNearestHighlighters(@NotNull MarkupModelEx markupModel, final int scrollBarY, @NotNull final Collection<RangeHighlighter> nearest) {
    int startOffset = yPositionToOffset(scrollBarY - myMinMarkHeight, true);
    int endOffset = yPositionToOffset(scrollBarY + myMinMarkHeight, false);
    markupModel.processRangeHighlightersOverlappingWith(startOffset, endOffset, highlighter -> {
        if (highlighter.getErrorStripeMarkColor() != null) {
            ProperTextRange range = offsetsToYPositions(highlighter.getStartOffset(), highlighter.getEndOffset());
            if (scrollBarY >= range.getStartOffset() - myMinMarkHeight * 2 && scrollBarY <= range.getEndOffset() + myMinMarkHeight * 2) {
                nearest.add(highlighter);
            }
        }
        return true;
    });
}
Also used : ProperTextRange(com.intellij.openapi.util.ProperTextRange) com.intellij.codeInsight.hint(com.intellij.codeInsight.hint) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 18 with ProperTextRange

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

the class DartServerFindUsagesTest method checkUsages.

private void checkUsages(@NotNull final SearchScope scope, @NotNull final String... expected) {
    final String[] actualResult = ContainerUtil.map2Array(findUsages(scope), String.class, info -> {
        final PsiElement element = info.getElement();
        assertNotNull(element);
        final ProperTextRange range = info.getRangeInElement();
        assertNotNull(range);
        final int startOffset = element.getTextRange().getStartOffset() + range.getStartOffset();
        final int endOffset = element.getTextRange().getStartOffset() + range.getEndOffset();
        return element.getClass().getSimpleName() + " in " + element.getContainingFile().getName() + "@" + startOffset + ":" + endOffset + (info.isDynamicUsage() ? " (dynamic usage)" : "") + (info.isNonCodeUsage() ? " (non-code usage)" : "");
    });
    assertSameElements(actualResult, expected);
}
Also used : ProperTextRange(com.intellij.openapi.util.ProperTextRange) PsiElement(com.intellij.psi.PsiElement)

Example 19 with ProperTextRange

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

the class WholeFileLocalInspectionsPassFactory method createHighlightingPass.

@Override
@Nullable
public TextEditorHighlightingPass createHighlightingPass(@NotNull final PsiFile file, @NotNull final Editor editor) {
    final Long appliedModificationCount = myPsiModificationCount.get(file);
    if (appliedModificationCount != null && appliedModificationCount == PsiManager.getInstance(myProject).getModificationTracker().getModificationCount()) {
        //optimization
        return null;
    }
    if (!ProblemHighlightFilter.shouldHighlightFile(file)) {
        return null;
    }
    if (myFileToolsCache.containsKey(file) && !myFileToolsCache.get(file)) {
        return null;
    }
    ProperTextRange visibleRange = VisibleHighlightingPassFactory.calculateVisibleRange(editor);
    return new LocalInspectionsPass(file, editor.getDocument(), 0, file.getTextLength(), visibleRange, true, new DefaultHighlightInfoProcessor()) {

        @NotNull
        @Override
        List<LocalInspectionToolWrapper> getInspectionTools(@NotNull InspectionProfileWrapper profile) {
            List<LocalInspectionToolWrapper> tools = super.getInspectionTools(profile);
            List<LocalInspectionToolWrapper> result = tools.stream().filter(LocalInspectionToolWrapper::runForWholeFile).collect(Collectors.toList());
            myFileToolsCache.put(file, !result.isEmpty());
            return result;
        }

        @Override
        protected String getPresentableName() {
            return DaemonBundle.message("pass.whole.inspections");
        }

        @Override
        void inspectInjectedPsi(@NotNull List<PsiElement> elements, boolean onTheFly, @NotNull ProgressIndicator indicator, @NotNull InspectionManager iManager, boolean inVisibleRange, @NotNull List<LocalInspectionToolWrapper> wrappers) {
        // already inspected in LIP
        }

        @Override
        protected void applyInformationWithProgress() {
            super.applyInformationWithProgress();
            myPsiModificationCount.put(file, PsiManager.getInstance(myProject).getModificationTracker().getModificationCount());
        }
    };
}
Also used : InspectionProfileWrapper(com.intellij.codeInspection.ex.InspectionProfileWrapper) InspectionManager(com.intellij.codeInspection.InspectionManager) ProperTextRange(com.intellij.openapi.util.ProperTextRange) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) NotNull(org.jetbrains.annotations.NotNull) LocalInspectionToolWrapper(com.intellij.codeInspection.ex.LocalInspectionToolWrapper) Nullable(org.jetbrains.annotations.Nullable)

Example 20 with ProperTextRange

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

the class MyTestInjector method textRangeToInject.

public static TextRange textRangeToInject(PsiLanguageInjectionHost host) {
    ASTNode[] children = host.getNode().getChildren(null);
    TextRange insideQuotes = new ProperTextRange(0, host.getTextLength());
    if (children.length > 1 && children[0].getElementType() == XmlTokenType.XML_ATTRIBUTE_VALUE_START_DELIMITER) {
        insideQuotes = new ProperTextRange(children[1].getTextRange().getStartOffset() - host.getTextRange().getStartOffset(), insideQuotes.getEndOffset());
    }
    if (children.length > 1 && children[children.length - 1].getElementType() == XmlTokenType.XML_ATTRIBUTE_VALUE_END_DELIMITER) {
        insideQuotes = new ProperTextRange(insideQuotes.getStartOffset(), children[children.length - 2].getTextRange().getEndOffset() - host.getTextRange().getStartOffset());
    }
    if (host instanceof PsiLiteralExpression) {
        insideQuotes = new ProperTextRange(1, host.getTextLength() - 1);
    }
    return insideQuotes;
}
Also used : ProperTextRange(com.intellij.openapi.util.ProperTextRange) ASTNode(com.intellij.lang.ASTNode) ProperTextRange(com.intellij.openapi.util.ProperTextRange) TextRange(com.intellij.openapi.util.TextRange)

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