addons/isl/src/firstPassCodeReview/firstPassCodeReviewAtoms.tsblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318import {atom} from 'jotai';
b69ab319import {writeAtom} from '../jotaiUtils';
b69ab3110import platform from '../platform';
b69ab3111import {registerDisposable} from '../utils';
b69ab3112import type {CodeReviewIssue, CodeReviewProgressStatus} from './types';
b69ab3113
b69ab3114/**
b69ab3115 * Atom that stores the current status of the AI code review.
b69ab3116 */
b69ab3117export const codeReviewStatusAtom = atom<CodeReviewProgressStatus | null>(null);
b69ab3118
b69ab3119/**
b69ab3120 * Atom that stores comments for the current review.
b69ab3121 */
b69ab3122export const firstPassCommentData = atom<CodeReviewIssue[]>([]);
b69ab3123
b69ab3124export const firstPassCommentDataCount = atom(get => get(firstPassCommentData).length);
b69ab3125
b69ab3126export const firstPassCommentError = atom<Error | undefined>(undefined);
b69ab3127
b69ab3128/**
b69ab3129 * Derived atom that maps comments by file path.
b69ab3130 * The resulting object has file paths as keys and arrays of CodeReviewIssue as values.
b69ab3131 */
b69ab3132export const commentsByFilePathAtom = atom(get => {
b69ab3133 const comments = get(firstPassCommentData);
b69ab3134 return comments.reduce<Record<string, CodeReviewIssue[]>>((acc, comment) => {
b69ab3135 if (!acc[comment.filepath]) {
b69ab3136 acc[comment.filepath] = [];
b69ab3137 }
b69ab3138 acc[comment.filepath].push(comment);
b69ab3139 return acc;
b69ab3140 }, {});
b69ab3141});
b69ab3142
b69ab3143registerDisposable(
b69ab3144 firstPassCommentData,
b69ab3145 platform.aiCodeReview?.onDidChangeAIReviewComments(comments => {
b69ab3146 writeAtom(firstPassCommentData, comments);
b69ab3147 }) ?? {dispose: () => {}},
b69ab3148 import.meta.hot,
b69ab3149);