-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3113 from github/koesie10/compare-interpreted
Add SARIF result comparison to compare view
- Loading branch information
Showing
6 changed files
with
271 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Uri } from "vscode"; | ||
import * as sarif from "sarif"; | ||
import { pathExists } from "fs-extra"; | ||
import { sarifParser } from "../common/sarif-parser"; | ||
import { CompletedLocalQueryInfo } from "../query-results"; | ||
import { DatabaseManager } from "../databases/local-databases"; | ||
import { CodeQLCliServer } from "../codeql-cli/cli"; | ||
import { InterpretedQueryCompareResult } from "../common/interface-types"; | ||
|
||
import { sarifDiff } from "./sarif-diff"; | ||
|
||
async function getInterpretedResults( | ||
interpretedResultsPath: string, | ||
): Promise<sarif.Log | undefined> { | ||
if (!(await pathExists(interpretedResultsPath))) { | ||
return undefined; | ||
} | ||
|
||
return await sarifParser(interpretedResultsPath); | ||
} | ||
|
||
export async function compareInterpretedResults( | ||
databaseManager: DatabaseManager, | ||
cliServer: CodeQLCliServer, | ||
fromQuery: CompletedLocalQueryInfo, | ||
toQuery: CompletedLocalQueryInfo, | ||
): Promise<InterpretedQueryCompareResult> { | ||
const database = databaseManager.findDatabaseItem( | ||
Uri.parse(toQuery.initialInfo.databaseInfo.databaseUri), | ||
); | ||
if (!database) { | ||
throw new Error( | ||
"Could not find database the queries. Please check that the database still exists.", | ||
); | ||
} | ||
|
||
const [fromResultSet, toResultSet, sourceLocationPrefix] = await Promise.all([ | ||
getInterpretedResults( | ||
fromQuery.completedQuery.query.resultsPaths.interpretedResultsPath, | ||
), | ||
getInterpretedResults( | ||
toQuery.completedQuery.query.resultsPaths.interpretedResultsPath, | ||
), | ||
database.getSourceLocationPrefix(cliServer), | ||
]); | ||
|
||
if (!fromResultSet || !toResultSet) { | ||
throw new Error( | ||
"Could not find interpreted results for one or both queries.", | ||
); | ||
} | ||
|
||
const fromResults = fromResultSet.runs[0].results; | ||
const toResults = toResultSet.runs[0].results; | ||
|
||
if (!fromResults) { | ||
throw new Error("No results found in the 'from' query."); | ||
} | ||
|
||
if (!toResults) { | ||
throw new Error("No results found in the 'to' query."); | ||
} | ||
|
||
const { from, to } = sarifDiff(fromResults, toResults); | ||
|
||
return { | ||
kind: "interpreted", | ||
sourceLocationPrefix, | ||
from, | ||
to, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.