Skip to content

Commit 3c0129b

Browse files
committed
feat: Enhance results display with "no results" messaging and improve language grouping in ResultsProvider
1 parent ca7af87 commit 3c0129b

File tree

2 files changed

+85
-24
lines changed

2 files changed

+85
-24
lines changed

src/providers/resultsProvider.ts

Lines changed: 61 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,24 @@ export class ResultsProvider implements vscode.TreeDataProvider<ResultItem> {
8181
);
8282
} else if (element.type === 'language') {
8383
// Second level - group by severity within language
84-
const severityGroups = this.groupBySeverity(element.results!);
84+
if (!element.results || element.results.length === 0) {
85+
// Show "no results" for this language
86+
return Promise.resolve([
87+
new ResultItem(
88+
'✅ No security alerts found',
89+
vscode.TreeItemCollapsibleState.None,
90+
'noResults',
91+
element.language,
92+
undefined,
93+
undefined,
94+
undefined,
95+
undefined,
96+
`No security vulnerabilities were found for ${element.language}`
97+
)
98+
]);
99+
}
100+
101+
const severityGroups = this.groupBySeverity(element.results);
85102
const sortedSeverities = this.sortSeverityGroups(severityGroups);
86103
return Promise.resolve(
87104
sortedSeverities.map(([severity, results]) =>
@@ -145,14 +162,28 @@ export class ResultsProvider implements vscode.TreeDataProvider<ResultItem> {
145162
}
146163

147164
private groupByLanguage(results: ScanResult[]): { [language: string]: ScanResult[] } {
148-
return results.reduce((groups, result) => {
165+
// Get configured languages from settings
166+
const config = vscode.workspace.getConfiguration("codeql-scanner");
167+
const configuredLanguages = config.get<string[]>("languages", []);
168+
169+
// Start with results grouped by language
170+
const groups = results.reduce((groups, result) => {
149171
const language = result.language || 'unknown';
150172
if (!groups[language]) {
151173
groups[language] = [];
152174
}
153175
groups[language].push(result);
154176
return groups;
155177
}, {} as { [language: string]: ScanResult[] });
178+
179+
// Add configured languages that have no results
180+
configuredLanguages.forEach(language => {
181+
if (!groups[language]) {
182+
groups[language] = [];
183+
}
184+
});
185+
186+
return groups;
156187
}
157188

158189
private groupBySeverity(results: ScanResult[]): { [severity: string]: ScanResult[] } {
@@ -372,18 +403,34 @@ export class ResultItem extends vscode.TreeItem {
372403
private getIcon(): vscode.ThemeIcon {
373404
if (this.type === 'language') {
374405
switch (this.language) {
375-
case 'javascript':
376-
return new vscode.ThemeIcon('symbol-class', new vscode.ThemeColor('symbolIcon.classForeground'));
377-
case 'python':
378-
return new vscode.ThemeIcon('symbol-function', new vscode.ThemeColor('symbolIcon.functionForeground'));
379-
case 'java':
380-
return new vscode.ThemeIcon('symbol-interface', new vscode.ThemeColor('symbolIcon.interfaceForeground'));
381-
case 'csharp':
382-
return new vscode.ThemeIcon('symbol-namespace', new vscode.ThemeColor('symbolIcon.namespaceForeground'));
383-
case 'cpp':
384-
return new vscode.ThemeIcon('symbol-struct', new vscode.ThemeColor('symbolIcon.structForeground'));
385-
default:
386-
return new vscode.ThemeIcon('file-code');
406+
case 'javascript':
407+
case 'typescript':
408+
return new vscode.ThemeIcon('symbol-class', new vscode.ThemeColor('symbolIcon.classForeground'));
409+
case 'python':
410+
return new vscode.ThemeIcon('symbol-function', new vscode.ThemeColor('symbolIcon.functionForeground'));
411+
case 'java':
412+
return new vscode.ThemeIcon('symbol-interface', new vscode.ThemeColor('symbolIcon.interfaceForeground'));
413+
case 'csharp':
414+
return new vscode.ThemeIcon('symbol-namespace', new vscode.ThemeColor('symbolIcon.namespaceForeground'));
415+
case 'cpp':
416+
case 'c':
417+
return new vscode.ThemeIcon('symbol-struct', new vscode.ThemeColor('symbolIcon.structForeground'));
418+
case 'go':
419+
return new vscode.ThemeIcon('symbol-module', new vscode.ThemeColor('symbolIcon.moduleForeground'));
420+
case 'rust':
421+
return new vscode.ThemeIcon('symbol-package', new vscode.ThemeColor('symbolIcon.packageForeground'));
422+
case 'ruby':
423+
return new vscode.ThemeIcon('symbol-property', new vscode.ThemeColor('symbolIcon.propertyForeground'));
424+
case 'php':
425+
return new vscode.ThemeIcon('symbol-variable', new vscode.ThemeColor('symbolIcon.variableForeground'));
426+
case 'swift':
427+
return new vscode.ThemeIcon('symbol-key', new vscode.ThemeColor('symbolIcon.keyForeground'));
428+
case 'kotlin':
429+
return new vscode.ThemeIcon('symbol-constructor', new vscode.ThemeColor('symbolIcon.constructorForeground'));
430+
case 'scala':
431+
return new vscode.ThemeIcon('symbol-operator', new vscode.ThemeColor('symbolIcon.operatorForeground'));
432+
default:
433+
return new vscode.ThemeIcon('file-code');
387434
}
388435
} else if (this.type === 'severity') {
389436
switch (this.severity) {

src/services/codeqlService.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,12 @@ export class CodeQLService {
731731

732732
private getCodeQLDatabase(language: string): string {
733733
const codeqlDir = this.getCodeQLDirectory();
734-
const dbDir = path.join(codeqlDir, "databases", this.getRepositoryName(), language);
734+
const dbDir = path.join(
735+
codeqlDir,
736+
"databases",
737+
this.getRepositoryName(),
738+
language
739+
);
735740
if (!fs.existsSync(dbDir)) {
736741
fs.mkdirSync(dbDir, { recursive: true });
737742
}
@@ -741,8 +746,12 @@ export class CodeQLService {
741746

742747
private getCodeQLConfig(): string {
743748
const codeqlDir = this.getCodeQLDirectory();
744-
const configPath = path.join(codeqlDir, this.getRepositoryName(), "config.yml");
745-
return configPath;
749+
const configPath = path.join(
750+
codeqlDir,
751+
this.getRepositoryName(),
752+
"config.yml"
753+
);
754+
return configPath;
746755
}
747756

748757
private getCodeQLResults(): string {
@@ -821,15 +830,20 @@ export class CodeQLService {
821830
const config = vscode.workspace.getConfiguration("codeql-scanner");
822831
const codeqlPath = config.get<string>("codeqlPath", "codeql");
823832

824-
const databasePath = this.getCodeQLDatabase(language);
825-
const searchPathArg = searchPaths
826-
.map((p) => path.join(workspaceFolder, p))
827-
.join(":");
828-
833+
const databasePath = this.getCodeQLDatabase(language);
829834
let source = this.getWorkspaceFolder();
830835

831-
// TODO: We only support BMN
832-
const command = `${codeqlPath} database create --overwrite --language ${language} -s "${source}" --build-mode=none --search-path "${searchPathArg}" "${databasePath}"`;
836+
var command = `${codeqlPath} database create --overwrite --language ${language} -s "${source}"`;
837+
// Add BMN
838+
if (language === "cpp" || language === "csharp" || language === "java") {
839+
command += ` --build-mode=none`;
840+
}
841+
command += ` "${databasePath}"`
842+
843+
this.logger.info(
844+
"CodeQLService",
845+
`CodeQL Create Command: ${command}`
846+
)
833847

834848
try {
835849
progress.report({ message: `Creating ${language} database...` });

0 commit comments

Comments
 (0)