-
Notifications
You must be signed in to change notification settings - Fork 0
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
Prettify provenance output #72
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
"typescript.tsc.autoDetect": "off", | ||
"cSpell.words": [ | ||
"eopa", | ||
"norc", | ||
"picomatch", | ||
"tsandall" | ||
] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
[![slack](https://img.shields.io/badge/slack-styra-24b6e0.svg?logo=slack)](https://styracommunity.slack.com/) | ||
[![Apache License](https://img.shields.io/badge/license-Apache%202.0-orange.svg)](https://www.apache.org/licenses/LICENSE-2.0) | ||
[![Visual Studio Marketplace Version](https://img.shields.io/visual-studio-marketplace/v/Styra.vscode-styra?color=24b6e0)](#) | ||
[![Coverage](https://img.shields.io/badge/Coverage-74%25-brightgreen)](#) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guessing this happened automatically. Interesting setup. |
||
[![Coverage](https://img.shields.io/badge/Coverage-73%25-brightgreen)](#) | ||
[![CI status](https://github.com/StyraInc/vscode-styra/actions/workflows/main.yaml/badge.svg)](https://github.com/StyraInc/vscode-styra/actions/workflows/main.yaml) | ||
[![closed PRs](https://img.shields.io/github/issues-pr-closed-raw/StyraInc/vscode-styra)](https://github.com/StyraInc/vscode-styra/pulls?q=is%3Apr+is%3Aclosed) | ||
<!-- | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,21 +160,20 @@ export function formatResults(results: object, selection:boolean, raw?: boolean) | |
if (raw) { | ||
return JSON.stringify(results, null, 2); | ||
} | ||
const r = results as {result: object, metrics: {[key: string]: number}, printed: string, provenance: object}; | ||
const r = results as {result: object, metrics: {[key: string]: number}, printed: string, provenance: {[key: string]: string | {[key: string]: object}}}; | ||
|
||
let output = ''; | ||
|
||
if (r.provenance) { | ||
output += `PROVENANCE\n==========\n${JSON.stringify(r.provenance, null, 2)}\n\n`; | ||
output += `PROVENANCE\n==========\n${getPrettyProvenance(r.provenance)}`; | ||
} | ||
|
||
if (r.metrics?.timer_query_compile_stage_resolve_refs_ns) { | ||
output += `METRICS\n=======\n${metricTables(r.metrics)}`; | ||
// output += `METRICS\n=======\n${Object.keys(r.metrics).map((k: string) => formatMetric(k, r.metrics[k])).join('\n')}\n\n`; | ||
} | ||
|
||
if (r.printed) { | ||
output += `PRINTED\n=======\n${r.printed}\n\n`; | ||
output += `PRINTED\n=======\n${r.printed}\n`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PR Bonus: There was an extra line added after printed lines because each ends with a new-line character. This cause three new lines instead of 2. |
||
} | ||
|
||
output += 'RESULT\n======\n'; | ||
|
@@ -353,6 +352,28 @@ export function getPrettyTime(ns: number): string { | |
return (ns / 1e3).toString() + 'µs'; | ||
} | ||
|
||
function getPrettyProvenance(provenance: {[key: string]: string | {[key: string]: object}}): string { | ||
let output = ''; | ||
Object.keys(provenance).forEach((k: string) => { | ||
if (typeof provenance[k] !== 'string') { | ||
return; | ||
} | ||
const niceKey = k.split('_').map((part: string) => part[0].toUpperCase() + part.substring(1)).join(' '); | ||
output += `${niceKey}: ${provenance[k]}\n`; | ||
}); | ||
output += '\n'; | ||
|
||
if (provenance.bundles && typeof provenance.bundles === 'object' && Object.keys(provenance.bundles).length > 0) { | ||
const bundleData: Array<[string, string]> = [['Name', 'Revision']]; | ||
Object.keys(provenance.bundles).forEach((bundle) => { | ||
const revision = (provenance.bundles as {[key: string]: {revision?: string}})[bundle].revision; | ||
bundleData.push([bundle, revision || '']); | ||
}); | ||
output += table(bundleData, {border: getBorderCharacters('norc'), columns: [{}, {width: 65, wrapWord: true}], header: {alignment: 'center', content: 'BUNDLES'}}) + '\n'; | ||
} | ||
return output; | ||
} | ||
|
||
/** | ||
* Reports a result to the Enterprise OPA Preview pane | ||
*/ | ||
|
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.
Author Note: ensure VS Code cspell does not complain about the name of the table style used.