Skip to content

Commit a4db508

Browse files
committed
Fix bugg in alg variable diagnostics
1 parent 9c79645 commit a4db508

2 files changed

Lines changed: 25 additions & 56 deletions

File tree

packages/septic/src/diagnostics.ts

Lines changed: 10 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ export function validateAlg(
278278
diagnostics.push(diagnostic);
279279
return diagnostics;
280280
}
281-
const visitor = new AlgVisitor(true);
281+
const visitor = new AlgVisitor();
282282
visitor.visit(expr);
283283
visitor.calcs.forEach((calc) => {
284284
diagnostics.push(
@@ -291,7 +291,7 @@ export function validateAlg(
291291
variable,
292292
doc,
293293
contextProvider,
294-
offsetStartAlg,
294+
algPositionTransformer,
295295
),
296296
);
297297
});
@@ -302,7 +302,7 @@ export function validateAlgVariable(
302302
variable: AlgLiteral,
303303
doc: TextDocument,
304304
contextProvider: SepticContext,
305-
offsetStartAlg: number,
305+
algPositionTransformer: AlgPositionTransformer,
306306
): SepticDiagnostic[] {
307307
if (isPureJinja(variable.value)) {
308308
return [];
@@ -317,10 +317,7 @@ export function validateAlgVariable(
317317
return [
318318
createDiagnostic(
319319
SepticDiagnosticLevel.warning,
320-
{
321-
start: doc.positionAt(offsetStartAlg + variable.start),
322-
end: doc.positionAt(offsetStartAlg + variable.end),
323-
},
320+
algPositionTransformer(variable.start, variable.end),
324321
`Reference to undefined variable: ${variable.value}`,
325322
SepticDiagnosticCode.missingReference,
326323
),
@@ -333,10 +330,7 @@ export function validateAlgVariable(
333330
return [
334331
createDiagnostic(
335332
SepticDiagnosticLevel.error,
336-
{
337-
start: doc.positionAt(offsetStartAlg + variable.end - 1),
338-
end: doc.positionAt(offsetStartAlg + variable.end),
339-
},
333+
algPositionTransformer(variable.end - 1, variable.end),
340334
`Missing public property for variable`,
341335
SepticDiagnosticCode.missingPublicProperty,
342336
),
@@ -358,21 +352,15 @@ export function validateAlgVariable(
358352
return [
359353
createDiagnostic(
360354
SepticDiagnosticLevel.error,
361-
{
362-
start: doc.positionAt(
363-
offsetStartAlg +
364-
variable.start +
365-
variableParts[0]!.length +
366-
1,
367-
),
368-
end: doc.positionAt(offsetStartAlg + variable.end),
369-
},
355+
algPositionTransformer(
356+
variable.end - variableParts[1]!.length,
357+
variable.end,
358+
),
370359
`Unknown public property ${variableParts[1]} for ${referencedObjects[0]!.type}'`,
371360
SepticDiagnosticCode.unknownPublicProperty,
372361
),
373362
];
374363
}
375-
376364
return [];
377365
}
378366

@@ -593,11 +581,7 @@ function validateParamType(
593581
algPositionTransformer: AlgPositionTransformer,
594582
): SepticDiagnostic[] {
595583
if (types[0]!.startsWith("value")) {
596-
return validateValueParamType(
597-
expr,
598-
contextProvider,
599-
algPositionTransformer,
600-
);
584+
return [];
601585
}
602586
return validateObjectParamType(
603587
expr,
@@ -642,36 +626,6 @@ function validateObjectParamType(
642626
];
643627
}
644628

645-
function validateValueParamType(
646-
expr: AlgExpr,
647-
contextProvider: SepticContext,
648-
algPositionTransformer: AlgPositionTransformer,
649-
): SepticDiagnostic[] {
650-
if (!isAlgExprObjectReference(expr)) {
651-
return [];
652-
}
653-
const exprLiteral = expr as AlgLiteral;
654-
if (isPureJinja(exprLiteral.value)) {
655-
return [];
656-
}
657-
if (
658-
contextProvider.validateReferences(
659-
exprLiteral.value.split(".")[0]!,
660-
defaultRefValidationFunction,
661-
)
662-
) {
663-
return [];
664-
}
665-
return [
666-
createDiagnostic(
667-
SepticDiagnosticLevel.warning,
668-
algPositionTransformer(expr.start, expr.end),
669-
`Reference to undefined variable: ${exprLiteral.value}`,
670-
SepticDiagnosticCode.missingReference,
671-
),
672-
];
673-
}
674-
675629
function isAlgExprObjectReference(expr: AlgExpr) {
676630
return expr instanceof AlgLiteral && expr.type === AlgTokenType.identifier;
677631
}

packages/septic/src/test/diagnostics.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,21 @@ describe("Test diagnostics for references in algs", () => {
197197
SepticDiagnosticCode.unknownPublicProperty,
198198
);
199199
});
200+
it("Expect diagnostics for unknown property when variable is first param in calc", () => {
201+
const text = `
202+
Mvr: TestMvr
203+
CalcPvr: TestCalcPvr
204+
Text1= "Test"
205+
Alg= "-abs(TestMvr.Tests)"
206+
`;
207+
208+
const cnfg = parseSepticForTest(text);
209+
const diag = validateAlgs(cnfg, cnfg);
210+
expect(diag.length).to.equal(1);
211+
expect(diag[0]!.code).to.equal(
212+
SepticDiagnosticCode.unknownPublicProperty,
213+
);
214+
});
200215
});
201216

202217
describe("Test datatype diagnostics in algs", () => {

0 commit comments

Comments
 (0)