@Contract(pure = true)
  public static @NotNull Comparator<RangeHighlighterEx> createByLayerThenByAttributesComparator(@NotNull EditorColorsScheme scheme) {
    return (o1, o2) -> {
      int result = LayerComparator.HIGHER_FIRST.compare(o1, o2);
      if (result != 0) {
        return result;
      }

      // There is a possible case when more than one highlighter target the same region (e.g. 'identifier under caret' and 'identifier').
      // We want to prefer the one that defines foreground color to the one that doesn't define (has either fore- or background colors
      // while the other one has only foreground color). See IDEA-85697 for concrete example.
      TextAttributes a1 = o1.getTextAttributes(scheme);
      TextAttributes a2 = o2.getTextAttributes(scheme);
      if (a1 == null ^ a2 == null) {
        return a1 == null ? 1 : -1;
      }

      if (a1 != null) {
        Color fore1 = a1.getForegroundColor();
        Color fore2 = a2.getForegroundColor();
        if (fore1 == null ^ fore2 == null) {
          return fore1 == null ? 1 : -1;
        }

        Color back1 = a1.getBackgroundColor();
        Color back2 = a2.getBackgroundColor();
        if (back1 == null ^ back2 == null) {
          return back1 == null ? 1 : -1;
        }
      }
      return compareByHighlightInfoSeverity(o1, o2);
    };
  }
@Contract(pure = true)
  public static @NotNull Comparator<RangeHighlighterEx> createByLayerThenByAttributesComparator(@NotNull EditorColorsScheme scheme)