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
Make Console Script Aware #9433
Conversation
Here is the master list: https://github.com/elastic/elasticsearch/blob/master/modules/lang-painless/src/main/antlr/PainlessLexer.g4#L43-L57 |
Once we get this in I can modify the tool that extract CONSOLE syntax out of Elasticsearch's docs and we can use this in the docs. Much awesome! |
|
That'd be cool. We could add an endpoint that you could use to look them up if we wanted to get fancy. |
this.$outdent.autoOutdent(doc, row); | ||
}; | ||
|
||
// this.createWorker = function (session) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this code isn't in use, just remove it rather than commenting it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left overs indeed. removed.
@@ -20,6 +21,9 @@ var Mode = function () { | |||
this.$outdent = new MatchingBraceOutdent(); | |||
this.$behaviour = new CstyleBehaviour(); | |||
this.foldingRules = new CStyleFoldMode(); | |||
this.createModeDelegates({ | |||
"script-": ScriptMode | |||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove the extra indents here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure thing
if (state != "double_q_string") { | ||
if (state == "string_literal") { | ||
// noop | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a noop, why not just if (state !== 'string_literal') {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
uiModules.get('app/sense').setupResizeCheckerForRootEditors($el, input, output); | ||
// this may not exist if running from tests | ||
let appSense = uiModules.get('app/sense'); | ||
if (appSense.setupResizeCheckerForRootEditors) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we mock this in the tests rather than altering the code to accommodate the tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the extra check and everything seems to work fine now. I think it's a left over from old times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I take it back. Things break. I mocked it instead.
this.$behaviour = new CstyleBehaviour(); | ||
this.foldingRules = new CStyleFoldMode(); | ||
}; | ||
oop.inherits(ScriptMode, TextMode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with the oop
module in ace, but you can now use native JS class syntax, which is a little easier to grok:
class ScriptMode extends TextMode {
constructor() {
this.$outdent = new MatchingBraceOutdent();
this.$behaviour = new CstyleBehaviour();
this.foldingRules = new CStyleFoldMode();
}
get HighlightRules() {
return ScriptHighlightRules;
}
getNextLineIndent(state, line, tab) {
let indent = this.$getIndent(line);
const match = line.match(/^.*[\{\[]\s*$/);
if (match) {
indent += tab;
}
return indent;
}
// etc etc
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just noticed the acequire thing... I really have no idea what any of that is doing, so take what I just proposed with a grain of salt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the current ace is a stand alone fully embeddable version of it that tries to isolate itself from the universe. It has it's own version of require that is fully served from a single big file. I think at some point we should move to an unpacked version of ace where it's easier to read the source and we just import ourselves. I rather not tackle it now though.
|
||
}).call(ScriptMode.prototype); | ||
|
||
module.exports.ScriptMode = ScriptMode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use native JS exports now rather than CommonJS module exports, so your class definition can simply be:
export class ScriptMode extends TextMode {
And then you can remove module.exports.ScriptMode = ScriptMode;
entirely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx for the export
tip. applied.
"def|int|long|byte|String|new|null|for|if|return|ctx" | ||
); | ||
|
||
var ScriptHighlightRules = function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have the same suggestion here about using native class syntax as I did in the previous file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took over the direct export
I added a couple of notes. PRs for new features on console are particular challenging because we haven't yet updated the console codebase to be consistent in terms of code style and technologies with the rest of Kibana. I created two issues in particular for this: #9603 #9604 We shouldn't block this PR on those issues, but I wanted to highlight this for both you @bleskes and for other reviewers as we have to tread the fine line between writing code that's consistent with Kibana and code that's consistent with Console. |
thx @epixa . I addressed all your comments. Can you take another look? |
@bleskes Looks like there's a linter failure in CI:
|
@bleskes How do I run the qunit tests for console? |
Nevermind, I found it. Edit: Just access |
LGTM |
Backports PR #9433 **Commit 1:** Add console scripts * Original sha: c645975 * Authored by Boaz Leskes <b.leskes@gmail.com> on 2016-12-09T16:28:26Z **Commit 2:** Merge remote-tracking branch 'upstream/master' into console_scripts * Original sha: 795fcc0 * Authored by Boaz Leskes <b.leskes@gmail.com> on 2016-12-09T16:29:04Z **Commit 3:** Better handling of auto formatting * Original sha: cf6e0b1 * Authored by Boaz Leskes <b.leskes@gmail.com> on 2016-12-09T20:15:16Z **Commit 4:** Merge remote-tracking branch 'upstream/master' into console_scripts * Original sha: 036b0f6 * Authored by Boaz Leskes <b.leskes@gmail.com> on 2016-12-23T15:17:52Z **Commit 5:** review feedback * Original sha: 361429e * Authored by Boaz Leskes <b.leskes@gmail.com> on 2016-12-23T16:16:32Z **Commit 6:** linting * Original sha: 412633d * Authored by Boaz Leskes <b.leskes@gmail.com> on 2016-12-23T18:22:28Z
That's peculiar because I thought you guys have linting setup as precommit. Anyway it works now :) @epixa thx for the review. It seems you guys have a different process (as you merged it in) and it looks like you guys are also taking care of backporting? If so thanks for that as well :) |
@bleskes To be honest, we do usually expect the submitter to merge/backport, but I didn't know what process you followed, so I treated this as I would a community submitted PR instead. I'll remember this for your future PRs though :P |
@epixa ❤️ |
Oh, and as for the precommit hook: the task was broken for a little while and wasn't linting properly, but that was fixed recently. Your branch just didn't have the latest master, so the linter wasn't working. |
Backports PR #9433 **Commit 1:** Add console scripts * Original sha: c645975 * Authored by Boaz Leskes <b.leskes@gmail.com> on 2016-12-09T16:28:26Z **Commit 2:** Merge remote-tracking branch 'upstream/master' into console_scripts * Original sha: 795fcc0 * Authored by Boaz Leskes <b.leskes@gmail.com> on 2016-12-09T16:29:04Z **Commit 3:** Better handling of auto formatting * Original sha: cf6e0b1 * Authored by Boaz Leskes <b.leskes@gmail.com> on 2016-12-09T20:15:16Z **Commit 4:** Merge remote-tracking branch 'upstream/master' into console_scripts * Original sha: 036b0f6 * Authored by Boaz Leskes <b.leskes@gmail.com> on 2016-12-23T15:17:52Z **Commit 5:** review feedback * Original sha: 361429e * Authored by Boaz Leskes <b.leskes@gmail.com> on 2016-12-23T16:16:32Z **Commit 6:** linting * Original sha: 412633d * Authored by Boaz Leskes <b.leskes@gmail.com> on 2016-12-23T18:22:28Z
Backports PR #9433 **Commit 1:** Add console scripts * Original sha: c645975 * Authored by Boaz Leskes <b.leskes@gmail.com> on 2016-12-09T16:28:26Z **Commit 2:** Merge remote-tracking branch 'upstream/master' into console_scripts * Original sha: 795fcc0 * Authored by Boaz Leskes <b.leskes@gmail.com> on 2016-12-09T16:29:04Z **Commit 3:** Better handling of auto formatting * Original sha: cf6e0b1 * Authored by Boaz Leskes <b.leskes@gmail.com> on 2016-12-09T20:15:16Z **Commit 4:** Merge remote-tracking branch 'upstream/master' into console_scripts * Original sha: 036b0f6 * Authored by Boaz Leskes <b.leskes@gmail.com> on 2016-12-23T15:17:52Z **Commit 5:** review feedback * Original sha: 361429e * Authored by Boaz Leskes <b.leskes@gmail.com> on 2016-12-23T16:16:32Z **Commit 6:** linting * Original sha: 412633d * Authored by Boaz Leskes <b.leskes@gmail.com> on 2016-12-23T18:22:28Z
At the moment, Console understands HTTP methods, URLs and JSON. However ES has long had the options to write inline scripts in its API and with the introduction of painless inline scripts become more and more popular. Sadly, writing them in JSON is a PITA as you must escape every single thing.
This PR adds the notion of literal strings to Console's flavor of JSON. This means that everything that is surrounded with
"""
will be JSON escaped before sending to ES. On top of that, if a literal string is found after"script"
or"inline"
tag it is treated as a script literal, which adds syntax highlighting and some Ace goodness. Script literal are a full blown Ace Mode, meaning we can extend it to do auto complete and similar in the future. Also, auto formatting works as well, automatically taking strings with more than 2 escaped characters and converting them literal strings. In similar fashion, the output pane also auto converts strings in the output.This is how it all looks:
Script literal:
String literals as fields in documents:
To illustrate what happens when things are sent to ES, here is the Copy as Curl output of the last document: