-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathget-ast-nodes.ts
More file actions
32 lines (27 loc) · 980 Bytes
/
get-ast-nodes.ts
File metadata and controls
32 lines (27 loc) · 980 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { type AstNode } from "../ast/extract-ast-nodes.js";
import { type ApexAstNodeMetadata } from "../ast/metadata/apex-ast-reference.js";
import { PmdAstNodePipeline } from "../ast/ast-node-pipeline.js";
// Action that returns AST nodes plus cached metadata.
export type GetAstNodesInput = {
code: string;
language: string;
};
export type GetAstNodesOutput = {
status: string;
nodes: AstNode[];
metadata: ApexAstNodeMetadata[];
};
export interface GetAstNodesAction {
exec(input: GetAstNodesInput): Promise<GetAstNodesOutput>;
}
export class GetAstNodesActionImpl implements GetAstNodesAction {
public async exec(input: GetAstNodesInput): Promise<GetAstNodesOutput> {
try {
const pipeline = new PmdAstNodePipeline();
const { nodes, metadata } = await pipeline.run(input);
return { status: "success", nodes, metadata };
} catch (e) {
return { status: (e as Error)?.message ?? String(e), nodes: [], metadata: [] };
}
}
}