Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

form editor, disabled download button, nested grid which may have roo… #1213

Merged
merged 8 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion codemirror-lang-sequence/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"build": "npm run clean && rollup -c",
"clean": "rm -rf dist",
"postinstall": "npm run build",
"test": "npm run build && mocha test/test.js"
"test": "npm run build && mocha test/*.js"
},
"dependencies": {
"@codemirror/autocomplete": "^6.15.0",
Expand Down
1 change: 1 addition & 0 deletions codemirror-lang-sequence/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const SeqLanguage = LRLanguage.define({
}),
styleTags({
Boolean: t.bool,
GenericDirective: t.namespace,
Global: t.namespace,
HardwareCommands: t.namespace,
IdDeclaration: t.namespace,
Expand Down
23 changes: 12 additions & 11 deletions codemirror-lang-sequence/src/sequence.grammar
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
@top Sequence {
(newLine | whiteSpace)?
commentLine* ~maybeComments
IdDeclaration?
commentLine* ~maybeComments
ParameterDeclaration?
commentLine* ~maybeComments
LocalDeclaration?
(
commentLine* ~maybeComments
(IdDeclaration | ParameterDeclaration | LocalDeclaration | GenericDirective)
)*
commentLine* ~maybeComments
Metadata?
Commands?
Expand All @@ -14,14 +12,17 @@
}

// Potential Improvements
// flexibility - allow indentation of directives
// maintainability - use @specialize on directives
// extensibility - add generic Directive { "@"identifier }
// expressiveness - add activate, load and ground syntax

@precedence {
stemStart @cut
}

GenericDirective {
genericDirective (whiteSpace String)* newLine
}

IdDeclaration {
idDirective whiteSpace String newLine
}
Expand Down Expand Up @@ -148,10 +149,9 @@ Stem { !stemStart identifier }
parameterDirective { "@INPUT_PARAMS" }
metadataDirective { "@METADATA" }
modelDirective { "@MODEL" }
genericDirective { "@"identifier }

@precedence {
newLine, whiteSpace
}
@precedence { newLine, whiteSpace }

@precedence{ TimeAbsolute, TimeRelative, TimeEpoch, TimeComplete, identifier }

Expand All @@ -164,6 +164,7 @@ Stem { !stemStart identifier }
localsDirective,
parameterDirective,
LoadAndGoDirective,
genericDirective,
identifier
}
}
8 changes: 8 additions & 0 deletions codemirror-lang-sequence/test/cases/errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,11 @@ Sequence(Commands(
Command(Stem,Args(RepeatArg(⚠))),
Command(Stem,Args(RepeatArg(⚠,Enum)))
))

# locals with wrong value types

@LOCALS "string_not_enum"

==>

Sequence(LocalDeclaration(⚠(String)))
16 changes: 16 additions & 0 deletions codemirror-lang-sequence/test/cases/parse_tree.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ Sequence(
)
)

# Generic directive

@WRONG_LOAD_AND_GO

C CMD_1

==>

Sequence(
GenericDirective,
Commands(
Command(TimeTag(TimeComplete),Stem,Args)
)
)


# Command with two string args

FSW_CMD "hello" "world"
Expand Down
7 changes: 4 additions & 3 deletions codemirror-lang-sequence/test/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('error positions', () => {
testname: 'bad number arg',
},
{
first_error: 20,
first_error: 24,
input: `COM 12345
COM "dsa"
@UNKNOWN DIRECTIVE`,
Expand All @@ -58,7 +58,9 @@ describe('error positions', () => {
describe('seqfiles', () => {
const seqDir = path.dirname(fileURLToPath(import.meta.url)) + '/sequences';
for (const file of readdirSync(seqDir)) {
if (!/\.txt$/.test(file)) {continue};
if (!/\.txt$/.test(file)) {
continue;
}

const name = /^[^.]*/.exec(file)[0];
it(name, () => {
Expand Down Expand Up @@ -91,7 +93,6 @@ CMD0
return {
from,
to: from + nodeText.length,

};
};
const expectedCommentLocations = {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"d3-selection": "^3.0.0",
"d3-shape": "^3.2.0",
"d3-time": "^3.1.0",
"fastest-levenshtein": "^1.0.16",
"graphql-ws": "^5.14.0",
"json-source-map": "^0.6.1",
"jszip": "^3.10.1",
Expand Down
2 changes: 1 addition & 1 deletion src/components/sequencing/CommandTooltip.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

export let command: FswCommand | HwCommand;

let commandExample: string;
$: commandExample = command.stem;

$: if (command.type === 'hw_command') {
commandExample = command.stem;
Expand Down
82 changes: 51 additions & 31 deletions src/components/sequencing/SequenceEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
import { lintGutter } from '@codemirror/lint';
import { Compartment, EditorState } from '@codemirror/state';
import type { ViewUpdate } from '@codemirror/view';
import type { SyntaxNode } from '@lezer/common';
import type { CommandDictionary } from '@nasa-jpl/aerie-ampcs';
import { EditorView, basicSetup } from 'codemirror';
import { seq } from 'codemirror-lang-sequence';
import { debounce } from 'lodash-es';
import { createEventDispatcher, onMount } from 'svelte';
import { commandDictionaries, userSequencesRows } from '../../stores/sequencing';
import { commandDictionaries, userSequenceEditorColumns, userSequencesRows } from '../../stores/sequencing';
import type { User } from '../../types/app';
import effects from '../../utilities/effects';
import { seqJsonLinter } from '../../utilities/new-sequence-editor/seq-json-linter';
Expand All @@ -23,6 +24,7 @@
import CssGridGutter from '../ui/CssGridGutter.svelte';
import Panel from '../ui/Panel.svelte';
import SectionTitle from '../ui/SectionTitle.svelte';
import SelectedCommand from './form/selected-command.svelte';

export let readOnly: boolean = false;
export let sequenceCommandDictionaryId: number | null = null;
Expand All @@ -48,6 +50,7 @@
let editorSeqJsonView: EditorView;
let editorSequenceDiv: HTMLDivElement;
let editorSequenceView: EditorView;
let selectedNode: SyntaxNode | null;

$: {
if (editorSequenceView) {
Expand Down Expand Up @@ -122,8 +125,15 @@
editorSeqJsonView.dispatch({ changes: { from: 0, insert: seqJsonStr, to: editorSeqJsonView.state.doc.length } });

dispatch('sequence', sequence);

const updatedSelectionNode = tree.resolveInner(viewUpdate.state.selection.asSingle().main.from, -1);
// minimize triggering selected command view
if (selectedNode !== updatedSelectionNode) {
selectedNode = updatedSelectionNode;
}
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
function downloadSeqJson() {
const a = document.createElement('a');
a.href = URL.createObjectURL(new Blob([sequenceDefinition], { type: 'application/json' }));
Expand All @@ -132,34 +142,44 @@
}
</script>

<CssGrid bind:rows={$userSequencesRows} minHeight={'0'}>
<Panel>
<svelte:fragment slot="header">
<SectionTitle>{title}</SectionTitle>

<div class="right">
<slot />
</div>
</svelte:fragment>

<svelte:fragment slot="body">
<div bind:this={editorSequenceDiv} />
</svelte:fragment>
</Panel>

<CssGridGutter track={1} type="row" />

<Panel>
<svelte:fragment slot="header">
<SectionTitle>Seq JSON (Read-only)</SectionTitle>

<div class="right">
<button class="st-button secondary ellipsis" on:click={downloadSeqJson}>Download</button>
</div>
</svelte:fragment>

<svelte:fragment slot="body">
<div bind:this={editorSeqJsonDiv} />
</svelte:fragment>
</Panel>
<CssGrid bind:columns={$userSequenceEditorColumns} minHeight={'0'}>
<CssGrid bind:rows={$userSequencesRows} minHeight={'0'}>
<Panel>
<svelte:fragment slot="header">
<SectionTitle>{title}</SectionTitle>

<div class="right">
<slot />
</div>
</svelte:fragment>

<svelte:fragment slot="body">
<div bind:this={editorSequenceDiv} />
</svelte:fragment>
</Panel>

<CssGridGutter track={1} type="row" />

<Panel>
<svelte:fragment slot="header">
<SectionTitle>Seq JSON (Read-only)</SectionTitle>

<!-- <div class="right">
<button class="st-button secondary ellipsis" on:click={downloadSeqJson}>Download</button>
</div> -->
</svelte:fragment>

<svelte:fragment slot="body">
<div bind:this={editorSeqJsonDiv} />
</svelte:fragment>
</Panel>
</CssGrid>

<CssGridGutter track={1} type="column" />

{#if !!commandDictionary && !!selectedNode}
<SelectedCommand node={selectedNode} {commandDictionary} {editorSequenceView} />
{:else}
<div>Selected Command</div>
{/if}
</CssGrid>
3 changes: 2 additions & 1 deletion src/components/sequencing/SequenceForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
loadAdaptation(adaptation);
});

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async function getUserSequenceFromSeqJson() {
const file: File = seqJsonFiles[0];
const text = await file.text();
Expand Down Expand Up @@ -256,7 +257,7 @@
}}
/>
</fieldset>
<!--
<!--
<fieldset>
<label for="seqJsonFile">Create Sequence from Seq JSON (optional)</label>
<input
Expand Down
11 changes: 11 additions & 0 deletions src/components/sequencing/form/add-missing-args-button.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<svelte:options immutable={true} />

<script lang="ts">
export let setInEditor: () => void;
</script>

<div>
<button on:click={setInEditor}>
Add Missing Arguments
</button>
</div>
Loading