Skip to content

Commit

Permalink
toggle between literal and reference option
Browse files Browse the repository at this point in the history
  • Loading branch information
joswig committed Nov 5, 2024
1 parent 4ea8614 commit 5dc7489
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 24 deletions.
20 changes: 13 additions & 7 deletions src/components/sequencing/form/ArgEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,20 @@
/>
{/if}
{:else}
<ArgTitle {argDef} />
{#if argInfo.argDef}
<ArgTitle
argDef={argInfo.argDef}
{commandInfoMapper}
argumentValueCategory={isVariable ? 'Reference' : 'Literal'}
setInEditor={val => {
if (argInfo.node) {
setInEditor(argInfo.node, val);
}
}}
/>
{/if}
{#if isVariable && isFswCommandArgumentEnum(argDef)}
<div
class="st-typography-small-caps"
title="Literals are quoted in editor, Constants/Parameters/Variables are unquoted"
>
Reference
</div>
<div class="st-typography-small-caps">Reference</div>
<EnumEditor
{argDef}
initVal={argInfo.text ?? ''}
Expand Down
88 changes: 75 additions & 13 deletions src/components/sequencing/form/ArgTitle.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<script lang="ts">
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,
Expand All @@ -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)) {
Expand All @@ -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' &&
Expand All @@ -39,29 +61,69 @@
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})`;
}
return base;
}
function onValueTypeChange(event: Event) {
const { value } = getTarget(event);
if (value === 'Literal') {
setInEditor(commandInfoMapper.getDefaultValueForArgumentDef(argDef, {}));
} else {
setInEditor('VARIABLE_OR_CONSTANT_NAME');
}
}
</script>

<Collapse headerHeight={24} padContent={false} {title} defaultExpanded={false}>
<div style="padding-bottom: 4px">
{argDef.description}
<div class="w-100 labeled-values" style="padding-bottom: 4px">
{#if formattedRange}
<div>Range</div>
<div>{formattedRange}</div>
{/if}

{#if typeInfo}
<div>Type</div>
<div>{typeInfo}</div>
{/if}

<div>Description</div>
<div>
{argDef.description}
</div>

<div>Value Type</div>

<select class="st-select" required bind:value={argumentValueCategory} on:change={onValueTypeChange}>
<option value="Literal"> Literal </option>
<option value="Reference"> Reference </option>
</select>
</div>
</Collapse>

<style>
.labeled-values {
align-content: center;
column-gap: 3px;
display: grid;
grid-template-columns: max-content 1fr;
row-gap: 2px;
}
.labeled-values > * {
align-self: top;
}
.labeled-values > div:nth-child(odd) {
font-weight: bold;
}
</style>
3 changes: 3 additions & 0 deletions src/utilities/codemirror/commandInfoMapper.ts
Original file line number Diff line number Diff line change
@@ -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 */
Expand All @@ -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;

Expand Down
6 changes: 6 additions & 0 deletions src/utilities/codemirror/seq-n-tree-utils.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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';
Expand Down Expand Up @@ -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);
}
Expand Down
8 changes: 4 additions & 4 deletions src/utilities/codemirror/vml/vmlAdaptation.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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';
Expand All @@ -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 '""';
}
Expand Down
6 changes: 6 additions & 0 deletions src/utilities/codemirror/vml/vmlTreeUtils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import type { SyntaxNode, Tree } from '@lezer/common';
import type { EnumMap, FswCommandArgument } from '@nasa-jpl/aerie-ampcs';
import {
filterNodesToArray,
getChildrenNode,
getNearestAncestorNodeOfType,
isDefined,
} from '../../sequence-editor/tree-utils';
import type { CommandInfoMapper } from '../commandInfoMapper';
import { getDefaultArgumentValue } from './vmlAdaptation';
import {
RULE_CALL_PARAMETER,
RULE_CALL_PARAMETERS,
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 5dc7489

Please sign in to comment.