From 21977a601df4afea8f7c0dc16ce2e3a6333056dd Mon Sep 17 00:00:00 2001 From: David Evans Date: Mon, 30 Oct 2017 22:02:08 +0000 Subject: [PATCH] Highlight lines with syntax errors --- scripts/sequence/CodeMirrorMode.js | 41 +++++++++++++++++++----------- styles/main.css | 6 ++++- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/scripts/sequence/CodeMirrorMode.js b/scripts/sequence/CodeMirrorMode.js index b276690..defdc58 100644 --- a/scripts/sequence/CodeMirrorMode.js +++ b/scripts/sequence/CodeMirrorMode.js @@ -2,7 +2,8 @@ define(['core/ArrayUtilities'], (array) => { 'use strict'; const CM_END = {type: '', suggest: '\n', then: {}}; - const CM_ERROR = {type: 'error', then: {'': 0}}; + const CM_HIDDEN_END = {type: '', then: {}}; + const CM_ERROR = {type: 'error line-error', then: {'': 0}}; function makeCMCommaBlock(type, suggest, exits = {}) { return {type, suggest, then: Object.assign({ @@ -22,25 +23,26 @@ define(['core/ArrayUtilities'], (array) => { }); const CM_AGENT_TO_OPTTEXT = {type: 'variable', suggest: 'Agent', then: { '': 0, - ':': {type: 'operator', suggest: true, then: {'': CM_TEXT_TO_END}}, - '\n': CM_END, - }}; - - const CM_NOTE_SIDE_THEN = { - 'of': {type: 'keyword', suggest: true, then: { - '': CM_AGENT_LIST_TO_TEXT, - }}, ':': {type: 'operator', suggest: true, then: { '': CM_TEXT_TO_END, + '\n': CM_HIDDEN_END, }}, - '': CM_AGENT_LIST_TO_TEXT, - }; + '\n': CM_END, + }}; function makeCMSideNote(side) { return { type: 'keyword', suggest: [side + ' of ', side + ': '], - then: CM_NOTE_SIDE_THEN, + then: { + 'of': {type: 'keyword', suggest: true, then: { + '': CM_AGENT_LIST_TO_TEXT, + }}, + ':': {type: 'operator', suggest: true, then: { + '': CM_TEXT_TO_END, + }}, + '': CM_AGENT_LIST_TO_TEXT, + }, }; } @@ -61,7 +63,7 @@ define(['core/ArrayUtilities'], (array) => { '': 0, }}; - const CM_COMMANDS = {type: 'error', then: { + const CM_COMMANDS = {type: 'error line-error', then: { 'title': {type: 'keyword', suggest: true, then: { '': CM_TEXT_TO_END, }}, @@ -231,6 +233,10 @@ define(['core/ArrayUtilities'], (array) => { updateSuggestion(state, suggestions, '', {}); } state.nextCompletions = cmMakeCompletions(state, path); + state.valid = ( + Boolean(current.then['\n']) || + Object.keys(current.then).length === 0 + ); return current.type; } @@ -258,6 +264,7 @@ define(['core/ArrayUtilities'], (array) => { beginCompletions: cmMakeCompletions({}, [CM_COMMANDS]), completions: [], nextCompletions: [], + valid: true, line: [], indent: 0, }; @@ -336,10 +343,14 @@ define(['core/ArrayUtilities'], (array) => { if(stream.sol() && state.currentType === -1) { state.line.length = 0; } + let type = ''; if(state.currentType !== -1 || this._tokenBegin(stream, state)) { - return this._tokenEnd(stream, state); + type = this._tokenEnd(stream, state); + } + if(state.currentType === -1 && stream.eol() && !state.valid) { + return 'line-error ' + type; } else { - return null; + return type; } } diff --git a/styles/main.css b/styles/main.css index bbe8236..d53b9e5 100644 --- a/styles/main.css +++ b/styles/main.css @@ -17,6 +17,10 @@ html, body { background: #EEEEEE; } +.CodeMirror-line.error { + background: rgba(255, 0, 0, 0.2); +} + .cm-s-default .cm-keyword {color: #0055CC;} .cm-s-default .cm-variable {color: #AA5500;} .cm-s-default .cm-operator {color: #0055CC;} @@ -25,7 +29,7 @@ html, body { .cm-s-default .cm-error {color: #FF0000;} .cm-s-default .cm-trailingspace { - background: rgba(255, 0, 0, 0.5); + background: rgba(255, 0, 0, 0.2); } .pick-virtual {