static @Nullable ProperTextRange getChangedPsiRange(@NotNull PsiFile file,
                                                      @NotNull Document document,
                                                      @NotNull CharSequence oldDocumentText,
                                                      @NotNull CharSequence newDocumentText) {
    int psiLength = oldDocumentText.length();
    if (!file.getViewProvider().supportsIncrementalReparse(file.getLanguage())) {
      return new ProperTextRange(0, psiLength);
    }
    List<DocumentEvent> events = ((PsiDocumentManagerBase)PsiDocumentManager.getInstance(file.getProject())).getEventsSinceCommit(
      document);
    int prefix = Integer.MAX_VALUE;
    int suffix = Integer.MAX_VALUE;
    int lengthBeforeEvent = psiLength;
    for (DocumentEvent event : events) {
      prefix = Math.min(prefix, event.getOffset());
      suffix = Math.min(suffix, lengthBeforeEvent - event.getOffset() - event.getOldLength());
      lengthBeforeEvent = lengthBeforeEvent - event.getOldLength() + event.getNewLength();
    }
    if ((prefix == psiLength || suffix == psiLength) && newDocumentText.length() == psiLength) {
      return null;
    }
    //Important! delete+insert sequence can give some of same chars back, lets grow affixes to include them.
    int shortestLength = Math.min(psiLength, newDocumentText.length());
    while (prefix < shortestLength &&
           oldDocumentText.charAt(prefix) == newDocumentText.charAt(prefix)) {
      prefix++;
    }
    while (suffix < shortestLength - prefix &&
           oldDocumentText.charAt(psiLength - suffix - 1) == newDocumentText.charAt(newDocumentText.length() - suffix - 1)) {
      suffix++;
    }
    int end = Math.max(prefix, psiLength - suffix);
    if (end == prefix && newDocumentText.length() == oldDocumentText.length()) return null;
    return ProperTextRange.create(prefix, end);
  }
static @Nullable ProperTextRange getChangedPsiRange(@NotNull PsiFile file,
                                                      @NotNull Document document,
                                                      @NotNull CharSequence oldDocumentText,
                                                      @NotNull CharSequence newDocumentText)