|
1 |
| -import type { ReplCommand, ReplOutput } from './repl-main'; |
2 |
| -import { createDataflowPipeline } from '../../../core/steps/pipeline/default-pipelines'; |
3 |
| -import { fileProtocol, requestFromInput } from '../../../r-bridge/retriever'; |
| 1 | +import type { ReplCodeCommand, ReplOutput } from './repl-main'; |
| 2 | +import { fileProtocol } from '../../../r-bridge/retriever'; |
4 | 3 | import { graphToMermaid, graphToMermaidUrl } from '../../../util/mermaid/dfg';
|
5 |
| -import type { KnownParser } from '../../../r-bridge/parser'; |
6 | 4 | import { ColorEffect, Colors, FontStyles } from '../../../util/text/ansi';
|
7 |
| -import type { FlowrConfigOptions } from '../../../config'; |
| 5 | +import type { PipelinePerStepMetaInformation } from '../../../core/steps/pipeline/pipeline'; |
| 6 | +import { handleString } from '../core'; |
8 | 7 |
|
9 |
| -/** |
10 |
| - * Obtain the dataflow graph using a known parser (such as the {@link RShell} or {@link TreeSitterExecutor}). |
11 |
| - */ |
12 |
| -async function replGetDataflow(config: FlowrConfigOptions, parser: KnownParser, code: string) { |
13 |
| - return await createDataflowPipeline(parser, { |
14 |
| - request: requestFromInput(code.trim()) |
15 |
| - }, config).allRemainingSteps(); |
| 8 | +function formatInfo(out: ReplOutput, type: string, meta: PipelinePerStepMetaInformation ): string { |
| 9 | + return out.formatter.format(`Copied ${type} to clipboard (dataflow: ${meta['.meta'].timing + 'ms'}).`, |
| 10 | + { color: Colors.White, effect: ColorEffect.Foreground, style: FontStyles.Italic }); |
16 | 11 | }
|
17 | 12 |
|
18 |
| -function handleString(code: string): string { |
19 |
| - return code.startsWith('"') ? JSON.parse(code) as string : code; |
20 |
| -} |
21 |
| - |
22 |
| -function formatInfo(out: ReplOutput, type: string, timing: number): string { |
23 |
| - return out.formatter.format(`Copied ${type} to clipboard (dataflow: ${timing}ms).`, { color: Colors.White, effect: ColorEffect.Foreground, style: FontStyles.Italic }); |
24 |
| -} |
25 |
| - |
26 |
| -export const dataflowCommand: ReplCommand = { |
| 13 | +export const dataflowCommand: ReplCodeCommand = { |
27 | 14 | description: `Get mermaid code for the dataflow graph, start with '${fileProtocol}' to indicate a file`,
|
| 15 | + usesAnalyzer: true, |
28 | 16 | usageExample: ':dataflow',
|
29 | 17 | aliases: [ 'd', 'df' ],
|
30 | 18 | script: false,
|
31 |
| - fn: async({ output, parser, remainingLine, config }) => { |
32 |
| - const result = await replGetDataflow(config, parser, handleString(remainingLine)); |
33 |
| - const mermaid = graphToMermaid({ graph: result.dataflow.graph, includeEnvironments: false }).string; |
| 19 | + argsParser: (args: string) => handleString(args), |
| 20 | + fn: async({ output, analyzer }) => { |
| 21 | + const result = await analyzer.dataflow(); |
| 22 | + const mermaid = graphToMermaid({ graph: result.graph, includeEnvironments: false }).string; |
34 | 23 | output.stdout(mermaid);
|
35 | 24 | try {
|
36 | 25 | const clipboard = await import('clipboardy');
|
37 | 26 | clipboard.default.writeSync(mermaid);
|
38 |
| - output.stdout(formatInfo(output, 'mermaid code', result.dataflow['.meta'].timing)); |
| 27 | + output.stdout(formatInfo(output, 'mermaid code', result)); |
39 | 28 | } catch{ /* do nothing this is a service thing */ }
|
40 | 29 | }
|
41 | 30 | };
|
42 | 31 |
|
43 |
| -export const dataflowStarCommand: ReplCommand = { |
| 32 | +export const dataflowStarCommand: ReplCodeCommand = { |
44 | 33 | description: 'Returns the URL to mermaid.live',
|
| 34 | + usesAnalyzer: true, |
45 | 35 | usageExample: ':dataflow*',
|
46 | 36 | aliases: [ 'd*', 'df*' ],
|
47 | 37 | script: false,
|
48 |
| - fn: async({ output, parser, remainingLine, config }) => { |
49 |
| - const result = await replGetDataflow(config, parser, handleString(remainingLine)); |
50 |
| - const mermaid = graphToMermaidUrl(result.dataflow.graph, false); |
| 38 | + argsParser: (args: string) => handleString(args), |
| 39 | + fn: async({ output, analyzer }) => { |
| 40 | + const result = await analyzer.dataflow(); |
| 41 | + const mermaid = graphToMermaidUrl(result.graph, false); |
51 | 42 | output.stdout(mermaid);
|
52 | 43 | try {
|
53 | 44 | const clipboard = await import('clipboardy');
|
54 | 45 | clipboard.default.writeSync(mermaid);
|
55 |
| - output.stdout(formatInfo(output, 'mermaid url', result.dataflow['.meta'].timing)); |
| 46 | + output.stdout(formatInfo(output, 'mermaid url', result)); |
56 | 47 | } catch{ /* do nothing this is a service thing */ }
|
57 | 48 | }
|
58 | 49 | };
|
59 | 50 |
|
60 | 51 |
|
61 |
| -export const dataflowSimplifiedCommand: ReplCommand = { |
| 52 | +export const dataflowSimplifiedCommand: ReplCodeCommand = { |
62 | 53 | description: `Get mermaid code for the simplified dataflow graph, start with '${fileProtocol}' to indicate a file`,
|
| 54 | + usesAnalyzer: true, |
63 | 55 | usageExample: ':dataflowsimple',
|
64 | 56 | aliases: [ 'ds', 'dfs' ],
|
65 | 57 | script: false,
|
66 |
| - fn: async({ output, parser, remainingLine, config }) => { |
67 |
| - const result = await replGetDataflow(config, parser, handleString(remainingLine)); |
68 |
| - const mermaid = graphToMermaid({ graph: result.dataflow.graph, includeEnvironments: false, simplified: true }).string; |
| 58 | + argsParser: (args: string) => handleString(args), |
| 59 | + fn: async({ output, analyzer }) => { |
| 60 | + const result = await analyzer.dataflow(); |
| 61 | + const mermaid = graphToMermaid({ graph: result.graph, includeEnvironments: false, simplified: true }).string; |
69 | 62 | output.stdout(mermaid);
|
70 | 63 | try {
|
71 | 64 | const clipboard = await import('clipboardy');
|
72 | 65 | clipboard.default.writeSync(mermaid);
|
73 |
| - output.stdout(formatInfo(output, 'mermaid code', result.dataflow['.meta'].timing)); |
| 66 | + output.stdout(formatInfo(output, 'mermaid code', result)); |
74 | 67 | } catch{ /* do nothing this is a service thing */ }
|
75 | 68 | }
|
76 | 69 | };
|
77 | 70 |
|
78 |
| -export const dataflowSimpleStarCommand: ReplCommand = { |
| 71 | +export const dataflowSimpleStarCommand: ReplCodeCommand = { |
79 | 72 | description: 'Returns the URL to mermaid.live',
|
| 73 | + usesAnalyzer: true, |
80 | 74 | usageExample: ':dataflowsimple*',
|
81 | 75 | aliases: [ 'ds*', 'dfs*' ],
|
82 | 76 | script: false,
|
83 |
| - fn: async({ output, parser, remainingLine, config }) => { |
84 |
| - const result = await replGetDataflow(config, parser, handleString(remainingLine)); |
85 |
| - const mermaid = graphToMermaidUrl(result.dataflow.graph, false, undefined, true); |
| 77 | + argsParser: (args: string) => handleString(args), |
| 78 | + fn: async({ output, analyzer }) => { |
| 79 | + const result = await analyzer.dataflow(); |
| 80 | + const mermaid = graphToMermaidUrl(result.graph, false, undefined, true); |
86 | 81 | output.stdout(mermaid);
|
87 | 82 | try {
|
88 | 83 | const clipboard = await import('clipboardy');
|
89 | 84 | clipboard.default.writeSync(mermaid);
|
90 |
| - output.stdout(formatInfo(output, 'mermaid url', result.dataflow['.meta'].timing)); |
| 85 | + output.stdout(formatInfo(output, 'mermaid url', result)); |
91 | 86 | } catch{ /* do nothing this is a service thing */ }
|
92 | 87 | }
|
93 | 88 | };
|
0 commit comments