diff --git a/src/legacy/core_plugins/console/public/quarantined/src/sense_editor/mode/input_highlight_rules.js b/src/legacy/core_plugins/console/public/quarantined/src/sense_editor/mode/input_highlight_rules.js index 74384d2621ad5..17c1e3876f076 100644 --- a/src/legacy/core_plugins/console/public/quarantined/src/sense_editor/mode/input_highlight_rules.js +++ b/src/legacy/core_plugins/console/public/quarantined/src/sense_editor/mode/input_highlight_rules.js @@ -36,12 +36,17 @@ export function mergeTokens(/* ... */) { const oop = ace.acequire('ace/lib/oop'); const { TextHighlightRules } = ace.acequire('ace/mode/text_highlight_rules'); -export function InputHighlightRules() { +export function InputHighlightRules() { // regexp must not have capturing parentheses. Use (?:) instead. // regexps are ordered -> the first match is used /*jshint -W015 */ this.$rules = { + 'start-sql': [ + { token: 'whitespace', regex: '\\s+' }, + { token: 'paren.lparen', regex: '{', next: 'json-sql', push: true }, + { regex: '', next: 'start' } + ], 'start': mergeTokens([ { 'token': 'warning', 'regex': '#!.*$' }, { token: 'comment', regex: /^#.*$/ }, @@ -66,6 +71,7 @@ export function InputHighlightRules() { addEOL(['whitespace'], /(\s+)/, 'start', 'url') ), 'url': mergeTokens( + addEOL(['url.part'], /(_sql)/, 'start-sql', 'url-sql'), addEOL(['url.part'], /([^?\/,\s]+)/, 'start'), addEOL(['url.comma'], /(,)/, 'start'), addEOL(['url.slash'], /(\/)/, 'start'), @@ -75,7 +81,17 @@ export function InputHighlightRules() { addEOL(['url.param', 'url.equal', 'url.value'], /([^&=]+)(=)([^&]*)/, 'start'), addEOL(['url.param'], /([^&=]+)/, 'start'), addEOL(['url.amp'], /(&)/, 'start') - ) + ), + 'url-sql': mergeTokens( + addEOL(['url.comma'], /(,)/, 'start-sql'), + addEOL(['url.slash'], /(\/)/, 'start-sql'), + addEOL(['url.questionmark'], /(\?)/, 'start-sql', 'urlParams-sql') + ), + 'urlParams-sql': mergeTokens( + addEOL(['url.param', 'url.equal', 'url.value'], /([^&=]+)(=)([^&]*)/, 'start-sql'), + addEOL(['url.param'], /([^&=]+)/, 'start-sql'), + addEOL(['url.amp'], /(&)/, 'start-sql') + ), }; addToRules(this); diff --git a/src/legacy/core_plugins/console/public/quarantined/src/sense_editor/mode/x_json_highlight_rules.js b/src/legacy/core_plugins/console/public/quarantined/src/sense_editor/mode/x_json_highlight_rules.js index 674a682551f47..8e39ea0acba10 100644 --- a/src/legacy/core_plugins/console/public/quarantined/src/sense_editor/mode/x_json_highlight_rules.js +++ b/src/legacy/core_plugins/console/public/quarantined/src/sense_editor/mode/x_json_highlight_rules.js @@ -18,15 +18,15 @@ */ import ace from 'brace'; +const _ = require('lodash'); const { SqlHighlightRules } = ace.acequire('ace/mode/sql_highlight_rules'); -const _ = require('lodash'); -const ScriptHighlightRules = require('./script_highlight_rules').ScriptHighlightRules; +const { ScriptHighlightRules } = require('./script_highlight_rules'); const jsonRules = function (root) { root = root ? root : 'json'; const rules = {}; - rules[root] = [ + const xJsonRules = [ { token: ['variable', 'whitespace', 'ace.punctuation.colon', 'whitespace', 'punctuation.start_triple_quote'], regex: '("(?:[^"]*_)?script"|"inline"|"source")(\\s*?)(:)(\\s*?)(""")', @@ -34,13 +34,6 @@ const jsonRules = function (root) { merge: false, push: true }, - { - token: 'punctuation.start_triple_quote', - regex: '"""sql', - next: 'sql-start', - merge: false, - push: true - }, { token: 'variable', // single line regex: '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]\\s*(?=:)' @@ -116,6 +109,16 @@ const jsonRules = function (root) { regex: '.+?' } ]; + + rules[root] = xJsonRules; + rules[root + '-sql'] = [{ + token: ['variable', 'whitespace', 'ace.punctuation.colon', 'whitespace', 'punctuation.start_triple_quote'], + regex: '("query")(\\s*?)(:)(\\s*?)(""")', + next: 'sql-start', + merge: false, + push: true + }].concat(xJsonRules); + rules.string_literal = [ { token: 'punctuation.end_triple_quote', diff --git a/src/legacy/core_plugins/console/public/quarantined/src/sense_editor/row_parser.js b/src/legacy/core_plugins/console/public/quarantined/src/sense_editor/row_parser.js index c1bba107de784..f1e3268454d52 100644 --- a/src/legacy/core_plugins/console/public/quarantined/src/sense_editor/row_parser.js +++ b/src/legacy/core_plugins/console/public/quarantined/src/sense_editor/row_parser.js @@ -48,7 +48,7 @@ function RowParser(editor) { return MODE.BETWEEN_REQUESTS; } // shouldn't really happen - if (mode !== 'start') { + if (mode !== 'start' && mode !== 'start-sql') { return MODE.IN_REQUEST; } let line = (session.getLine(row) || '').trim(); diff --git a/src/legacy/core_plugins/console/public/quarantined/src/utils.js b/src/legacy/core_plugins/console/public/quarantined/src/utils.js index ee1b91595e7ec..5b6bd1646c300 100644 --- a/src/legacy/core_plugins/console/public/quarantined/src/utils.js +++ b/src/legacy/core_plugins/console/public/quarantined/src/utils.js @@ -59,7 +59,7 @@ utils.reformatData = function (data, indent) { }; utils.collapseLiteralStrings = function (data) { - const splitData = data.replace(/"""sql/, `"""`).split(`"""`); + const splitData = data.split(`"""`); for (let idx = 1; idx < splitData.length - 1; idx += 2) { splitData[idx] = JSON.stringify(splitData[idx]); } diff --git a/src/legacy/core_plugins/console/public/quarantined/tests/src/setup_mocks.js b/src/legacy/core_plugins/console/public/quarantined/tests/src/setup_mocks.js index 203d8a20b1055..f988eae946d91 100644 --- a/src/legacy/core_plugins/console/public/quarantined/tests/src/setup_mocks.js +++ b/src/legacy/core_plugins/console/public/quarantined/tests/src/setup_mocks.js @@ -43,6 +43,7 @@ import 'brace'; import 'brace/ext/language_tools'; import 'brace/ext/searchbox'; import 'brace/mode/json'; +import 'brace/mode/sql'; import 'brace/mode/text'; jest.mock('../../../../np_ready/public/application', () => ({ legacyBackDoorToSettings: () => {}, })); diff --git a/x-pack/legacy/plugins/console_extensions/spec/overrides/sql.query.json b/x-pack/legacy/plugins/console_extensions/spec/overrides/sql.query.json index 0baebcf9c7a80..843fba30bb489 100644 --- a/x-pack/legacy/plugins/console_extensions/spec/overrides/sql.query.json +++ b/x-pack/legacy/plugins/console_extensions/spec/overrides/sql.query.json @@ -4,7 +4,7 @@ "query": { "__template": { "__raw": true, - "value": "\"\"\"sql\nSELECT * FROM \"TABLE\"\n\"\"\"" + "value": "\"\"\"\nSELECT * FROM \"TABLE\"\n\"\"\"" } } }, @@ -19,6 +19,6 @@ "smile" ] }, - "template": "_sql?format=json\n{\n\"query\":\n \"\"\"sql\n SELECT * FROM \"TABLE\"\n \"\"\"\n}\n" + "template": "_sql?format=json\n{\n \"query\": \"\"\"\n SELECT * FROM \"${1:TABLE}\"\n \"\"\"\n}\n" } }