Skip to content

Commit

Permalink
form view for library sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
joswig committed Feb 3, 2025
1 parent f2d6292 commit 2be0db9
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 11 deletions.
26 changes: 22 additions & 4 deletions src/components/sequencing/SequenceEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
vmlHighlightBlock,
} from '../../utilities/codemirror/vml/vml';
import { parseFunctionSignatures, vmlAutoComplete } from '../../utilities/codemirror/vml/vmlAdaptation';
import { librarySequenceToFswCommand } from '../../utilities/codemirror/vml/vmlBlockLibrary';
import { vmlFormat } from '../../utilities/codemirror/vml/vmlFormatter';
import { vmlLinter } from '../../utilities/codemirror/vml/vmlLinter';
import { vmlTooltip } from '../../utilities/codemirror/vml/vmlTooltip';
Expand Down Expand Up @@ -113,6 +114,7 @@
let commandDictionary: CommandDictionary | null;
let disableCopyAndExport: boolean = true;
let parameterDictionaries: ParameterDictionary[] = [];
let librarySequenceMap: { [sequenceName: string]: LibrarySequence } = {};
let librarySequences: LibrarySequence[] = [];
let commandFormBuilderGrid: string;
let editorOutputDiv: HTMLDivElement;
Expand Down Expand Up @@ -205,11 +207,14 @@
name: sequence.name,
parameters: parseVariables(tree.topNode, sequence.definition, 'ParameterDeclaration') ?? [],
tree,
type: 'librarySequence',
workspace_id: sequence.workspace_id,
};
});
}
librarySequenceMap = Object.fromEntries(librarySequences.map(seq => [seq.name, seq]));
if (unparsedCommandDictionary) {
if (sequenceName && isInVmlMode) {
getParsedCommandDictionary(unparsedCommandDictionary, user).then(parsedCommandDictionary => {
Expand All @@ -220,7 +225,7 @@
),
});
editorSequenceView.dispatch({
effects: compartmentSeqLinter.reconfigure(vmlLinter(commandDictionary, librarySequences)),
effects: compartmentSeqLinter.reconfigure(vmlLinter(commandDictionary, librarySequenceMap)),
});
editorSequenceView.dispatch({
effects: compartmentSeqTooltip.reconfigure(vmlTooltip(commandDictionary)),
Expand Down Expand Up @@ -298,7 +303,7 @@
$: commandNameNode = commandInfoMapper.getNameNode(commandNode);
$: commandName =
commandNameNode && unquoteUnescape(editorSequenceView.state.sliceDoc(commandNameNode.from, commandNameNode.to));
$: commandDef = getCommandDef(commandDictionary, commandName ?? '');
$: commandDef = getCommandDef(commandDictionary, librarySequenceMap, commandName ?? '');
$: timeTagNode = getTimeTagInfo(editorSequenceView, commandNode);
$: argInfoArray = getArgumentInfo(
commandInfoMapper,
Expand Down Expand Up @@ -505,8 +510,21 @@
);
}
function getCommandDef(commandDictionary: CommandDictionary | null, stemName: string): FswCommand | null {
return commandDictionary?.fswCommandMap[stemName] ?? null;
function getCommandDef(
commandDictionary: CommandDictionary | null,
librarySequenceMap: { [sequenceName: string]: LibrarySequence },
stemName: string,
): FswCommand | null {
const commandDefFromCommandDictionary = commandDictionary?.fswCommandMap[stemName];
if (commandDefFromCommandDictionary) {
return commandDefFromCommandDictionary;
}
const librarySeqDef = librarySequenceMap[stemName];
if (librarySeqDef) {
return librarySequenceToFswCommand(librarySeqDef);
}
return null;
}
function getVariablesInScope(
Expand Down
5 changes: 5 additions & 0 deletions src/types/sequencing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,14 @@ export type LibrarySequence = {
name: string;
parameters: VariableDeclaration[];
tree: Tree;
type: 'librarySequence';
workspace_id: number;
};

export function isLibrarySequence(obj: unknown): obj is LibrarySequence {
return !!obj && (obj as LibrarySequence).type === 'librarySequence';
}

export type UserSequenceInsertInput = Omit<UserSequence, 'created_at' | 'id' | 'owner' | 'updated_at'>;

export type Workspace = {
Expand Down
7 changes: 4 additions & 3 deletions src/utilities/codemirror/codemirror-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ import type {
} from '@nasa-jpl/aerie-ampcs';
import type { VariableDeclaration } from '@nasa-jpl/seq-json-schema/types';
import type { EditorView } from 'codemirror';
import type { ArgTextDef, NumberArg, StringArg } from '../../types/sequencing';
import type { ArgTextDef, LibrarySequence, NumberArg, StringArg } from '../../types/sequencing';
import { fswCommandArgDefault } from '../sequence-editor/command-dictionary';
import type { CommandInfoMapper } from './commandInfoMapper';

export function isFswCommand(command: FswCommand | HwCommand): command is FswCommand {
export function isFswCommand(command: FswCommand | HwCommand | LibrarySequence): command is FswCommand {
return (command as FswCommand).type === 'fsw_command';
}
export function isHwCommand(command: FswCommand | HwCommand): command is HwCommand {

export function isHwCommand(command: FswCommand | HwCommand | LibrarySequence): command is HwCommand {
return (command as HwCommand).type === 'hw_command';
}

Expand Down
1 change: 1 addition & 0 deletions src/utilities/codemirror/vml/vmlAdaptation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export function parseFunctionSignatures(contents: string, workspace_id: number):
};
}),
tree: VmlLanguage.parser.parse(contents),
type: 'librarySequence',
workspace_id,
}));
}
Expand Down
71 changes: 71 additions & 0 deletions src/utilities/codemirror/vml/vmlBlockLibrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@ import type {
Enum,
FswCommand,
FswCommandArgument,
FswCommandArgumentEnum,
FswCommandArgumentFloat,
FswCommandArgumentInteger,
FswCommandArgumentUnsigned,
FswCommandArgumentVarString,
Header,
HwCommand,
NumericRange,
} from '@nasa-jpl/aerie-ampcs';
import type { VariableDeclaration } from '@nasa-jpl/seq-json-schema/types';
import type { LibrarySequence } from '../../../types/sequencing';
import { filterEmpty } from '../../generic';
import { VmlLanguage } from './vml';
import {
Expand Down Expand Up @@ -250,3 +257,67 @@ function parameterNodeToDescription(parameterNode: SyntaxNode, vml: string): str
const commentNode = parameterNode.firstChild?.getChild(RULE_COMMENT);
return commentNode ? ioType + vml.slice(commentNode.from, commentNode.to).slice(1).trim() : '';
}

function variableToParam(
variable: VariableDeclaration,
):
| FswCommandArgumentEnum
| FswCommandArgumentFloat
| FswCommandArgumentInteger
| FswCommandArgumentVarString
| FswCommandArgumentUnsigned {
const bit_length = null;
const default_value = null;
const description = '';
const name = variable.name;
const range = null;
const units = '';
switch (variable.type) {
case 'ENUM':
return {
arg_type: 'enum',
bit_length,
default_value,
description,
enum_name: name,
name,
range,
};
case 'STRING':
return {
arg_type: 'var_string',
default_value,
description,
max_bit_length: null,
name,
prefix_bit_length: null,
valid_regex: null,
};
case 'INT':
case 'UINT':
case 'FLOAT':
return {
arg_type: { FLOAT: 'float', INT: 'integer', UINT: 'unsigned' }[variable.type] as
| 'float'
| 'integer'
| 'unsigned',
bit_length,
default_value,
description,
name,
range,
units,
};
}
}

export function librarySequenceToFswCommand(librarySequence: LibrarySequence): FswCommand {
const cndArguments: FswCommandArgument[] = librarySequence.parameters.map(variable => variableToParam(variable));
return {
argumentMap: {},
arguments: cndArguments,
description: 'library sequence',
stem: librarySequence.name,
type: 'fsw_command',
};
}
3 changes: 1 addition & 2 deletions src/utilities/codemirror/vml/vmlLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const MAX_PARSER_ERRORS = 100;

export function vmlLinter(
commandDictionary: CommandDictionary | null = null,
librarySequences: LibrarySequence[] = [],
librarySequenceMap: { [sequenceName: string]: LibrarySequence } = {},
): Extension {
return linter(view => {
const diagnostics: Diagnostic[] = [];
Expand All @@ -50,7 +50,6 @@ export function vmlLinter(
}

const parsed = VmlLanguage.parser.parse(sequence);
const librarySequenceMap = Object.fromEntries(librarySequences.map(seq => [seq.name, seq]));
diagnostics.push(...validateCommands(commandDictionary, librarySequenceMap, sequence, parsed));

return diagnostics;
Expand Down
23 changes: 21 additions & 2 deletions src/utilities/codemirror/vml/vmlTreeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
RULE_ISSUE,
RULE_ISSUE_DYNAMIC,
RULE_SIMPLE_EXPR,
RULE_SPAWN,
RULE_STATEMENT,
RULE_TIME_TAGGED_STATEMENT,
RULE_VARIABLE_DECLARATION_TYPE,
Expand Down Expand Up @@ -57,7 +58,20 @@ export class VmlCommandInfoMapper implements CommandInfoMapper {
}

getArgumentNodeContainer(commandNode: SyntaxNode | null): SyntaxNode | null {
return commandNode?.getChild(RULE_STATEMENT)?.firstChild?.getChild(RULE_CALL_PARAMETERS) ?? null;
const statementNode = commandNode?.getChild(RULE_STATEMENT);
if (statementNode) {
const vmManagementNode = statementNode.getChild(RULE_VM_MANAGEMENT);
if (vmManagementNode) {
const spawnNode = vmManagementNode.getChild(RULE_SPAWN);
if (spawnNode) {
return spawnNode.getChild(RULE_CALL_PARAMETERS);
}
}

// ISSUE and ISSUE_DYNAMIC
return statementNode.firstChild?.getChild(RULE_CALL_PARAMETERS) ?? null;
}
return null;
}

getArgumentsFromContainer(containerNode: SyntaxNode): SyntaxNode[] {
Expand Down Expand Up @@ -112,11 +126,16 @@ export class VmlCommandInfoMapper implements CommandInfoMapper {
?.getChild(TOKEN_STRING_CONST) ?? null
);
case RULE_VM_MANAGEMENT:
{
const spawnNode = statementSubNode.getChild(RULE_SPAWN);
if (spawnNode) {
return spawnNode.getChild(RULE_FUNCTION_NAME);
}
}
break;
}
}

// once block library is implemented allow spawn here too
return null;
}

Expand Down

0 comments on commit 2be0db9

Please sign in to comment.