Skip to content

Commit

Permalink
Bug/fix seq linter (#1485)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
cohansen authored Oct 1, 2024
1 parent 304e440 commit 0673db7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
13 changes: 7 additions & 6 deletions src/components/sequencing/Sequences.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,14 @@
workspaceId = event.detail;
if (browser) {
setQueryParam(SearchParameters.WORKSPACE_ID, `${workspaceId}` ?? null);
setQueryParam(SearchParameters.WORKSPACE_ID, workspaceId !== null ? `${workspaceId}` : null);
}
}
function navigateToNewSequence(): void {
const workspaceId = getSearchParameterNumber(SearchParameters.WORKSPACE_ID);
goto(`${base}/sequencing/new${workspaceId ? `?${SearchParameters.WORKSPACE_ID}=${workspaceId}` : ''}`);
}
</script>

<CssGrid bind:columns={$userSequencesColumns}>
Expand All @@ -77,11 +82,7 @@
permissionError: 'You do not have permission to create a new sequence',
}}
disabled={workspace === undefined}
on:click={() => {
goto(
`${base}/sequencing/new${'?' + SearchParameters.WORKSPACE_ID + '=' + getSearchParameterNumber(SearchParameters.WORKSPACE_ID) ?? ''}`,
);
}}
on:click={navigateToNewSequence}
>
New Sequence
</button>
Expand Down
25 changes: 10 additions & 15 deletions src/utilities/sequence-editor/sequence-linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ import { closest, distance } from 'fastest-levenshtein';

import type { VariableDeclaration } from '@nasa-jpl/seq-json-schema/types';
import type { EditorView } from 'codemirror';
import { get } from 'svelte/store';
import { TOKEN_COMMAND, TOKEN_ERROR, TOKEN_REPEAT_ARG, TOKEN_REQUEST } from '../../constants/seq-n-grammar-constants';
import { TimeTypes } from '../../enums/time';
import { getGlobals, sequenceAdaptation } from '../../stores/sequence-adaptation';
import { getGlobals } from '../../stores/sequence-adaptation';
import { CustomErrorCodes } from '../../workers/customCodes';
import { addDefaultArgs, quoteEscape } from '../codemirror/codemirror-utils';
import { addDefaultArgs, isHexValue, parseNumericArg, quoteEscape } from '../codemirror/codemirror-utils';
import { closeSuggestion, computeBlocks, openSuggestion } from '../codemirror/custom-folder';
import {
getBalancedDuration,
Expand Down Expand Up @@ -74,7 +73,7 @@ export function sequenceLinter(
const tree = syntaxTree(view.state);
const treeNode = tree.topNode;
const docText = view.state.doc.toString();
let diagnostics: Diagnostic[] = [];
const diagnostics: Diagnostic[] = [];

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

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

const inputLinter = get(sequenceAdaptation)?.inputFormat.linter;

if (inputLinter !== undefined && commandDictionary !== null) {
diagnostics = inputLinter(diagnostics, commandDictionary, view, treeNode);
}

return diagnostics;
}

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

function conditionalAndLoopKeywordsLinter(commandNodes: SyntaxNode[], state: EditorState): Diagnostic[] {
const diagnostics: Diagnostic[] = [];

const blocks = computeBlocks(state);

if (blocks) {
Expand Down Expand Up @@ -1185,13 +1177,12 @@ function validateArgument(
break;
}
const { max, min } = dictArg.range;
const nodeTextAsNumber = parseFloat(argText);

const nodeTextAsNumber = parseNumericArg(argText, dictArgType);
if (nodeTextAsNumber < min || nodeTextAsNumber > max) {
const message =
max !== min
? `Number out of range. Range is between ${min} and ${max} inclusive.`
: `Number out of range. Range is ${min}.`;
? `Number out of range. Range is between ${numFormat(argText, min)} and ${numFormat(argText, max)} inclusive.`
: `Number out of range. Range is ${numFormat(argText, min)}.`;
diagnostics.push({
actions:
max === min
Expand Down Expand Up @@ -1356,6 +1347,10 @@ function validateArgument(
return diagnostics;
}

function numFormat(argText: string, num: number): number | string {
return isHexValue(argText) ? `0x${num.toString(16).toUpperCase()}` : num;
}

function validateId(commandNode: SyntaxNode, text: string): Diagnostic[] {
const diagnostics: Diagnostic[] = [];
const idNodes = commandNode.getChildren('IdDeclaration');
Expand Down

0 comments on commit 0673db7

Please sign in to comment.