Skip to content

Commit 44c88c6

Browse files
Merge pull request #17 from Corgea/COR-990
COR-990: VS Code Scanning Improvement
2 parents 6ac98ab + b5fcf59 commit 44c88c6

4 files changed

Lines changed: 27 additions & 18 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "Corgea",
44
"publisher": "Corgea",
55
"description": "Corgea helps you automatically fix insecure code.",
6-
"version": "1.5.0",
6+
"version": "1.5.1",
77
"icon": "images/logo.png",
88
"license": "UNLICENSED",
99
"repository": {

src/services/scanningService.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export interface ScanState {
3737
scanId?: string;
3838
output: string[];
3939
error?: string;
40+
lastScanType?: 'full' | 'uncommitted';
4041
}
4142

4243
export default class scanningService {
@@ -66,7 +67,7 @@ export default class scanningService {
6667
return;
6768
}
6869

69-
await scanningService.scanProject(false);
70+
await scanningService.scanProject(false, 'uncommitted');
7071
}
7172

7273
public static async getUncommittedFiles(includeIgnored: boolean = false): Promise<any[]> {
@@ -95,7 +96,7 @@ export default class scanningService {
9596
*/
9697
@OnCommand("corgea.scan-full")
9798
@withErrorHandling()
98-
public static async scanProject(isFullScan: boolean = true) {
99+
public static async scanProject(isFullScan: boolean = true, scanType: 'full' | 'uncommitted' = 'full') {
99100
// Check if IDE scanning is enabled
100101
const isIdeScanningEnabled = await ConfigService.isIdeScanningEnabled();
101102
if (!isIdeScanningEnabled) {
@@ -121,6 +122,7 @@ export default class scanningService {
121122
scan: false
122123
},
123124
output: [],
125+
lastScanType: scanType,
124126
};
125127

126128
// Notify webview that scan started

src/views/components/ScanningError/ScanningError.tsx

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@ interface ScanningErrorProps {
88

99
const ScanningError: React.FC<ScanningErrorProps> = ({ isCancelled = false }) => {
1010
const { state, actions } = useVulnerabilities();
11-
11+
const actionsButtons = (<div className="error-actions">
12+
<button className="btn btn-primary mt-3" onClick={actions.retryLastScan}>
13+
<i className="fas fa-play"></i>
14+
Try Again
15+
</button>
16+
<button className="btn btn-secondary mt-3 ml-2" onClick={actions.clearScanState}>
17+
<i className="fas fa-times"></i>
18+
Clear
19+
</button>
20+
</div>);
1221
if (isCancelled) {
1322
return (
1423
<div className="scanning-error">
1524
<div className="error-icon">
1625
<i className="fas fa-times-circle" style={{ color: '#ff9500' }}></i>
1726
</div>
1827
<div className="error-message">Scan was cancelled</div>
19-
<div className="error-actions">
20-
<button className="btn btn-primary mt-3" onClick={actions.scanProject}>
21-
<i className="fas fa-play"></i>
22-
&nbsp;Start New Scan
23-
</button>
24-
<button className="btn btn-secondary mt-3 ml-2" onClick={actions.clearScanState}>
25-
<i className="fas fa-times"></i>
26-
&nbsp;Clear
27-
</button>
28-
</div>
28+
{actionsButtons}
2929
</div>
3030
);
3131
}
@@ -36,10 +36,7 @@ const ScanningError: React.FC<ScanningErrorProps> = ({ isCancelled = false }) =>
3636
<i className="fas fa-exclamation-triangle"></i>
3737
</div>
3838
<div className="error-message">{state.scanState.error}</div>
39-
<button className="btn btn-primary mt-3" onClick={actions.scanProject}>
40-
<i className="fas fa-redo"></i>
41-
&nbsp;Try Again
42-
</button>
39+
{actionsButtons}
4340
</div>
4441
);
4542
};

src/views/context/VulnerabilitiesContext.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export interface ScanState {
5151
upload: boolean;
5252
scan: boolean;
5353
};
54+
lastScanType?: 'full' | 'uncommitted';
5455
}
5556

5657
export interface FileGroup {
@@ -218,6 +219,7 @@ const VulnerabilitiesContext = createContext<{
218219
showUncommittedFilesModal: () => void;
219220
hideUncommittedFilesModal: () => void;
220221
clearScanState: () => void;
222+
retryLastScan: () => void;
221223
};
222224
} | undefined>(undefined);
223225

@@ -309,6 +311,14 @@ export function VulnerabilitiesProvider({ children }: { children: ReactNode }) {
309311
},
310312
clearScanState: () => {
311313
vscode.postMessage({ type: 'clearScanState' });
314+
},
315+
retryLastScan: () => {
316+
const lastScanType = state.scanState.lastScanType;
317+
if (lastScanType === 'uncommitted') {
318+
vscode.postMessage({ type: 'scanUncommittedFiles' });
319+
} else {
320+
vscode.postMessage({ type: 'scanProject' });
321+
}
312322
}
313323
};
314324

0 commit comments

Comments
 (0)