private PsiReferenceExpression[] surroundWithCodeBlock(PsiReferenceExpression[] refs) throws IncorrectOperationException {
    mySurroundResults = new ArrayList<>();

    for (PsiReferenceExpression ref : refs) {
      if (ref instanceof PsiMethodReferenceExpression) continue;
      ref.putCopyableUserData(MARK_KEY, ref);
    }
    var visitor = new PsiRecursiveElementWalkingVisitor() {
      final Map<PsiReferenceExpression, PsiReferenceExpression> mapping = new HashMap<>();

      @Override
      public void visitElement(@NotNull PsiElement element) {
        if (element instanceof PsiReferenceExpression) {
          PsiReferenceExpression orig = element.getCopyableUserData(MARK_KEY);
          if (orig != null) {
            mapping.put(orig, (PsiReferenceExpression)element);
          }
        }
        super.visitElement(element);
      }
    };

    for (PsiReferenceExpression ref : refs) {
      if (!ref.isValid() || ref instanceof PsiMethodReferenceExpression) continue;

      CodeBlockSurrounder surrounder = CodeBlockSurrounder.forExpression(ref);
      if (surrounder != null) {
        CodeBlockSurrounder.SurroundResult surround = surrounder.surround();
        surround.getAnchor().accept(visitor);
        mySurroundResults.add(surround);
      }
    }

    return StreamEx.of(refs).map(ref -> visitor.mapping.getOrDefault(ref, ref))
      .peek(ref -> ref.putCopyableUserData(MARK_KEY, null))
      .toArray(new PsiReferenceExpression[0]);
  }
private PsiReferenceExpression[] surroundWithCodeBlock(PsiReferenceExpression[] refs)