-
Notifications
You must be signed in to change notification settings - Fork 202
Add commands for navigating the steps on a path #175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,95 @@ | ||
import * as sarif from 'sarif'; | ||
|
||
/** | ||
* Identifies one of the results in a result set by its index in the result list. | ||
*/ | ||
export interface Result { | ||
resultIndex: number; | ||
} | ||
|
||
/** | ||
* Identifies one of the paths associated with a result. | ||
*/ | ||
export interface Path extends Result { | ||
pathIndex: number; | ||
} | ||
|
||
/** | ||
* Identifies one of the nodes in a path. | ||
*/ | ||
export interface PathNode extends Path { | ||
pathNodeIndex: number; | ||
} | ||
|
||
/** Alias for `undefined` but more readable in some cases */ | ||
export const none: PathNode | undefined = undefined; | ||
|
||
/** | ||
* Looks up a specific result in a result set. | ||
*/ | ||
export function getResult(sarif: sarif.Log, key: Result): sarif.Result | undefined { | ||
if (sarif.runs.length === 0) return undefined; | ||
if (sarif.runs[0].results === undefined) return undefined; | ||
let results = sarif.runs[0].results; | ||
return results[key.resultIndex]; | ||
} | ||
|
||
/** | ||
* Looks up a specific path in a result set. | ||
*/ | ||
export function getPath(sarif: sarif.Log, key: Path): sarif.ThreadFlow | undefined { | ||
let result = getResult(sarif, key); | ||
if (result === undefined) return undefined; | ||
let index = -1; | ||
if (result.codeFlows === undefined) return undefined; | ||
for (let codeFlows of result.codeFlows) { | ||
for (let threadFlow of codeFlows.threadFlows) { | ||
++index; | ||
if (index == key.pathIndex) | ||
return threadFlow; | ||
} | ||
} | ||
return undefined; | ||
} | ||
|
||
/** | ||
* Looks up a specific path node in a result set. | ||
*/ | ||
export function getPathNode(sarif: sarif.Log, key: PathNode): sarif.Location | undefined { | ||
let path = getPath(sarif, key); | ||
if (path === undefined) return undefined; | ||
return path.locations[key.pathNodeIndex]; | ||
} | ||
|
||
/** | ||
* Returns true if the two keys are both `undefined` or contain the same set of indices. | ||
*/ | ||
export function equals(key1: PathNode | undefined, key2: PathNode | undefined): boolean { | ||
if (key1 === key2) return true; | ||
if (key1 === undefined || key2 === undefined) return false; | ||
return key1.resultIndex === key2.resultIndex && key1.pathIndex === key2.pathIndex && key1.pathNodeIndex === key2.pathNodeIndex; | ||
} | ||
|
||
/** | ||
* Returns true if the two keys contain the same set of indices and neither are `undefined`. | ||
*/ | ||
export function equalsNotUndefined(key1: PathNode | undefined, key2: PathNode | undefined): boolean { | ||
if (key1 === undefined || key2 === undefined) return false; | ||
return key1.resultIndex === key2.resultIndex && key1.pathIndex === key2.pathIndex && key1.pathNodeIndex === key2.pathNodeIndex; | ||
} | ||
|
||
/** | ||
* Returns the list of paths in the given SARIF result. | ||
* | ||
* Path nodes indices are relative to this flattened list. | ||
*/ | ||
export function getAllPaths(result: sarif.Result): sarif.ThreadFlow[] { | ||
if (result.codeFlows === undefined) return []; | ||
let paths = []; | ||
for (const codeFlow of result.codeFlows) { | ||
for (const threadFlow of codeFlow.threadFlows) { | ||
paths.push(threadFlow); | ||
} | ||
} | ||
return paths; | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be
const
, yeah?