int (@NotNull PyArgumentList argumentList, int allegedCursorOffset, PsiFile file) { CharSequence chars = file.getViewProvider().getContents(); // align offset to nearest expression; context may point to a space, etc. final List<PyExpression> flattenedArguments = PyUtil.flattenedParensAndLists(argumentList.getArguments()); int offset = -1; for (PyExpression argument : flattenedArguments) { final TextRange range = argument.getTextRange(); // widen the range to include all whitespace around the argument final int left = CharArrayUtil.shiftBackward(chars, range.getStartOffset() - 1, " \t\r\n"); int right = CharArrayUtil.shiftForwardCarefully(chars, range.getEndOffset(), " \t\r\n"); if (argument.getParent() instanceof PyListLiteralExpression || argument.getParent() instanceof PyTupleExpression) { right = CharArrayUtil.shiftForward(chars, range.getEndOffset(), " \t\r\n])"); } if (left <= allegedCursorOffset && right >= allegedCursorOffset) { offset = range.getStartOffset(); break; } } return offset; }