Skip to content

Commit

Permalink
pull sequence adaptation store references from utility functions
Browse files Browse the repository at this point in the history
  • Loading branch information
duranb committed Feb 26, 2025
1 parent b3e0bcc commit 2c855a5
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 35 deletions.
17 changes: 13 additions & 4 deletions src/components/sequencing/SequenceEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import { debounce } from 'lodash-es';
import { createEventDispatcher, onDestroy, onMount } from 'svelte';
import {
getGlobals,
inputFormat,
outputFormat as outputFormatStore,
sequenceAdaptation,
Expand Down Expand Up @@ -46,7 +47,7 @@
import { blockTheme } from '../../utilities/codemirror/themes/block';
import effects from '../../utilities/effects';
import { downloadBlob, downloadJSON } from '../../utilities/generic';
import type { CommandInfoMapper } from '../../utilities/sequence-editor/commandInfoMapper';
import type { CommandInfoMapper } from '../../utilities/sequence-editor/command-info-mapper';
import { inputLinter, outputLinter } from '../../utilities/sequence-editor/extension-points';
import { setupLanguageSupport } from '../../utilities/sequence-editor/languages/seq-n/seq-n';
import {
Expand Down Expand Up @@ -258,14 +259,21 @@
),
compartmentSeqLinter.reconfigure(
inputLinter(
$sequenceAdaptation,
getGlobals(),
parsedChannelDictionary,
parsedCommandDictionary,
nonNullParsedParameterDictionaries,
librarySequences,
),
),
compartmentSeqTooltip.reconfigure(
sequenceTooltip(parsedChannelDictionary, parsedCommandDictionary, nonNullParsedParameterDictionaries),
sequenceTooltip(
$sequenceAdaptation,
parsedChannelDictionary,
parsedCommandDictionary,
nonNullParsedParameterDictionaries,
),
),
...($sequenceAdaptation.autoIndent
? [compartmentSeqAutocomplete.reconfigure(indentService.of($sequenceAdaptation.autoIndent()))]
Expand Down Expand Up @@ -310,6 +318,7 @@
commandDef?.arguments,
undefined,
parameterDictionaries,
$sequenceAdaptation,
);
$: variablesInScope = getVariablesInScope(
commandInfoMapper,
Expand All @@ -335,8 +344,8 @@
EditorView.theme({ '.cm-gutter': { 'min-height': '0px' } }),
lintGutter(),
compartmentSeqLanguage.of(setupLanguageSupport($sequenceAdaptation.autoComplete(null, null, [], []))),
compartmentSeqLinter.of(inputLinter()),
compartmentSeqTooltip.of(sequenceTooltip()),
compartmentSeqLinter.of(inputLinter($sequenceAdaptation, getGlobals())),
compartmentSeqTooltip.of(sequenceTooltip($sequenceAdaptation)),
EditorView.updateListener.of(debounce(sequenceUpdateListener, 250)),
EditorView.updateListener.of(selectedCommandUpdateListener),
blockTheme,
Expand Down
2 changes: 2 additions & 0 deletions src/components/sequencing/SequenceForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { base } from '$app/paths';
import type { ParameterDictionary } from '@nasa-jpl/aerie-ampcs';
import { SearchParameters } from '../../enums/searchParameters';
import { sequenceAdaptation } from '../../stores/sequence-adaptation';
import {
parameterDictionaries as parameterDictionariesStore,
parcelToParameterDictionaries,
Expand Down Expand Up @@ -118,6 +119,7 @@
fileNameAndContents.contents,
parsedParameterDictionaries.filter((pd): pd is ParameterDictionary => pd !== null),
parsedChannelDictionary,
$sequenceAdaptation,
);
if (sequence !== undefined) {
Expand Down
22 changes: 12 additions & 10 deletions src/types/sequencing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ export interface IOutputFormat {
): Promise<string>;
}

export interface IInputFormat {
linter?: (
diagnostics: Diagnostic[],
commandDictionary: AmpcsCommandDictionary,
view: EditorView,
node: SyntaxNode,
) => Diagnostic[];
name: string;
toInputFormat?(input: string): Promise<string>;
}

export interface ISequenceAdaptation {
argDelegator?: ArgDelegator;
autoComplete: (
Expand All @@ -78,16 +89,7 @@ export interface ISequenceAdaptation {
) => (context: CompletionContext) => CompletionResult | null;
autoIndent?: () => (context: IndentContext, pos: number) => number | null | undefined;
globals?: GlobalType[];
inputFormat: {
linter?: (
diagnostics: Diagnostic[],
commandDictionary: AmpcsCommandDictionary,
view: EditorView,
node: SyntaxNode,
) => Diagnostic[];
name: string;
toInputFormat?(input: string): Promise<string>;
};
inputFormat: IInputFormat;
modifyOutput?: (
output: string,
parameterDictionaries: AmpcsParameterDictionary[],
Expand Down
32 changes: 22 additions & 10 deletions src/utilities/sequence-editor/extension-points.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import {
type FswCommandArgument,
type ParameterDictionary,
} from '@nasa-jpl/aerie-ampcs';
import { get } from 'svelte/store';
import { inputFormat, sequenceAdaptation } from '../../stores/sequence-adaptation';
import type { IOutputFormat, LibrarySequence } from '../../types/sequencing';
import type { GlobalType } from '../../types/global-type';
import type { IInputFormat, IOutputFormat, ISequenceAdaptation, LibrarySequence } from '../../types/sequencing';
import { seqJsonLinter } from './seq-json-linter';
import { sequenceLinter } from './sequence-linter';

Expand Down Expand Up @@ -38,11 +37,12 @@ export function getCustomArgDef(
precedingArgs: string[],
parameterDictionaries: ParameterDictionary[],
channelDictionary: ChannelDictionary | null,
sequenceAdaptation?: ISequenceAdaptation,
) {
let delegate = undefined;

if (get(sequenceAdaptation).argDelegator !== undefined) {
delegate = get(sequenceAdaptation).argDelegator?.[stem]?.[dictArg.name];
if (sequenceAdaptation?.argDelegator !== undefined) {
delegate = sequenceAdaptation.argDelegator?.[stem]?.[dictArg.name];
}

return delegate?.(dictArg, parameterDictionaries, channelDictionary, precedingArgs) ?? dictArg;
Expand All @@ -52,8 +52,10 @@ export async function toInputFormat(
output: string,
parameterDictionaries: ParameterDictionary[],
channelDictionary: ChannelDictionary | null,
sequenceAdaptation: ISequenceAdaptation,
inputFormat?: IInputFormat,
) {
const modifyOutputParse = get(sequenceAdaptation).modifyOutputParse;
const modifyOutputParse = sequenceAdaptation.modifyOutputParse;
if (modifyOutputParse !== undefined) {
let modifiedOutput = await modifyOutputParse(output, parameterDictionaries, channelDictionary);
if (modifiedOutput === null) {
Expand All @@ -66,10 +68,10 @@ export async function toInputFormat(
modifiedOutput = `${modifiedOutput}`;
}

return (await get(inputFormat)?.toInputFormat?.(modifiedOutput)) ?? output;
return (await inputFormat?.toInputFormat?.(modifiedOutput)) ?? output;
} else {
try {
return (await get(inputFormat)?.toInputFormat?.(output)) ?? output;
return (await inputFormat?.toInputFormat?.(output)) ?? output;
} catch (e) {
console.error(e);
return output;
Expand All @@ -78,18 +80,28 @@ export async function toInputFormat(
}

export function inputLinter(
sequenceAdaptation: ISequenceAdaptation,
globalVariables: GlobalType[],
channelDictionary: ChannelDictionary | null = null,
commandDictionary: CommandDictionary | null = null,
parameterDictionaries: ParameterDictionary[] = [],
librarySequences: LibrarySequence[] = [],
): Extension {
return linter(view => {
const inputFormatLinter = get(sequenceAdaptation).inputFormat.linter;
const inputFormatLinter = sequenceAdaptation.inputFormat.linter;
const tree = syntaxTree(view.state);
const treeNode = tree.topNode;
let diagnostics: Diagnostic[];

diagnostics = sequenceLinter(view, channelDictionary, commandDictionary, parameterDictionaries, librarySequences);
diagnostics = sequenceLinter(
view,
sequenceAdaptation,
channelDictionary,
commandDictionary,
parameterDictionaries,
librarySequences,
globalVariables,
);

if (inputFormatLinter !== undefined && commandDictionary !== null) {
diagnostics = inputFormatLinter(diagnostics, commandDictionary, view, treeNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
import { SequenceTypes } from '../../../../enums/sequencing';
import { type LibrarySequence, type UserSequence } from '../../../../types/sequencing';
import { fswCommandArgDefault } from '../../command-dictionary';
import type { CommandInfoMapper } from '../../commandInfoMapper';
import type { CommandInfoMapper } from '../../command-info-mapper';
import { validateVariables } from '../../sequence-linter';
import { parseVariables } from '../../to-seq-json';
import { getFromAndTo, getNearestAncestorNodeOfType } from '../../tree-utils';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { SyntaxNode, Tree } from '@lezer/common';
import type { EnumMap, FswCommandArgument } from '@nasa-jpl/aerie-ampcs';
import { filterEmpty } from '../../../generic';
import type { CommandInfoMapper } from '../../commandInfoMapper';
import type { CommandInfoMapper } from '../../command-info-mapper';
import { filterNodesToArray, getChildrenNode, getNearestAncestorNodeOfType } from '../../tree-utils';
import { getDefaultArgumentValue } from './vml-adaptation';
import {
Expand Down
21 changes: 18 additions & 3 deletions src/utilities/sequence-editor/sequence-completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { syntaxTree } from '@codemirror/language';
import type { ChannelDictionary, CommandDictionary, ParameterDictionary } from '@nasa-jpl/aerie-ampcs';
import { RULE_SEQUENCE_NAME, TOKEN_ACTIVATE, TOKEN_LOAD } from '../../constants/seq-n-grammar-constants';
import { getGlobals } from '../../stores/sequence-adaptation';
import type { LibrarySequence } from '../../types/sequencing';
import type { ISequenceAdaptation, LibrarySequence } from '../../types/sequencing';
import { getDoyTime } from '../time';
import { fswCommandArgDefault } from './command-dictionary';
import { getCustomArgDef } from './extension-points';
Expand Down Expand Up @@ -31,6 +31,7 @@ export function sequenceCompletion(
commandDictionary: CommandDictionary | null = null,
parameterDictionaries: ParameterDictionary[],
librarySequences: LibrarySequence[],
sequenceAdaptation?: ISequenceAdaptation,
) {
return (context: CompletionContext): CompletionResult | null => {
const nodeBefore = syntaxTree(context.state).resolveInner(context.pos, -1);
Expand Down Expand Up @@ -245,7 +246,13 @@ export function sequenceCompletion(
// If TimeTag has been entered show the completion list when 1 character has been entered
if (word.text.length > (cursor.isAfterTimeTag || cursor.isBeforeImmedOrHDWCommands === false ? 0 : 1)) {
fswCommandsCompletions.push(
...generateCommandCompletions(channelDictionary, commandDictionary, cursor, parameterDictionaries),
...generateCommandCompletions(
channelDictionary,
commandDictionary,
cursor,
parameterDictionaries,
sequenceAdaptation,
),
);

//add load, activate, ground_block, and ground_event commands
Expand Down Expand Up @@ -337,6 +344,7 @@ function generateCommandCompletions(
commandDictionary: CommandDictionary | null,
cursor: CursorInfo,
parameterDictionaries: ParameterDictionary[],
sequenceAdaptation?: ISequenceAdaptation,
): Completion[] {
if (commandDictionary === null) {
return [];
Expand All @@ -357,7 +365,14 @@ function generateCommandCompletions(
args.forEach(arg => {
argDefaults.push(
fswCommandArgDefault(
getCustomArgDef(stem, arg, argDefaults.slice(), parameterDictionaries, channelDictionary),
getCustomArgDef(
stem,
arg,
argDefaults.slice(),
parameterDictionaries,
channelDictionary,
sequenceAdaptation,
),
commandDictionary.enumMap,
),
);
Expand Down
Loading

0 comments on commit 2c855a5

Please sign in to comment.