diff --git a/src/components/sequencing/form/ArgEditor.svelte b/src/components/sequencing/form/ArgEditor.svelte
index a1f8ba6841..b1751890a4 100644
--- a/src/components/sequencing/form/ArgEditor.svelte
+++ b/src/components/sequencing/form/ArgEditor.svelte
@@ -82,7 +82,12 @@
{:else}
{#if isVariable && isFswCommandArgumentEnum(argDef)}
-
Global/Parameter
+
+ Reference
+
blockToCommandDef(blockNode, vml),
),
- ].filter((maybeCommandDef): maybeCommandDef is FswCommand => !!maybeCommandDef);
+ ].filter(isDefined);
const mission_name = '';
const spacecraft_ids = [0];
@@ -84,7 +85,7 @@ function blockToCommandDef(functionNode: SyntaxNode, vml: string): FswCommand |
const parameterNodes = commonFunctionNode?.getChild(RULE_PARAMETERS)?.getChildren(RULE_PARAMETER) ?? [];
const fswArguments: FswCommandArgument[] = parameterNodes
?.map(parameterNode => inputToArgument(parameterNode, vml))
- .filter((maybeArg): maybeArg is FswCommandArgument => !!maybeArg);
+ .filter(isDefined);
if (stem) {
return {
@@ -205,7 +206,7 @@ function parseRange(parameterNode: SyntaxNode | null, vml: string): null | strin
}
return null;
})
- .filter((maybeRangeValue): maybeRangeValue is number | string | NumericRange => !!maybeRangeValue);
+ .filter(isDefined);
// mixed arrays aren't resolved due to undefined meaning
if (rangeValues.every(rangeValue => typeof rangeValue === 'number')) {
diff --git a/src/utilities/codemirror/vml/vmlFormatter.ts b/src/utilities/codemirror/vml/vmlFormatter.ts
index a8d2f3855f..95ae50edaa 100644
--- a/src/utilities/codemirror/vml/vmlFormatter.ts
+++ b/src/utilities/codemirror/vml/vmlFormatter.ts
@@ -2,6 +2,7 @@ import { syntaxTree } from '@codemirror/language';
import type { ChangeSpec, EditorState } from '@codemirror/state';
import type { SyntaxNode } from '@lezer/common';
import { EditorView } from 'codemirror';
+import { isDefined } from '../../sequence-editor/tree-utils';
import {
RULE_ASSIGNMENT,
RULE_CALL_PARAMETERS,
@@ -142,7 +143,7 @@ export function vmlFormat(view: EditorView): void {
const docText = state.toText(state.sliceDoc());
const maybeChanges = linesToFormat.flatMap((line: LineOfNodes) => {
- const firstNode = line.find(maybeNode => !!maybeNode);
+ const firstNode = line.find(isDefined);
if (firstNode === undefined) {
// unexpected case of no nodes on line
return [];
@@ -150,7 +151,7 @@ export function vmlFormat(view: EditorView): void {
const commandLine = docText.lineAt(firstNode.from);
- const filteredArray: SyntaxNode[] = line.filter((maybeNode): maybeNode is SyntaxNode => !!maybeNode);
+ const filteredArray: SyntaxNode[] = line.filter(isDefined);
const deletions: ChangeSpec[] = [];
// remove indentation at start of line
@@ -209,10 +210,7 @@ export function vmlFormat(view: EditorView): void {
return [...deletions, ...insertions];
});
- const changes = [
- ...commandIndentChangeMap.values(),
- ...maybeChanges.filter((maybeChange): maybeChange is ChangeSpec => !!maybeChange),
- ];
+ const changes = [...commandIndentChangeMap.values(), ...maybeChanges.filter(isDefined)];
// Consider delete end of line whitespace
// Consider alignment of comments
diff --git a/src/utilities/codemirror/vml/vmlTreeUtils.ts b/src/utilities/codemirror/vml/vmlTreeUtils.ts
index 353db0f5b7..177c59a22c 100644
--- a/src/utilities/codemirror/vml/vmlTreeUtils.ts
+++ b/src/utilities/codemirror/vml/vmlTreeUtils.ts
@@ -1,5 +1,10 @@
import type { SyntaxNode, Tree } from '@lezer/common';
-import { filterNodesToArray, getChildrenNode, getNearestAncestorNodeOfType } from '../../sequence-editor/tree-utils';
+import {
+ filterNodesToArray,
+ getChildrenNode,
+ getNearestAncestorNodeOfType,
+ isDefined,
+} from '../../sequence-editor/tree-utils';
import type { CommandInfoMapper } from '../commandInfoMapper';
import {
RULE_CALL_PARAMETER,
@@ -123,10 +128,6 @@ export class VmlCommandInfoMapper implements CommandInfoMapper {
}
}
-function isDefined(maybeValue: Type | null | undefined): maybeValue is Type {
- return maybeValue !== null && maybeValue !== undefined;
-}
-
export function getArgumentPosition(argNode: SyntaxNode): number {
return (
getNearestAncestorNodeOfType(argNode, [RULE_STATEMENT])
diff --git a/src/utilities/sequence-editor/tree-utils.ts b/src/utilities/sequence-editor/tree-utils.ts
index 6f8b58c5f2..5ecd03611c 100644
--- a/src/utilities/sequence-editor/tree-utils.ts
+++ b/src/utilities/sequence-editor/tree-utils.ts
@@ -93,3 +93,7 @@ export function filterNodesToArray(cursor: TreeCursor, filter?: (node: SyntaxNod
export function nodeContents(input: string, node: SyntaxNode): string {
return input.substring(node.from, node.to);
}
+
+export function isDefined(maybeValue: Type | null | undefined): maybeValue is Type {
+ return maybeValue !== null && maybeValue !== undefined;
+}