All files / src/issue-reporting/commands report-issue-command.ts

0% Statements 0/40
100% Branches 1/1
100% Functions 1/1
0% Lines 0/40

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88                                                                                                                                                                               
/**
 * Report Issue Command - VS Code command registration
 *
 * Handles the "Report Issue" command that opens the issue reporting modal.
 */
 
import * as vscode from "vscode";
import { ExtensionCommands } from "../../extension-commands";
import { IssueReportModal } from "../ui/report-modal";
import { Logger } from "../../logger";
 
/**
 * Data passed to the report issue command
 */
export interface ReportIssueCommandData {
    /** Job ID for the highlight */
    jobId: number;
    /** File path where the highlight is located */
    filePath: string;
    /** Line number (1-indexed) */
    codeLine: number;
    /** SQL query IDs */
    sqlIds: number[];
    /** Node IDs */
    nodeIds: number[];
    /** Display text from the highlight */
    displayText?: string;
    /** Whether this is a performance hotspot */
    isHotspot: boolean;
    /** Severity of the highlight */
    severity?: string;
    /** Query prefix (e.g., "🔵Q3") */
    queryPrefix?: string;
    /** Number of alerts */
    alertCount: number;
    /** Number of findings */
    findingCount: number;
}
 
/**
 * Register issue reporting commands
 *
 * @param context - VS Code extension context
 * @param getDataflintService - Function to get the DataFlint service instance
 */
export function registerIssueReportingCommands(
    context: vscode.ExtensionContext,
    getDataflintService: () => any // Using any to avoid circular dependency
): void {
    const logger = Logger.getInstance();
 
    // Register the report issue command
    const reportIssueCommand = vscode.commands.registerCommand(
        ExtensionCommands.REPORT_HIGHLIGHT_ISSUE,
        async (data: ReportIssueCommandData) => {
            logger.info(
                `Report issue command triggered for job ${data.jobId}, line ${data.codeLine}`
            );
 
            try {
                const dataflintService = getDataflintService();
                if (!dataflintService) {
                    vscode.window.showErrorMessage(
                        "DataFlint service not available. Please login first."
                    );
                    return;
                }
 
                // Create and show the report modal
                const modal = new IssueReportModal(
                    context,
                    dataflintService,
                    data
                );
                await modal.show();
            } catch (error) {
                logger.error("Failed to open issue report modal:", error);
                vscode.window.showErrorMessage(
                    `Failed to open issue report: ${error instanceof Error ? error.message : "Unknown error"}`
                );
            }
        }
    );
 
    context.subscriptions.push(reportIssueCommand);
    logger.info("Issue reporting commands registered");
}