@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
63 lines (45 loc) • 2.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.showSearch = showSearch;
const doc_dfg_1 = require("./doc-dfg");
const doc_code_1 = require("./doc-code");
const time_1 = require("../../util/text/time");
const flowr_search_printer_1 = require("../../search/flowr-search-printer");
const node_id_1 = require("../../r-bridge/lang-4.x/ast/model/processing/node-id");
const flowr_analyzer_builder_1 = require("../../project/flowr-analyzer-builder");
const range_1 = require("../../util/range");
/**
* Visualizes a search and its results in markdown format.
*/
async function showSearch(shell, code, search, { collapseResult = true } = {}) {
const now = performance.now();
const analyzer = await new flowr_analyzer_builder_1.FlowrAnalyzerBuilder()
.setParser(shell)
.build();
analyzer.addRequest(code);
const result = await analyzer.runSearch(search);
const duration = performance.now() - now;
const metaInfo = `
The search required _${(0, time_1.printAsMs)(duration)}_ (including parsing and normalization and the query) within the generation environment.
`.trim();
const dataflow = await analyzer.dataflow();
return `
${(0, doc_code_1.codeBlock)('ts', (0, flowr_search_printer_1.flowrSearchToCode)(search))}
<details style="color:gray"> <summary>Search Visualization</summary>
${(0, doc_code_1.codeBlock)('mermaid', (0, flowr_search_printer_1.flowrSearchToMermaid)(search))}
In the code:
${(0, doc_code_1.codeBlock)('r', code)}
<details style="color:gray"> <summary>JSON Representation</summary>
${(0, doc_code_1.codeBlock)('json', JSON.stringify(search, null, 2))}
</details>
</details>
${collapseResult ? ' <details> <summary style="color:gray">Show Results</summary>' : ''}
The query returns the following vetices (all references to \`x\` in the code):
${result.getElements().map(({ node }) => `<b>${node.info.id} ('${(0, node_id_1.recoverContent)(node.info.id, dataflow.graph)}')</b> at L${range_1.SourceRange.format(node.location)}`).join(', ')}
${metaInfo}
The returned results are highlighted thick and blue within the dataflow graph:
${await (0, doc_dfg_1.printDfGraphForCode)(shell, code, { showCode: false, switchCodeAndGraph: false, mark: new Set(result.getElements().map(({ node }) => node.info.id)) })}
${collapseResult ? '</details>' : ''}
`;
}
//# sourceMappingURL=doc-search.js.map