From 64e3f6aa0362bdfeaa4ed18adbf5aab17bebd965 Mon Sep 17 00:00:00 2001 From: David Evans Date: Sun, 21 Jan 2018 00:44:52 +0000 Subject: [PATCH] Fix autocomplete for multi-word names, and minor tweaks. Add testing for CodeMirror integration [#34] --- lib/sequence-diagram.js | 376 +++++++++++------ lib/sequence-diagram.min.js | 2 +- scripts/sequence/CodeMirrorHints.js | 166 ++++++-- scripts/sequence/CodeMirrorMode.js | 210 ++++++---- scripts/sequence/CodeMirrorMode_spec.js | 521 ++++++++++++++++++++++++ scripts/specs.js | 1 + test.htm | 6 + 7 files changed, 1029 insertions(+), 253 deletions(-) create mode 100644 scripts/sequence/CodeMirrorMode_spec.js diff --git a/lib/sequence-diagram.js b/lib/sequence-diagram.js index f6e3e86..1d313af 100644 --- a/lib/sequence-diagram.js +++ b/lib/sequence-diagram.js @@ -626,32 +626,44 @@ define('sequence/CodeMirrorMode',['core/ArrayUtilities'], (array) => { const end = {type: '', suggest: '\n', then: {}}; const hiddenEnd = {type: '', then: {}}; - function textTo(exit) { - return {type: 'string', then: Object.assign({'': 0}, exit)}; + function textTo(exit, suggest) { + return { + type: 'string', + suggest, + then: Object.assign({'': 0}, exit), + }; } const textToEnd = textTo({'\n': end}); - const aliasListToEnd = {type: 'variable', suggest: 'Agent', then: { - '': 0, - '\n': end, - ',': {type: 'operator', suggest: true, then: {'': 1}}, - 'as': {type: 'keyword', suggest: true, then: { - '': {type: 'variable', suggest: 'Agent', then: { - '': 0, - ',': {type: 'operator', suggest: true, then: {'': 3}}, - '\n': end, + const aliasListToEnd = { + type: 'variable', + suggest: {known: 'Agent'}, + then: { + '': 0, + '\n': end, + ',': {type: 'operator', suggest: true, then: {'': 1}}, + 'as': {type: 'keyword', suggest: true, then: { + '': {type: 'variable', suggest: {known: 'Agent'}, then: { + '': 0, + ',': {type: 'operator', suggest: true, then: {'': 3}}, + '\n': end, + }}, }}, - }}, - }}; + }, + }; function agentListTo(exit) { - return {type: 'variable', suggest: 'Agent', then: Object.assign({}, - exit, - { - '': 0, - ',': {type: 'operator', suggest: true, then: {'': 1}}, - } - )}; + return { + type: 'variable', + suggest: {known: 'Agent'}, + then: Object.assign({}, + exit, + { + '': 0, + ',': {type: 'operator', suggest: true, then: {'': 1}}, + } + ), + }; } const colonTextToEnd = { @@ -662,32 +674,50 @@ define('sequence/CodeMirrorMode',['core/ArrayUtilities'], (array) => { const agentListToText = agentListTo({ ':': colonTextToEnd, }); - const agentList2ToText = {type: 'variable', suggest: 'Agent', then: { - '': 0, - ',': {type: 'operator', suggest: true, then: {'': agentListToText}}, - ':': CM_ERROR, - }}; - const singleAgentToText = {type: 'variable', suggest: 'Agent', then: { - '': 0, - ',': CM_ERROR, - ':': colonTextToEnd, - }}; - const agentToOptText = {type: 'variable', suggest: 'Agent', then: { - '': 0, - ':': {type: 'operator', suggest: true, then: { - '': textToEnd, - '\n': hiddenEnd, - }}, - '\n': end, - }}; + const agentList2ToText = { + type: 'variable', + suggest: {known: 'Agent'}, + then: { + '': 0, + ',': {type: 'operator', suggest: true, then: { + '': agentListToText, + }}, + ':': CM_ERROR, + }, + }; + const singleAgentToText = { + type: 'variable', + suggest: {known: 'Agent'}, + then: { + '': 0, + ',': CM_ERROR, + ':': colonTextToEnd, + }, + }; + const agentToOptText = { + type: 'variable', + suggest: {known: 'Agent'}, + then: { + '': 0, + ':': {type: 'operator', suggest: true, then: { + '': textToEnd, + '\n': hiddenEnd, + }}, + '\n': end, + }, + }; const referenceName = { ':': {type: 'operator', suggest: true, then: { '': textTo({ 'as': {type: 'keyword', suggest: true, then: { - '': {type: 'variable', suggest: 'Agent', then: { - '': 0, - '\n': end, - }}, + '': { + type: 'variable', + suggest: {known: 'Agent'}, + then: { + '': 0, + '\n': end, + }, + }, }}, }), }}, @@ -774,7 +804,7 @@ define('sequence/CodeMirrorMode',['core/ArrayUtilities'], (array) => { then: {}, }; return makeOpBlock( - {type: 'variable', suggest: 'Agent', then}, + {type: 'variable', suggest: {known: 'Agent'}, then}, then ); } @@ -868,12 +898,16 @@ define('sequence/CodeMirrorMode',['core/ArrayUtilities'], (array) => { }}, 'autolabel': {type: 'keyword', suggest: true, then: { 'off': {type: 'keyword', suggest: true, then: {}}, - '': textToEnd, + '': textTo({'\n': end}, [ + {v: '