Skip to content

Commit

Permalink
feat: allow to provide dialect
Browse files Browse the repository at this point in the history
This enables me as a user to specify the FEEL dialect to use,
one of `expression` or `unaryTests`.
  • Loading branch information
nikku committed Jun 4, 2024
1 parent 875f05a commit c0aaf53
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 6 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,16 @@ const editor = new FeelEditor({
});
```

Optionally, you can provide a starting document and listen for changes:
Configure the FEEL dialect (expression or unary tests):

```JavaScript
const editor = new FeelEditor({
container,
dialect: 'unaryTests' // defaults to 'expression'
});
```

You can provide a starting document and listen for changes:

```JavaScript
const editor = new FeelEditor({
Expand Down
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const placeholderConf = new Compartment();
* @param {Object} config
* @param {DOMNode} config.container
* @param {Extension[]} [config.extensions]
* @param {'expression' | 'unaryTests'} [config.dialect='expression']
* @param {DOMNode|String} [config.tooltipContainer]
* @param {Function} [config.onChange]
* @param {Function} [config.onKeyDown]
Expand All @@ -44,6 +45,7 @@ const placeholderConf = new Compartment();
*/
export default function FeelEditor({
extensions: editorExtensions = [],
dialect = 'expression',
container,
contentAttributes = {},
tooltipContainer,
Expand Down Expand Up @@ -104,7 +106,9 @@ export default function FeelEditor({
keymap.of([
...defaultKeymap,
]),
language(),
language({
dialect
}),
linter,
lintHandler,
placeholderConf.of(placeholderExt(placeholder)),
Expand Down
12 changes: 8 additions & 4 deletions src/language/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { LanguageSupport } from '@codemirror/language';
import { feelLanguage } from 'lang-feel';
import { feel } from 'lang-feel';

export function language() {
return new LanguageSupport(feelLanguage, [ ]);
/**
* @param {'expression' | 'unaryTests'} dialect
*
* @return {LanguageSupport}
*/
export function language(dialect) {
return feel(dialect);
}
50 changes: 50 additions & 0 deletions test/spec/CodeEditor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,22 @@ return
});


it('should configure <unaryTests> dialect', async function() {

// when
const initialValue = '"Hello", "World"';
const editor = new FeelEditor({
container,
value: initialValue,
dialect: 'unaryTests'
});

// then
expect(editor).to.exist;
expect(editor._cmEditor.state.doc.toString()).to.equal('"Hello", "World"');
});


it('should allow for extensions', async function() {

// when
Expand Down Expand Up @@ -520,6 +536,40 @@ return
});


describe('should not highlight valid', function() {

[
{ dialect: 'expression', value: 'Mike < 10' },
{ dialect: 'unaryTests', value: '12, now(), "STRING"' }
].forEach(({ dialect, value }) => {

it(`<${dialect}>`, function(done) {

// given
const editor = new FeelEditor({
container,
value,
dialect
});

const cm = getCm(editor);

// when
forceLinting(cm);

// then
// update done async
setTimeout(() => {
expect(diagnosticCount(cm.state)).to.eql(0);
done();
}, 0);
});

});

});


it('should highlight unexpected operations', function(done) {
const initalValue = '= 15';

Expand Down

0 comments on commit c0aaf53

Please sign in to comment.