Skip to content

Commit fcee31b

Browse files
authored
Merge pull request #42 from MetabobProject/edge-case-empty-identified-problems
fix: edge case where no problem detected should be shown
2 parents 6d76640 + 197dc39 commit fcee31b

File tree

9 files changed

+74
-5
lines changed

9 files changed

+74
-5
lines changed

ext-src/events.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export interface AnalysisEvents {
1010
| 'FIX_SUGGESTION'
1111
| 'CURRENT_FILE'
1212
| 'CURRENT_PROJECT'
13-
| 'INIT_DATA_UPON_NEW_FILE_OPEN';
13+
| 'INIT_DATA_UPON_NEW_FILE_OPEN'
14+
| 'Analysis_Completed_Empty_Problems';
1415
data: any;
1516
}
1617

ext-src/helpers/HandleDocumentAnalyze.ts

+18
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,24 @@ export const handleDocumentAnalyze = async (
201201
}
202202

203203
await analyzeState.set(results);
204+
205+
if (problems.length === 0) {
206+
getExtensionEventEmitter().fire({
207+
type: 'Analysis_Completed_Empty_Problems',
208+
data: { shouldResetRecomendation: true, shouldMoveToAnalyzePage: true, ...results },
209+
});
210+
211+
getExtensionEventEmitter().fire({
212+
type: 'CURRENT_PROJECT',
213+
data: {
214+
name: currentWorkSpaceFolder
215+
},
216+
});
217+
218+
return verifiedResponse
219+
}
220+
221+
204222
getExtensionEventEmitter().fire({
205223
type: 'Analysis_Completed',
206224
data: { shouldResetRecomendation: true, shouldMoveToAnalyzePage: true, ...results },

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "metabob",
33
"displayName": "Metabob: Debug and Refactor with AI",
44
"description": "Generative AI to automate debugging and refactoring Python code",
5-
"version": "1.2.0",
5+
"version": "1.2.1",
66
"icon": "media/extension-icon.png",
77
"repository": {
88
"url": "https://github.com/MetabobProject/metabob-vscode",

src/components/Analyze/ProblemList/index.spec.tsx

+17-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ describe('ProblemList component', () => {
2626
test('renders correctly with detectedProblems', () => {
2727
const { getByText } = render(
2828
<RecoilRoot>
29-
<ProblemList detectedProblems={3} otherFileWithProblems={[]} />
29+
<ProblemList
30+
detectedProblems={3}
31+
otherFileWithProblems={[]}
32+
isEmptyIdentifiedProblemDetected={false}
33+
/>
3034
</RecoilRoot>,
3135
);
3236
expect(getByText('3 Problems Detected')).toBeInTheDocument();
@@ -36,9 +40,14 @@ describe('ProblemList component', () => {
3640
const otherFileWithProblems = [{ name: 'file1.txt' }, { name: 'file2.txt' }];
3741
const { getByText, getAllByText } = render(
3842
<RecoilRoot>
39-
<ProblemList detectedProblems={0} otherFileWithProblems={otherFileWithProblems} />
43+
<ProblemList
44+
detectedProblems={0}
45+
otherFileWithProblems={otherFileWithProblems}
46+
isEmptyIdentifiedProblemDetected={true}
47+
/>
4048
</RecoilRoot>,
4149
);
50+
expect(getByText('No Problems Detected')).toBeInTheDocument();
4251
expect(getByText('Other files with problems')).toBeInTheDocument();
4352
otherFileWithProblems.forEach(({ name }) => {
4453
expect(getAllByText(name)).toHaveLength(1); // Ensure each file name is rendered once
@@ -49,9 +58,14 @@ describe('ProblemList component', () => {
4958
const otherFileWithProblems = [{ name: 'file1.txt' }];
5059
const { getByText } = render(
5160
<RecoilRoot>
52-
<ProblemList detectedProblems={0} otherFileWithProblems={otherFileWithProblems} />
61+
<ProblemList
62+
detectedProblems={0}
63+
otherFileWithProblems={otherFileWithProblems}
64+
isEmptyIdentifiedProblemDetected={true}
65+
/>
5366
</RecoilRoot>,
5467
);
68+
expect(getByText('No Problems Detected')).toBeInTheDocument();
5569
fireEvent.click(getByText('Open'));
5670
expect(vscode.postMessage).toHaveBeenCalledWith({
5771
type: 'OPEN_FILE_IN_NEW_TAB',

src/components/Analyze/ProblemList/index.tsx

+8
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ import { useCallback } from 'react';
1414
export interface ProblemsListProps {
1515
detectedProblems?: number;
1616
otherFileWithProblems?: Array<{ name: string }>;
17+
isEmptyIdentifiedProblemDetected: boolean;
1718
}
1819

1920
export const ProblemList = ({
2021
otherFileWithProblems,
2122
detectedProblems,
23+
isEmptyIdentifiedProblemDetected,
2224
}: ProblemsListProps): JSX.Element => {
2325
const theme = useTheme();
2426

@@ -42,6 +44,12 @@ export const ProblemList = ({
4244
</Typography>
4345
)}
4446

47+
{isEmptyIdentifiedProblemDetected === true && (
48+
<Typography variant='h6' sx={ProblemListHeading(theme)}>
49+
No Problems Detected
50+
</Typography>
51+
)}
52+
4553
{otherFileWithProblems && otherFileWithProblems.length > 0 && (
4654
<>
4755
<Typography sx={ListHeaderTypography}>Other files with problems</Typography>

src/components/Analyze/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const AnalyzePage = ({
2424
const identifiedProblems = useRecoilValue(State.identifiedProblems);
2525
const currentEditor = useRecoilValue(State.currentEditor);
2626
const currentWorkSpaceProject = useRecoilValue(State.currentWorkSpaceProject);
27+
const isEmptyIdentifiedProblemDetected = useRecoilValue(State.isEmptyIdentifiedProblemDetected);
2728

2829
const otherFileWithProblems: Array<{ name: string }> | undefined = useMemo(() => {
2930
if (!identifiedProblems) return undefined;
@@ -186,6 +187,7 @@ export const AnalyzePage = ({
186187
<ProblemList
187188
detectedProblems={detectedProblems}
188189
otherFileWithProblems={otherFileWithProblems}
190+
isEmptyIdentifiedProblemDetected={isEmptyIdentifiedProblemDetected}
189191
/>
190192
)}
191193
</>

src/context/UserContext.tsx

+20
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ const AccountSettingProvider = ({ children }: Props): JSX.Element => {
2828
const setAnalysisLoading = useSetRecoilState(State.isAnalysisLoading);
2929
const setCurrentEditor = useSetRecoilState(State.currentEditor);
3030
const setCurrentWorkSpaceProject = useSetRecoilState(State.currentWorkSpaceProject);
31+
const setIsEmptyIdentifiedProblemDetected = useSetRecoilState(
32+
State.isEmptyIdentifiedProblemDetected,
33+
);
3134

3235
const handleMessagesFromExtension = useCallback(
3336
(event: MessageEvent<MessageType>) => {
@@ -51,8 +54,25 @@ const AccountSettingProvider = ({ children }: Props): JSX.Element => {
5154
case EventDataType.ANALYSIS_ERROR:
5255
setIsAnalysisLoading(false);
5356
break;
57+
case EventDataType.ANALYSIS_COMPLETED_EMPTY_PROBLEMS: {
58+
const { shouldResetRecomendation, shouldMoveToAnalyzePage, ...problem } = payload;
59+
setIsEmptyIdentifiedProblemDetected(true);
60+
if (problem) {
61+
setIdentifiedProblems(problem as AnalyzeState);
62+
}
63+
if (shouldMoveToAnalyzePage) {
64+
setIdentifiedSuggestion(undefined);
65+
setApplicationState(ApplicationWebviewState.ANALYZE_MODE);
66+
}
67+
if (shouldResetRecomendation) {
68+
setIdentifiedRecommendation(undefined);
69+
}
70+
setIsAnalysisLoading(false);
71+
break;
72+
}
5473
case EventDataType.ANALYSIS_COMPLETED:
5574
const { shouldResetRecomendation, shouldMoveToAnalyzePage, ...problem } = payload;
75+
setIsEmptyIdentifiedProblemDetected(false);
5676
if (problem) {
5777
setIdentifiedProblems(problem as AnalyzeState);
5878
}

src/state/atoms/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ export const identifiedProblems = atom<AnalyzeState | undefined>({
5454
effects_UNSTABLE: [persistAtom]
5555
});
5656

57+
export const isEmptyIdentifiedProblemDetected = atom<boolean>({
58+
default: false,
59+
key: "Metabob:isEmptyIdentifiedProblemDetected"
60+
})
61+
5762
export const currentEditor = atom<string | undefined>({
5863
default: undefined,
5964
key: 'Metabob:currentEditor',

src/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export enum EventDataType {
2424
CURRENT_FILE = 'CURRENT_FILE',
2525
CURRENT_PROJECT = 'CURRENT_PROJECT',
2626
INIT_DATA_UPON_NEW_FILE_OPEN = 'INIT_DATA_UPON_NEW_FILE_OPEN',
27+
ANALYSIS_COMPLETED_EMPTY_PROBLEMS = 'Analysis_Completed_Empty_Problems'
2728
}
2829

2930
export enum ApplicationWebviewState {

0 commit comments

Comments
 (0)