Skip to content

Commit

Permalink
Improve editor linter self-correction
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhincore committed Jan 10, 2025
1 parent a584178 commit 2db2680
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions web/src/modes/editor/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ export const customLinter = linter(
steps.set(key, currentStep);
};

const checkAttribute = (key: string, node: SyntaxNodeRef) => {
if (!currentStep) throw new Error("No step at depth 2");
if (!ALLOWED_ATTRIBUTES.has(key as any)) {
diagnostics.push({
from: node.from,
to: node.to,
severity: "warning",
message: `Unknown step attribute '${key}'.`,
});
}

currentStep[key as keyof Step] = true;
if (key == "options") inOptions = true;
};

function enter(node: SyntaxNodeRef) {
// Syntax error
if (node.type.isError) {
Expand Down Expand Up @@ -65,18 +80,7 @@ export const customLinter = linter(

// Step attributes
case 2:
if (!currentStep) throw new Error("No step at depth 2");
if (!ALLOWED_ATTRIBUTES.has(key as any)) {
diagnostics.push({
from: node.from,
to: node.to,
severity: "warning",
message: `Unknown step attribute '${key}'.`,
});
}

currentStep[key as keyof Step] = true;
if (key == "options") inOptions = true;
checkAttribute(key, node);
break;

case 3:
Expand All @@ -88,8 +92,10 @@ export const customLinter = linter(

case 4:
// NOTE: Self-correction
depth = 1;
if (lastKey) startStep(getString(lastKey), lastKey);
depth = 2;
checkAttribute(key, node);
}
lastKey = node.node;
break;
Expand Down

0 comments on commit 2db2680

Please sign in to comment.