diff --git a/src/components/sequencing/form/ArgEditor.svelte b/src/components/sequencing/form/ArgEditor.svelte index b1751890a4..064560850e 100644 --- a/src/components/sequencing/form/ArgEditor.svelte +++ b/src/components/sequencing/form/ArgEditor.svelte @@ -80,14 +80,20 @@ /> {/if} {:else} - + {#if argInfo.argDef} + { + if (argInfo.node) { + setInEditor(argInfo.node, val); + } + }} + /> + {/if} {#if isVariable && isFswCommandArgumentEnum(argDef)} -
- Reference -
+
Reference
import type { FswCommandArgument } from '@nasa-jpl/aerie-ampcs'; import { isArray } from 'lodash-es'; + import type { CommandInfoMapper } from '../../../utilities/codemirror/commandInfoMapper'; + import { getTarget } from '../../../utilities/generic'; import Collapse from '../../Collapse.svelte'; import { isFswCommandArgumentFloat, @@ -13,10 +15,19 @@ } from './../../../utilities/codemirror/codemirror-utils'; export let argDef: FswCommandArgument; + export let commandInfoMapper: CommandInfoMapper; + export let setInEditor: (val: string) => void; + export let argumentValueCategory: 'Literal' | 'Reference'; + + let title: string = ''; + let typeInfo: string = ''; + let formattedRange: string = ''; $: title = getArgTitle(argDef); + $: typeInfo = compactType(argDef); + $: formattedRange = formatRange(argDef); - function compactType(argDef: FswCommandArgument) { + function compactType(argDef: FswCommandArgument): string { if (isFswCommandArgumentUnsigned(argDef)) { return `U${argDef.bit_length}`; } else if (isFswCommandArgumentInteger(argDef)) { @@ -30,7 +41,18 @@ return ''; } - function getArgTitle(argDef: FswCommandArgument) { + function formatRange(argDef: FswCommandArgument): string { + if ('range' in argDef && argDef.range) { + if (isArray(argDef.range)) { + return ` [${argDef.range.join(', ')}]`; + } else { + return ` [${argDef.range.min} – ${argDef.range.max}]`; + } + } + return ''; + } + + function getArgTitle(argDef: FswCommandArgument): string { if ( isFswCommandArgumentRepeat(argDef) && typeof argDef.repeat?.max === 'number' && @@ -39,18 +61,11 @@ return `${argDef.name} - [${argDef.repeat?.min}, ${argDef.repeat?.max}] sets`; } - let compactTypeInfo = compactType(argDef); + let compactTypeInfo = typeInfo; if (compactTypeInfo) { compactTypeInfo = ` [${compactTypeInfo}]`; } - let base = `${argDef.name}${compactTypeInfo}`; - if ('range' in argDef && argDef.range) { - if (isArray(argDef.range)) { - base += ` [${argDef.range.join(', ')}]`; - } else { - base += ` [${argDef.range.min} – ${argDef.range.max}]`; - } - } + let base = `${argDef.name}${compactTypeInfo}${formatRange(argDef)}`; if ('units' in argDef) { return `${base} – (${argDef.units})`; @@ -58,10 +73,57 @@ return base; } + + function onValueTypeChange(event: Event) { + const { value } = getTarget(event); + if (value === 'Literal') { + setInEditor(commandInfoMapper.getDefaultValueForArgumentDef(argDef, {})); + } else { + setInEditor('VARIABLE_OR_CONSTANT_NAME'); + } + } -
- {argDef.description} +
+ {#if formattedRange} +
Range
+
{formattedRange}
+ {/if} + + {#if typeInfo} +
Type
+
{typeInfo}
+ {/if} + +
Description
+
+ {argDef.description} +
+ +
Value Type
+ +
+ + diff --git a/src/utilities/codemirror/commandInfoMapper.ts b/src/utilities/codemirror/commandInfoMapper.ts index 4ecfaf6347..b04269e0a4 100644 --- a/src/utilities/codemirror/commandInfoMapper.ts +++ b/src/utilities/codemirror/commandInfoMapper.ts @@ -1,4 +1,5 @@ import type { SyntaxNode, Tree } from '@lezer/common'; +import type { EnumMap, FswCommandArgument } from '@nasa-jpl/aerie-ampcs'; export interface CommandInfoMapper { /** format string of multiple arguments */ @@ -16,6 +17,8 @@ export interface CommandInfoMapper { /** ascends parse tree to find scope to display in form editor */ getContainingCommand(node: SyntaxNode | null): SyntaxNode | null; + getDefaultValueForArgumentDef(argDef: FswCommandArgument, enumMap: EnumMap): string; + /** finds the node in the parse tree containing the name */ getNameNode(stepNode: SyntaxNode | null): SyntaxNode | null; diff --git a/src/utilities/codemirror/seq-n-tree-utils.ts b/src/utilities/codemirror/seq-n-tree-utils.ts index 38d733d6c9..12045baa5a 100644 --- a/src/utilities/codemirror/seq-n-tree-utils.ts +++ b/src/utilities/codemirror/seq-n-tree-utils.ts @@ -1,4 +1,5 @@ import type { SyntaxNode, Tree } from '@lezer/common'; +import type { EnumMap, FswCommandArgument } from '@nasa-jpl/aerie-ampcs'; import { RULE_ARGS, RULE_COMMAND, @@ -16,6 +17,7 @@ import { TOKEN_REQUEST, TOKEN_STRING, } from '../../constants/seq-n-grammar-constants'; +import { fswCommandArgDefault } from '../sequence-editor/command-dictionary'; import { validateVariables } from '../sequence-editor/sequence-linter'; import { getFromAndTo, getNearestAncestorNodeOfType } from '../sequence-editor/tree-utils'; import type { CommandInfoMapper } from './commandInfoMapper'; @@ -86,6 +88,10 @@ export class SeqNCommandInfoMapper implements CommandInfoMapper { return getAncestorStepOrRequest(node); } + getDefaultValueForArgumentDef(argDef: FswCommandArgument, enumMap: EnumMap): string { + return fswCommandArgDefault(argDef, enumMap); + } + getNameNode(stepNode: SyntaxNode | null): SyntaxNode | null { return getNameNode(stepNode); } diff --git a/src/utilities/codemirror/vml/vmlAdaptation.ts b/src/utilities/codemirror/vml/vmlAdaptation.ts index 8436915b47..cce847c934 100644 --- a/src/utilities/codemirror/vml/vmlAdaptation.ts +++ b/src/utilities/codemirror/vml/vmlAdaptation.ts @@ -1,6 +1,6 @@ import { type CompletionContext, type CompletionResult } from '@codemirror/autocomplete'; import { syntaxTree } from '@codemirror/language'; -import type { CommandDictionary, FswCommand, FswCommandArgument } from '@nasa-jpl/aerie-ampcs'; +import type { CommandDictionary, EnumMap, FswCommand, FswCommandArgument } from '@nasa-jpl/aerie-ampcs'; import { getNearestAncestorNodeOfType } from '../../sequence-editor/tree-utils'; import { RULE_FUNCTION_NAME, RULE_ISSUE, RULE_STATEMENT, TOKEN_STRING_CONST } from './vmlConstants'; import { getArgumentPosition } from './vmlTreeUtils'; @@ -72,12 +72,12 @@ export function vmlAutoComplete( function getStemAndDefaultArguments(commandDictionary: CommandDictionary, cmd: FswCommand): string { if (cmd.arguments.length) { - return `${cmd.stem} ${cmd.arguments.map(argNode => getDefaultArgumentValue(commandDictionary, argNode)).join(',')}`; + return `${cmd.stem} ${cmd.arguments.map(argNode => getDefaultArgumentValue(argNode, commandDictionary.enumMap)).join(',')}`; } return cmd.stem; } -function getDefaultArgumentValue(commandDictionary: CommandDictionary, argDef: FswCommandArgument): string { +export function getDefaultArgumentValue(argDef: FswCommandArgument, enumMap: EnumMap): string { switch (argDef.arg_type) { case 'boolean': return argDef.default_value ?? 'TRUE'; @@ -88,7 +88,7 @@ function getDefaultArgumentValue(commandDictionary: CommandDictionary, argDef: F // ignores conversion setting return (argDef.default_value ?? argDef.range?.min)?.toString(10) ?? '0'; case 'enum': - return `"${commandDictionary.enumMap[argDef.enum_name]?.values[0]?.symbol ?? ''}"`; + return `"${enumMap[argDef.enum_name]?.values[0]?.symbol ?? ''}"`; case 'var_string': return '""'; } diff --git a/src/utilities/codemirror/vml/vmlTreeUtils.ts b/src/utilities/codemirror/vml/vmlTreeUtils.ts index 177c59a22c..72915573b2 100644 --- a/src/utilities/codemirror/vml/vmlTreeUtils.ts +++ b/src/utilities/codemirror/vml/vmlTreeUtils.ts @@ -1,4 +1,5 @@ import type { SyntaxNode, Tree } from '@lezer/common'; +import type { EnumMap, FswCommandArgument } from '@nasa-jpl/aerie-ampcs'; import { filterNodesToArray, getChildrenNode, @@ -6,6 +7,7 @@ import { isDefined, } from '../../sequence-editor/tree-utils'; import type { CommandInfoMapper } from '../commandInfoMapper'; +import { getDefaultArgumentValue } from './vmlAdaptation'; import { RULE_CALL_PARAMETER, RULE_CALL_PARAMETERS, @@ -65,6 +67,10 @@ export class VmlCommandInfoMapper implements CommandInfoMapper { return getNearestAncestorNodeOfType(node, [RULE_TIME_TAGGED_STATEMENT]); } + getDefaultValueForArgumentDef(argDef: FswCommandArgument, enumMap: EnumMap): string { + return getDefaultArgumentValue(argDef, enumMap); + } + getNameNode(statementNode: SyntaxNode | null): SyntaxNode | null { const statementSubNode = statementNode?.getChild(RULE_STATEMENT)?.getChild(RULE_ISSUE); if (statementSubNode?.name === RULE_ISSUE) {