From 0673db7498413dc12efe1e600b416a70f9c9e2cd Mon Sep 17 00:00:00 2001 From: Cody Hansen Date: Tue, 1 Oct 2024 05:50:24 -1000 Subject: [PATCH] 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 --- src/components/sequencing/Sequences.svelte | 13 +++++----- .../sequence-editor/sequence-linter.ts | 25 ++++++++----------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/components/sequencing/Sequences.svelte b/src/components/sequencing/Sequences.svelte index 76e3a73cae..a9bbca94da 100644 --- a/src/components/sequencing/Sequences.svelte +++ b/src/components/sequencing/Sequences.svelte @@ -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}` : ''}`); + } @@ -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 diff --git a/src/utilities/sequence-editor/sequence-linter.ts b/src/utilities/sequence-editor/sequence-linter.ts index cb4580e34f..a5c13eabe8 100644 --- a/src/utilities/sequence-editor/sequence-linter.ts +++ b/src/utilities/sequence-editor/sequence-linter.ts @@ -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, @@ -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)); @@ -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; } @@ -191,7 +184,6 @@ function validateParserErrors(tree: Tree) { function conditionalAndLoopKeywordsLinter(commandNodes: SyntaxNode[], state: EditorState): Diagnostic[] { const diagnostics: Diagnostic[] = []; - const blocks = computeBlocks(state); if (blocks) { @@ -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 @@ -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');