Skip to content

Commit 0068492

Browse files
committed
feat: add 'ignore for this file' in notifications
1 parent dcf9458 commit 0068492

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

src/config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,16 @@ class Config {
206206
process.env['VSCEXT_TRUSTIFY_DA_IMAGE_PLATFORM'] = this.exhortImagePlatform;
207207
}
208208

209+
/**
210+
* Adds a path to the workspace-local redHatDependencyAnalytics.exclude list.
211+
* @param path The path to add
212+
*/
213+
async addFileToExcludeList(path: string) {
214+
const original = vscode.workspace.getConfiguration('redHatDependencyAnalytics').inspect('exclude');
215+
const newValues = [...((original?.workspaceValue as string[] | undefined) || []), path];
216+
await vscode.workspace.getConfiguration('redHatDependencyAnalytics').update('exclude', newValues);
217+
}
218+
209219
/**
210220
* Authorizes the RHDA (Red Hat Dependency Analytics) service.
211221
* @param context The extension context for authorization.

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export enum StatusMessages {
2121
export enum PromptText {
2222
FULL_STACK_PROMPT_TEXT = `Open Red Hat Dependency Analytics Report`,
2323
LSP_FAILURE_TEXT = `Open the output window`,
24+
IGNORE_FILE = 'Ignore this file',
2425
}
2526

2627
export enum Titles {

src/extension.ts

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { LLMAnalysisReportPanel } from './llmAnalysisReportPanel';
2121
// eslint-disable-next-line @typescript-eslint/no-require-imports
2222
import CliTable3 = require('cli-table3');
2323
import { Language, Parser, Query } from 'web-tree-sitter';
24+
import { AbstractDiagnosticsPipeline } from './diagnosticsPipeline';
2425

2526
export let outputChannelDep: DepOutputChannel;
2627

@@ -311,10 +312,16 @@ export async function activate(context: vscode.ExtensionContext) {
311312

312313
const showVulnerabilityFoundPrompt = async (msg: string, filePath: vscode.Uri) => {
313314
const fileName = path.basename(filePath.fsPath);
314-
const selection = await vscode.window.showWarningMessage(`${msg}`, PromptText.FULL_STACK_PROMPT_TEXT);
315+
const selection = await vscode.window.showWarningMessage(`${msg}`, PromptText.FULL_STACK_PROMPT_TEXT as string, PromptText.IGNORE_FILE);
315316
if (selection === PromptText.FULL_STACK_PROMPT_TEXT) {
316317
record(context, TelemetryActions.vulnerabilityReportPopupOpened, { manifest: fileName, fileName: fileName });
317318
vscode.commands.executeCommand(commands.STACK_ANALYSIS_COMMAND, filePath.fsPath);
319+
} else if (selection === PromptText.IGNORE_FILE) {
320+
outputChannelDep.info(`Added "${filePath.fsPath}" to workspace exclude list`);
321+
await globalConfig.addFileToExcludeList(filePath.fsPath);
322+
AbstractDiagnosticsPipeline.diagnosticsCollection.delete(filePath);
323+
clearCodeActionsMap(filePath);
324+
// TODO: need to clear status bar
318325
} else {
319326
record(context, TelemetryActions.vulnerabilityReportPopupIgnored, { manifest: fileName, fileName: fileName });
320327
}
@@ -334,12 +341,19 @@ export async function activate(context: vscode.ExtensionContext) {
334341
}
335342
});
336343

337-
notifications.on('caError', (errorData: CANotificationData) => {
344+
notifications.on('caError', async (errorData: CANotificationData) => {
338345
const notification = new CANotification(errorData);
339346
caStatusBarProvider.setError();
340347

341348
// Since CA is an automated feature, only warning message will be shown on failure
342-
vscode.window.showWarningMessage(`RHDA error while analyzing ${errorData.uri.fsPath}: ${notification.errorMsg()}`);
349+
const selection = await vscode.window.showWarningMessage(`RHDA error while analyzing ${errorData.uri.fsPath}: ${notification.errorMsg()}`, PromptText.IGNORE_FILE);
350+
if (selection === PromptText.IGNORE_FILE) {
351+
outputChannelDep.info(`Added "${errorData.uri.fsPath}" to workspace exclude list`);
352+
await globalConfig.addFileToExcludeList(errorData.uri.fsPath);
353+
AbstractDiagnosticsPipeline.diagnosticsCollection.delete(errorData.uri);
354+
clearCodeActionsMap(errorData.uri);
355+
// TODO: need to clear status bar
356+
}
343357

344358
// Record telemetry event
345359
record(context, TelemetryActions.componentAnalysisFailed, { manifest: path.basename(notification.origin().fsPath), fileName: path.basename(notification.origin().fsPath), error: notification.errorMsg() });
@@ -362,6 +376,7 @@ export async function activate(context: vscode.ExtensionContext) {
362376

363377
vscode.workspace.onDidChangeConfiguration(() => {
364378
globalConfig.loadData();
379+
outputChannelDep.debug(`configuration updated`);
365380
});
366381
}
367382

@@ -424,8 +439,11 @@ function showRHRepositoryRecommendationNotification() {
424439
* @param context - The extension context.
425440
*/
426441
function registerStackAnalysisCommands(context: vscode.ExtensionContext) {
427-
428-
const invokeFullStackReport = async (filePath: string) => {
442+
const recordAndInvoke = async (origin: string, uri: vscode.Uri) => {
443+
// TODO: vscode.window.activeTextEditor may be null
444+
const fileUri = uri || vscode.window.activeTextEditor!.document.uri;
445+
const filePath = fileUri.fsPath;
446+
record(context, origin, { manifest: path.basename(filePath), fileName: path.basename(filePath) });
429447
const fileName = path.basename(filePath);
430448
try {
431449
const metrics = await generateRHDAReport(context, filePath, outputChannelDep);
@@ -443,14 +461,6 @@ function registerStackAnalysisCommands(context: vscode.ExtensionContext) {
443461
}
444462
};
445463

446-
const recordAndInvoke = (origin: string, uri: vscode.Uri) => {
447-
// TODO: vscode.window.activeTextEditor may be null
448-
const fileUri = uri || vscode.window.activeTextEditor!.document.uri;
449-
const filePath = fileUri.fsPath;
450-
record(context, origin, { manifest: path.basename(filePath), fileName: path.basename(filePath) });
451-
invokeFullStackReport(filePath);
452-
};
453-
454464
const registerCommand = (cmd: string, action: TelemetryActions) => {
455465
return vscode.commands.registerCommand(cmd, recordAndInvoke.bind(null, action));
456466
};

0 commit comments

Comments
 (0)