Skip to content

Commit 0673db7

Browse files
authored
Bug/fix seq linter (#1485)
* Revered linter back to the original state * Added Chet's block linting back in * Refactored the sequence-linter again * Fixed some problems with null checking workspace ids * Moved numFormat to its own function, cleaned up workspaceId URL handling
1 parent 304e440 commit 0673db7

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

src/components/sequencing/Sequences.svelte

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,14 @@
5151
workspaceId = event.detail;
5252
5353
if (browser) {
54-
setQueryParam(SearchParameters.WORKSPACE_ID, `${workspaceId}` ?? null);
54+
setQueryParam(SearchParameters.WORKSPACE_ID, workspaceId !== null ? `${workspaceId}` : null);
5555
}
5656
}
57+
58+
function navigateToNewSequence(): void {
59+
const workspaceId = getSearchParameterNumber(SearchParameters.WORKSPACE_ID);
60+
goto(`${base}/sequencing/new${workspaceId ? `?${SearchParameters.WORKSPACE_ID}=${workspaceId}` : ''}`);
61+
}
5762
</script>
5863

5964
<CssGrid bind:columns={$userSequencesColumns}>
@@ -77,11 +82,7 @@
7782
permissionError: 'You do not have permission to create a new sequence',
7883
}}
7984
disabled={workspace === undefined}
80-
on:click={() => {
81-
goto(
82-
`${base}/sequencing/new${'?' + SearchParameters.WORKSPACE_ID + '=' + getSearchParameterNumber(SearchParameters.WORKSPACE_ID) ?? ''}`,
83-
);
84-
}}
85+
on:click={navigateToNewSequence}
8586
>
8687
New Sequence
8788
</button>

src/utilities/sequence-editor/sequence-linter.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ import { closest, distance } from 'fastest-levenshtein';
1515

1616
import type { VariableDeclaration } from '@nasa-jpl/seq-json-schema/types';
1717
import type { EditorView } from 'codemirror';
18-
import { get } from 'svelte/store';
1918
import { TOKEN_COMMAND, TOKEN_ERROR, TOKEN_REPEAT_ARG, TOKEN_REQUEST } from '../../constants/seq-n-grammar-constants';
2019
import { TimeTypes } from '../../enums/time';
21-
import { getGlobals, sequenceAdaptation } from '../../stores/sequence-adaptation';
20+
import { getGlobals } from '../../stores/sequence-adaptation';
2221
import { CustomErrorCodes } from '../../workers/customCodes';
23-
import { addDefaultArgs, quoteEscape } from '../codemirror/codemirror-utils';
22+
import { addDefaultArgs, isHexValue, parseNumericArg, quoteEscape } from '../codemirror/codemirror-utils';
2423
import { closeSuggestion, computeBlocks, openSuggestion } from '../codemirror/custom-folder';
2524
import {
2625
getBalancedDuration,
@@ -74,7 +73,7 @@ export function sequenceLinter(
7473
const tree = syntaxTree(view.state);
7574
const treeNode = tree.topNode;
7675
const docText = view.state.doc.toString();
77-
let diagnostics: Diagnostic[] = [];
76+
const diagnostics: Diagnostic[] = [];
7877

7978
diagnostics.push(...validateParserErrors(tree));
8079

@@ -155,12 +154,6 @@ export function sequenceLinter(
155154
...conditionalAndLoopKeywordsLinter(treeNode.getChild('Commands')?.getChildren(TOKEN_COMMAND) || [], view.state),
156155
);
157156

158-
const inputLinter = get(sequenceAdaptation)?.inputFormat.linter;
159-
160-
if (inputLinter !== undefined && commandDictionary !== null) {
161-
diagnostics = inputLinter(diagnostics, commandDictionary, view, treeNode);
162-
}
163-
164157
return diagnostics;
165158
}
166159

@@ -191,7 +184,6 @@ function validateParserErrors(tree: Tree) {
191184

192185
function conditionalAndLoopKeywordsLinter(commandNodes: SyntaxNode[], state: EditorState): Diagnostic[] {
193186
const diagnostics: Diagnostic[] = [];
194-
195187
const blocks = computeBlocks(state);
196188

197189
if (blocks) {
@@ -1185,13 +1177,12 @@ function validateArgument(
11851177
break;
11861178
}
11871179
const { max, min } = dictArg.range;
1188-
const nodeTextAsNumber = parseFloat(argText);
1189-
1180+
const nodeTextAsNumber = parseNumericArg(argText, dictArgType);
11901181
if (nodeTextAsNumber < min || nodeTextAsNumber > max) {
11911182
const message =
11921183
max !== min
1193-
? `Number out of range. Range is between ${min} and ${max} inclusive.`
1194-
: `Number out of range. Range is ${min}.`;
1184+
? `Number out of range. Range is between ${numFormat(argText, min)} and ${numFormat(argText, max)} inclusive.`
1185+
: `Number out of range. Range is ${numFormat(argText, min)}.`;
11951186
diagnostics.push({
11961187
actions:
11971188
max === min
@@ -1356,6 +1347,10 @@ function validateArgument(
13561347
return diagnostics;
13571348
}
13581349

1350+
function numFormat(argText: string, num: number): number | string {
1351+
return isHexValue(argText) ? `0x${num.toString(16).toUpperCase()}` : num;
1352+
}
1353+
13591354
function validateId(commandNode: SyntaxNode, text: string): Diagnostic[] {
13601355
const diagnostics: Diagnostic[] = [];
13611356
const idNodes = commandNode.getChildren('IdDeclaration');

0 commit comments

Comments
 (0)