Skip to content

Commit

Permalink
fix: support non-xvr calc params (#478)
Browse files Browse the repository at this point in the history
Remove diagnostics for non xvr params to calcs with correct object type
  • Loading branch information
vetlek authored Feb 8, 2024
1 parent 8f96617 commit 1dedaea
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
31 changes: 29 additions & 2 deletions server/src/language-service/diagnosticsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export function validateAlgs(
diagnostics.push(diagnostic);
continue;
}
const visitor = new AlgVisitor();
const visitor = new AlgVisitor(true);
visitor.visit(expr);

visitor.calcs.forEach((calc) => {
Expand Down Expand Up @@ -556,11 +556,19 @@ function checkValidParamType(
refProvider: SepticReferenceProvider
): boolean {
if (types[0] === VALUE) {
return true;
return checkValidValueParam(expr, refProvider);
}
if (!isAlgExprObjectReference(expr)) {
return false;
}
return checkValidObjectParam(expr, types, refProvider);
}

function checkValidObjectParam(
expr: AlgExpr,
types: string[],
refProvider: SepticReferenceProvider
) {
let exprLiteral = expr as AlgLiteral;
let objects = refProvider.getObjectsByIdentifier(
exprLiteral.value.split(".")[0]
Expand All @@ -573,6 +581,25 @@ function checkValidParamType(
return false;
}

function checkValidValueParam(
expr: AlgExpr,
refProvider: SepticReferenceProvider
) {
if (!isAlgExprObjectReference(expr)) {
return true;
}
let exprLiteral = expr as AlgLiteral;
let objects = refProvider.getObjectsByIdentifier(
exprLiteral.value.split(".")[0]
);
for (let obj of objects) {
if (obj.isXvr()) {
return true;
}
}
return false;
}

function isAlgExprObjectReference(expr: AlgExpr) {
return expr instanceof AlgLiteral && expr.type === AlgTokenType.identifier;
}
Expand Down
18 changes: 15 additions & 3 deletions server/src/septic/algParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,11 @@ export interface IAlgVisitor {
export class AlgVisitor implements IAlgVisitor {
calcs: AlgCalc[] = [];
variables: AlgLiteral[] = [];
private ignoreIdentifierCalcParams;

constructor(ignoreIdentifierCalcParams: boolean = false) {
this.ignoreIdentifierCalcParams = ignoreIdentifierCalcParams;
}

visit(expr: AlgExpr) {
expr.accept(this);
Expand All @@ -420,9 +425,16 @@ export class AlgVisitor implements IAlgVisitor {

visitCalc(expr: AlgCalc): void {
this.calcs.push(expr);
expr.params.forEach((arg) => {
arg.accept(this);
});
for (let param of expr.params) {
if (
this.ignoreIdentifierCalcParams &&
param instanceof AlgLiteral &&
param.type === AlgTokenType.identifier
) {
continue;
}
param.accept(this);
}
}

visitUnary(expr: AlgUnary): void {
Expand Down

0 comments on commit 1dedaea

Please sign in to comment.