Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/fix seq linter #1485

Merged
merged 5 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading