@NotNull
    private Pair<Point, Short> getBestPointPosition(LightweightHint hint,
                                                    PsiElement list,
                                                    int offset,
                                                    VisualPosition pos,
                                                    short preferredPosition) {
      if (list != null) {
        TextRange range = list.getTextRange();
        TextRange rangeWithoutParens = TextRange.from(range.getStartOffset() + 1, Math.max(range.getLength() - 2, 0));
        if (!rangeWithoutParens.contains(offset)) {
          offset = offset < rangeWithoutParens.getStartOffset() ? rangeWithoutParens.getStartOffset() : rangeWithoutParens.getEndOffset();
          pos = null;
        }
      }

      LookupImpl activeLookup = (LookupImpl)LookupManager.getActiveLookup(myEditor);
      Rectangle lookupBounds = !ApplicationManager.getApplication().isUnitTestMode()
                               && !ApplicationManager.getApplication().isHeadlessEnvironment()
                               && activeLookup != null
                               && activeLookup.isShown()
                               ? activeLookup.getBounds()
                               : null;

      Dimension hintSize = hint.getSize();

      boolean lookupPositionChanged = lookupBounds != null && !lookupBounds.equals(previousLookupBounds);
      boolean hintSizeChanged = !hintSize.equals(previousHintSize);

      if (previousOffset == offset && !lookupPositionChanged && !hintSizeChanged) {
        return Pair.create(previousBestPoint, previousBestPosition);
      }

      Editor editor = myEditor;
      if (pos == null) {
        pos = EditorUtil.inlayAwareOffsetToVisualPosition(myEditor, offset);
        // The position above is always in the host editor. If we are in an injected
        // editor this position will likely be outside of our range and the hint position
        // will be our range's end. To avoid that and compute hint position correctly,
        // switch to the host editor.
        editor = myEditor instanceof EditorWindow ? ((EditorWindow)myEditor).getDelegate() : editor;
      }
      Pair<Point, Short> position = chooseBestHintPosition(editor, pos, hint, activeLookup, preferredPosition, false);

      previousBestPoint = position.getFirst();
      previousBestPosition = position.getSecond();
      previousOffset = offset;
      previousLookupBounds = lookupBounds;
      previousHintSize = hintSize;
      return position;
    }
@NotNull
    private Pair<Point, Short> getBestPointPosition(LightweightHint hint,
                                                    PsiElement list,
                                                    int offset,
                                                    VisualPosition pos,
                                                    short preferredPosition)