Skip to content

Commit 5eb6591

Browse files
NEW: @W-19335794@: Warn if users select multiple files to scan with ApexGuru (#272)
Co-authored-by: Juliet Shackell <[email protected]>
1 parent b4c0d81 commit 5eb6591

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@
214214
},
215215
{
216216
"command": "sfca.runApexGuruAnalysisOnSelectedFile",
217-
"when": "sfca.extensionActivated && sfca.apexGuruEnabled && resourceExtname =~ /\\.cls|\\.trigger|\\.apex/"
217+
"when": "sfca.extensionActivated && sfca.apexGuruEnabled && explorerResourceIsFolder == false && resourceExtname =~ /\\.cls|\\.trigger|\\.apex/"
218218
}
219219
]
220220
},

src/extension.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,13 @@ export async function activate(context: vscode.ExtensionContext): Promise<SFCAEx
256256
await apexGuruService.isApexGuruAvailable();
257257
await establishVariableInContext(Constants.CONTEXT_VAR_APEX_GURU_ENABLED, isApexGuruEnabled);
258258

259-
// COMMAND_RUN_APEX_GURU_ON_FILE: Invokable by 'explorer/context' menu only when: "sfca.apexGuruEnabled && resourceExtname =~ /\\.cls|\\.trigger|\\.apex/"
260-
registerCommand(Constants.COMMAND_RUN_APEX_GURU_ON_FILE, async (selection: vscode.Uri, multiSelect?: vscode.Uri[]) =>
261-
await apexGuruRunAction.run(Constants.COMMAND_RUN_APEX_GURU_ON_FILE,
262-
multiSelect && multiSelect.length > 0 ? multiSelect[0] : selection)); // TODO: We should somehow restrict multi-select here. We only use the first file right now
259+
// COMMAND_RUN_APEX_GURU_ON_FILE: Invokable by 'explorer/context' menu only when: "sfca.apexGuruEnabled && explorerResourceIsFolder == false && resourceExtname =~ /\\.cls|\\.trigger|\\.apex/"
260+
registerCommand(Constants.COMMAND_RUN_APEX_GURU_ON_FILE, async (selection: vscode.Uri, multiSelect?: vscode.Uri[]) => {
261+
if (multiSelect?.length > 1) {
262+
display.displayWarning(messages.apexGuru.warnings.canOnlyScanOneFile(selection.fsPath));
263+
}
264+
await apexGuruRunAction.run(Constants.COMMAND_RUN_APEX_GURU_ON_FILE, selection);
265+
});
263266

264267
// COMMAND_RUN_APEX_GURU_ON_ACTIVE_FILE: Invokable by 'commandPalette' and 'editor/context' menus only when: "sfca.apexGuruEnabled && resourceExtname =~ /\\.cls|\\.trigger|\\.apex/"
265268
registerCommand(Constants.COMMAND_RUN_APEX_GURU_ON_ACTIVE_FILE, async () => {

src/lib/messages.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ export const messages = {
2424
apexGuru: {
2525
runningAnalysis: "Code Analyzer is running ApexGuru analysis.",
2626
finishedScan: (violationCount: number) => `Scan complete. ${violationCount} violations found.`,
27+
warnings: {
28+
canOnlyScanOneFile: (file: string) =>
29+
`ApexGuru can scan only one file at a time. Ignoring the other files in your multi-selection and scanning only this file: ${file}.`
30+
},
2731
errors: {
2832
unableToAnalyzeFile: 'ApexGuru was unable to analyze the file.',
2933
returnedUnexpectedResponse: (responseStr: string) =>

0 commit comments

Comments
 (0)