Java Code Examples for com.intellij.openapi.editor.markup.RangeHighlighter#getEndOffset()

The following examples show how to use com.intellij.openapi.editor.markup.RangeHighlighter#getEndOffset() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LSPLocalInspectionTool.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
    VirtualFile virtualFile = file.getVirtualFile();
    if (virtualFile != null) {
        Editor editor = LSPIJUtils.editorForFile(virtualFile);
        if (editor != null) {
            List<ProblemDescriptor> problemDescriptors = new ArrayList<>();
            try {
                for(LanguageServerWrapper wrapper : LanguageServiceAccessor.getInstance(file.getProject()).getLSWrappers(virtualFile, capabilities -> true)) {
                    RangeHighlighter[] highlighters = LSPDiagnosticsToMarkers.getMarkers(editor, wrapper.serverDefinition.id);
                    if (highlighters != null) {
                        for(RangeHighlighter highlighter : highlighters) {
                            PsiElement element = new LSPPSiElement(editor.getProject(), file, highlighter.getStartOffset(), highlighter.getEndOffset(), editor.getDocument().getText(new TextRange(highlighter.getStartOffset(), highlighter.getEndOffset())));
                            ProblemHighlightType highlightType = getHighlighType(((Diagnostic)highlighter.getErrorStripeTooltip()).getSeverity());
                            problemDescriptors.add(manager.createProblemDescriptor(element, ((Diagnostic)highlighter.getErrorStripeTooltip()).getMessage(), true, highlightType, isOnTheFly));
                        }
                    }
                }
            } catch (IOException e) {
                LOGGER.warn(e.getLocalizedMessage(), e);
            }
            return problemDescriptors.toArray(new ProblemDescriptor[problemDescriptors.size()]);
        }

    }
    return super.checkFile(file, manager, isOnTheFly);
}
 
Example 2
Source File: AnnotationRange.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new <code>AnnotationRange</code> with the given position. If there is currently no
 * local representation for the <code>AnnotationRange</code>, <code>null</code> should be passe as
 * the <code>RangeHighlighter</code>.
 *
 * <p>Both the given start and end point have to be positive integers. Furthermore, the start
 * position has to be smaller as or equal to the end position. If a <code>RangeHighlighter</code>
 * is given, it must match the given start and end position.
 *
 * @param start the start point of the annotation range
 * @param end the end point of the annotation range
 * @param rangeHighlighter the representation of the annotated text in a local editor
 */
AnnotationRange(int start, int end, @Nullable RangeHighlighter rangeHighlighter) {

  if (start < 0 || end < 0) {
    throw new IllegalArgumentException(
        "The start and end of the annotation must not be negative "
            + "values. start: "
            + start
            + ", end: "
            + end);
  }

  if (start > end) {
    throw new IllegalArgumentException(
        "The start of the annotation must not be after the end of the "
            + "annotation. start: "
            + start
            + ", end: "
            + end);
  }

  if (rangeHighlighter != null) {
    if (!rangeHighlighter.isValid()) {
      throw new IllegalArgumentException(
          "The given RangeHighlighter for the range (" + start + "," + end + ") is invalid");

    } else if (start != rangeHighlighter.getStartOffset()
        || end != rangeHighlighter.getEndOffset()) {

      throw new IllegalArgumentException(
          "The range of the given RangeHighlighter does not match the given start and end value");
    }
  }

  this.start = start;
  this.end = end;
  this.rangeHighlighter = rangeHighlighter;
}
 
Example 3
Source File: AnnotationRange.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds a local representation to this <code>AnnotationRange</code>. The given <code>
 * RangeHighlighter</code> must match the held start and end position.
 *
 * @param rangeHighlighter the RangeHighlighter for the annotation range
 */
void addRangeHighlighter(@NotNull RangeHighlighter rangeHighlighter) {

  if (start != rangeHighlighter.getStartOffset() || end != rangeHighlighter.getEndOffset()) {

    throw new IllegalArgumentException(
        "The range of the RangeHighlighter does not match the given " + "start and end value");
  }

  this.rangeHighlighter = rangeHighlighter;
}
 
Example 4
Source File: MyActionUtils.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NotNull
	public static List<RangeHighlighter> getRangeHighlightersAtOffset(Editor editor, int offset) {
		MarkupModel markupModel = editor.getMarkupModel();
		// collect all highlighters and combine to make a single tool tip
		List<RangeHighlighter> highlightersAtOffset = new ArrayList<RangeHighlighter>();
		for (RangeHighlighter r : markupModel.getAllHighlighters()) {
			int a = r.getStartOffset();
			int b = r.getEndOffset();
//			System.out.printf("#%d: %d..%d %s\n", i, a, b, r.toString());
			if (offset >= a && offset < b) { // cursor is over some kind of highlighting
				highlightersAtOffset.add(r);
			}
		}
		return highlightersAtOffset;
	}
 
Example 5
Source File: LivePreview.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void updateInSelectionHighlighters() {
  final SelectionModel selectionModel = mySearchResults.getEditor().getSelectionModel();
  int[] starts = selectionModel.getBlockSelectionStarts();
  int[] ends = selectionModel.getBlockSelectionEnds();

  for (RangeHighlighter highlighter : myHighlighters) {
    if (!highlighter.isValid()) continue;
    boolean needsAdditionalHighlighting = false;
    TextRange cursor = mySearchResults.getCursor();
    if (cursor == null || highlighter.getStartOffset() != cursor.getStartOffset() || highlighter.getEndOffset() != cursor.getEndOffset()) {
      for (int i = 0; i < starts.length; ++i) {
        TextRange selectionRange = new TextRange(starts[i], ends[i]);
        needsAdditionalHighlighting = selectionRange.intersects(highlighter.getStartOffset(), highlighter.getEndOffset()) &&
                                      selectionRange.getEndOffset() != highlighter.getStartOffset() &&
                                      highlighter.getEndOffset() != selectionRange.getStartOffset();
        if (needsAdditionalHighlighting) break;
      }
    }

    RangeHighlighter inSelectionHighlighter = highlighter.getUserData(IN_SELECTION_KEY);
    if (inSelectionHighlighter != null) {
      if (!needsAdditionalHighlighting) {
        removeHighlighter(inSelectionHighlighter);
      }
    }
    else if (needsAdditionalHighlighting) {
      RangeHighlighter additionalHighlighter = addHighlighter(highlighter.getStartOffset(), highlighter.getEndOffset(), new TextAttributes(null, null, Color.WHITE, EffectType.ROUNDED_BOX, Font.PLAIN));
      highlighter.putUserData(IN_SELECTION_KEY, additionalHighlighter);
    }
  }
}
 
Example 6
Source File: HighlightCommand.java    From CppTools with Apache License 2.0 5 votes vote down vote up
private static RangeHighlighter processHighlighter(int hFrom, int hTo, int colorIndex, TextAttributes attrs,
                                                   Editor editor, TIntObjectHashMap<RangeHighlighter> lastOffsetToMarkersMap,
                                                   THashSet<RangeHighlighter> highlightersSet,
                                                   THashSet<RangeHighlighter> invalidMarkersSet
                                                   ) {
  RangeHighlighter rangeHighlighter = lastOffsetToMarkersMap.get(hFrom);

  if (rangeHighlighter == null ||
      rangeHighlighter.getEndOffset() != hTo ||
      rangeHighlighter.getTextAttributes() != attrs
      ) {
    highlightersSet.add(
      rangeHighlighter = HighlightUtils.createRangeMarker(
        editor,
        hFrom,
        hTo,
        colorIndex,
        attrs
      )
    );

    lastOffsetToMarkersMap.put(hFrom, rangeHighlighter);
  } else {
    highlightersSet.add(rangeHighlighter);
    invalidMarkersSet.remove(rangeHighlighter);
  }

  return rangeHighlighter;
}
 
Example 7
Source File: FilteredIndentsHighlightingPass.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static int compare(@NotNull TextRange r, @NotNull RangeHighlighter h) {
  int answer = r.getStartOffset() - h.getStartOffset();
  return answer != 0 ? answer : r.getEndOffset() - h.getEndOffset();
}
 
Example 8
Source File: FilteredIndentsHighlightingPass.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static int compare(@NotNull TextRange r, @NotNull RangeHighlighter h) {
  int answer = r.getStartOffset() - h.getStartOffset();
  return answer != 0 ? answer : r.getEndOffset() - h.getEndOffset();
}
 
Example 9
Source File: FoldingUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean isHighlighterFolded(@Nonnull Editor editor, @Nonnull RangeHighlighter highlighter) {
  int startOffset = highlighter instanceof RangeHighlighterEx ? ((RangeHighlighterEx)highlighter).getAffectedAreaStartOffset() : highlighter.getStartOffset();
  int endOffset = highlighter instanceof RangeHighlighterEx ? ((RangeHighlighterEx)highlighter).getAffectedAreaEndOffset() : highlighter.getEndOffset();
  return isTextRangeFolded(editor, new TextRange(startOffset, endOffset));
}
 
Example 10
Source File: IndentsPass.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static int compare(@Nonnull TextRange r, @Nonnull RangeHighlighter h) {
  int answer = r.getStartOffset() - h.getStartOffset();
  return answer != 0 ? answer : r.getEndOffset() - h.getEndOffset();
}