Skip to content

Commit 63d1992

Browse files
author
nicosammito
committed
feat: enhance diagnostics structure with nodeId and parameterIndex for better error tracking
1 parent a1fb1a9 commit 63d1992

4 files changed

Lines changed: 29 additions & 4 deletions

File tree

src/utils.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ export interface ValidationResult {
1818
isValid: boolean;
1919
returnType: string;
2020
diagnostics: Array<{
21-
message: string;
22-
code: number;
23-
severity: "error" | "warning";
21+
message: string
22+
code: number
23+
severity: "error" | "warning"
24+
nodeId?: NodeFunction["id"]
25+
parameterIndex?: number
2426
}>;
2527
}
2628

src/validation/getNodeValidation.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const getNodeValidation = (
3030
return {
3131
isValid: false,
3232
returnType: "any",
33-
diagnostics: [{message: `Function ${node.id} not found`, code: 404, severity: "error"}],
33+
diagnostics: [{message: `Function ${node.id} not found`, nodeId: node.id, code: 404, severity: "error"}],
3434
};
3535
}
3636

@@ -46,6 +46,8 @@ export const getNodeValidation = (
4646
scopeErrors.push({
4747
message: validation.error || "Scope error",
4848
code: 403,
49+
nodeId: node.id,
50+
parameterIndex: params.indexOf(param),
4951
severity: "error"
5052
});
5153
}
@@ -114,6 +116,16 @@ export const getNodeValidation = (
114116
return {
115117
message,
116118
code: d.code,
119+
nodeId: node.id,
120+
parameterIndex: (() => {
121+
if (d.start !== undefined) {
122+
const argIndex = params.findIndex((_, i) => {
123+
const start = sourceCode.indexOf(paramCodes[i]);
124+
return d.start! >= start && d.start! < start + paramCodes[i].length;
125+
});
126+
if (argIndex !== -1) return argIndex;
127+
}
128+
})(),
117129
severity: (isGenericPlaceholder || isMockError ? "warning" : "error") as "error" | "warning",
118130
};
119131
});

test/data.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ export const DATA_TYPES: DataType[] = [
2626
*/
2727
export const FUNCTION_SIGNATURES: FunctionDefinition[] = [
2828
{
29+
parameterDefinitions: {
30+
nodes: [
31+
{
32+
identifier: "list"
33+
},
34+
{
35+
identifier: "index"
36+
}
37+
]
38+
},
2939
signature: "<R>(list: LIST<R>, index: NUMBER): R",
3040
identifier: "std::list::at",
3141
},

test/nodeValidation.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ describe('getNodeValidation', () => {
9393

9494
it('3', () => {
9595
const result = getNodeValidation({}, {
96+
id: "gid://sagittarius/NodeFunction/1",
9697
functionDefinition: {
9798
identifier: "std::list::at" as any
9899
},

0 commit comments

Comments
 (0)