Skip to content

Commit dfa6e7d

Browse files
committed
feat: Add commands to open files for selected results and flow steps, and improve data handling in ResultItem
1 parent a8def17 commit dfa6e7d

File tree

3 files changed

+51
-75
lines changed

3 files changed

+51
-75
lines changed

src/extension.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,36 @@ export async function activate(context: vscode.ExtensionContext) {
127127
} else {
128128
vscode.window.showWarningMessage('No flow steps available for this item.');
129129
}
130+
}),
131+
vscode.commands.registerCommand('codeql-scanner.resultSelected', async (resultData, uri, options) => {
132+
try {
133+
const document = await vscode.workspace.openTextDocument(uri);
134+
const editor = await vscode.window.showTextDocument(document);
135+
136+
if (options && options.selection) {
137+
editor.selection = new vscode.Selection(options.selection.start, options.selection.end);
138+
editor.revealRange(options.selection, vscode.TextEditorRevealType.InCenter);
139+
}
140+
} catch (error) {
141+
const logger = LoggerService.getInstance();
142+
logger.error('Command', 'Failed to open file for result', error);
143+
vscode.window.showErrorMessage(`Failed to open file: ${error instanceof Error ? error.message : String(error)}`);
144+
}
145+
}),
146+
vscode.commands.registerCommand('codeql-scanner.flowStepSelected', async (flowStepData, uri, options) => {
147+
try {
148+
const document = await vscode.workspace.openTextDocument(uri);
149+
const editor = await vscode.window.showTextDocument(document);
150+
151+
if (options && options.selection) {
152+
editor.selection = new vscode.Selection(options.selection.start, options.selection.end);
153+
editor.revealRange(options.selection, vscode.TextEditorRevealType.InCenter);
154+
}
155+
} catch (error) {
156+
const logger = LoggerService.getInstance();
157+
logger.error('Command', 'Failed to open file for flow step', error);
158+
vscode.window.showErrorMessage(`Failed to open file: ${error instanceof Error ? error.message : String(error)}`);
159+
}
130160
})
131161
];
132162

src/providers/resultsProvider.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,11 +675,20 @@ export class ResultItem extends vscode.TreeItem {
675675
const logger = LoggerService.getInstance();
676676

677677
if (this.type === 'result' && this.result) {
678+
// Extract only the necessary properties instead of passing 'this'
679+
const resultData = {
680+
type: this.type,
681+
result: this.result,
682+
// Include other necessary properties but avoid circular references
683+
language: this.language,
684+
severity: this.severity
685+
};
686+
678687
return {
679688
command: 'codeql-scanner.resultSelected',
680689
title: 'Open File',
681690
arguments: [
682-
this,
691+
resultData,
683692
vscode.Uri.file(this.result.location.file),
684693
{
685694
selection: new vscode.Range(
@@ -692,11 +701,18 @@ export class ResultItem extends vscode.TreeItem {
692701
]
693702
};
694703
} else if (this.type === 'flowStep' && this.flowStep) {
704+
// Extract only the necessary properties instead of passing 'this'
705+
const flowStepData = {
706+
type: this.type,
707+
flowStep: this.flowStep,
708+
result: this.result
709+
};
710+
695711
return {
696712
command: 'codeql-scanner.flowStepSelected',
697713
title: 'Open Flow Step',
698714
arguments: [
699-
this,
715+
flowStepData,
700716
vscode.Uri.file(this.flowStep.file),
701717
{
702718
selection: new vscode.Range(

src/providers/uiProvider.ts

Lines changed: 3 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -301,78 +301,6 @@ export class UiProvider implements vscode.WebviewViewProvider {
301301
}
302302
}
303303

304-
private async autoLoadLanguagesIfNeeded() {
305-
this.logger.logServiceCall(
306-
"UiProvider",
307-
"autoLoadLanguagesIfNeeded",
308-
"started"
309-
);
310-
311-
try {
312-
// Check if languages are already configured
313-
const config = vscode.workspace.getConfiguration("codeql-scanner");
314-
const configuredLanguages = config.get<string[]>("languages", []);
315-
316-
if (configuredLanguages.length > 0) {
317-
this.logger.debug(
318-
"UiProvider",
319-
`Languages already configured: ${configuredLanguages.join(", ")}`
320-
);
321-
return;
322-
}
323-
324-
// If no CodeQL service is available, can't auto-load
325-
if (!this._codeqlService) {
326-
this.logger.debug(
327-
"UiProvider",
328-
"CodeQL service not available for auto-loading languages"
329-
);
330-
return;
331-
}
332-
333-
this.logger.info(
334-
"UiProvider",
335-
"No languages configured, attempting to auto-load supported languages"
336-
);
337-
338-
// Try to get supported languages from CodeQL CLI
339-
await this._codeqlService.getSupportedLanguages();
340-
const supportedLanguages = this._codeqlService.getLanguages();
341-
342-
if (supportedLanguages.length > 0) {
343-
this.logger.info(
344-
"UiProvider",
345-
`Auto-loaded ${
346-
supportedLanguages.length
347-
} supported languages: ${supportedLanguages.join(", ")}`
348-
);
349-
350-
// Send the languages to the webview for display
351-
this._view?.webview.postMessage({
352-
command: "supportedLanguagesLoaded",
353-
success: true,
354-
languages: supportedLanguages,
355-
message: `Auto-loaded ${supportedLanguages.length} supported languages`,
356-
});
357-
358-
this.logger.logServiceCall(
359-
"UiProvider",
360-
"autoLoadLanguagesIfNeeded",
361-
"completed",
362-
{ languageCount: supportedLanguages.length }
363-
);
364-
} else {
365-
this.logger.warn(
366-
"UiProvider",
367-
"No supported languages found during auto-load"
368-
);
369-
}
370-
} catch (error) {
371-
this.logger.warn("UiProvider", "Failed to auto-load languages", error);
372-
// Don't show error to user for auto-loading, just log it
373-
}
374-
}
375-
376304
private async autoSelectGitHubLanguages(): Promise<string[]> {
377305
this.logger.logServiceCall(
378306
"UiProvider",
@@ -570,7 +498,9 @@ export class UiProvider implements vscode.WebviewViewProvider {
570498
message:
571499
alert.message?.text || alert.rule?.description || "No description",
572500
location: {
573-
file: alert.most_recent_instance?.location?.path || "unknown",
501+
file: alert.most_recent_instance?.location?.path
502+
? path.join(vscode.workspace.workspaceFolders?.[0]?.uri.fsPath || "", alert.most_recent_instance.location.path)
503+
: "unknown",
574504
startLine: alert.most_recent_instance?.location?.start_line || 1,
575505
startColumn: alert.most_recent_instance?.location?.start_column || 1,
576506
endLine: alert.most_recent_instance?.location?.end_line || 1,

0 commit comments

Comments
 (0)