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
[Console] Token Iterator #46793
[Console] Token Iterator #46793
Conversation
Pinging @elastic/es-ui |
💚 Build Succeeded |
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.
This looks great! I was able to follow the code pretty easily but had a couple questions and some really minor suggestions -- feel free to merge without implementing them if you prefer.
src/legacy/core_plugins/console/np_ready/public/interfaces/editor.ts
Outdated
Show resolved
Hide resolved
src/legacy/core_plugins/console/np_ready/public/lib/ace_token_provider/token_provider.test.ts
Outdated
Show resolved
Hide resolved
src/legacy/core_plugins/console/np_ready/public/lib/ace_token_provider/token_provider.ts
Show resolved
Hide resolved
src/legacy/core_plugins/console/np_ready/public/lib/ace_token_provider/token_provider.ts
Outdated
Show resolved
Hide resolved
let acc = ''; | ||
return tokens.map(token => { | ||
const column = acc.length + 1; | ||
acc += token.value || ''; |
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.
When is token.value
falsey? It seems like we would get into a strange situation if this occurred, since appending an empty string won't change the length of acc
and yet we're using the length of acc
to specify column
on line 30. So we'd have multiple tokens occupying the same column.
If token.value
can never be falsey then maybe we should just remove this default value? Or, if it can be falsey, then I wonder if this represents an error state -- in which case maybe we should throw
? Or if it's not an error state, should we just skip the token without mutating acc
and without creating a token, and move on to the next one?
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.
Great catch! You are totally correct that this should be an error case. In fact, most tokenizers I've used will error out if you match an empty string or if it doesn't have a way to tokenize a string. Will remove the default.
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.
👍 Maybe some unit tests for this function or testing this error case through its consumers would be good too.
src/legacy/core_plugins/console/np_ready/public/lib/ace_token_provider/token_provider.ts
Outdated
Show resolved
Hide resolved
src/legacy/core_plugins/console/np_ready/public/lib/token_iterator/token_iterator.ts
Outdated
Show resolved
Hide resolved
src/legacy/core_plugins/console/np_ready/public/lib/token_iterator/token_iterator.ts
Outdated
Show resolved
Hide resolved
src/legacy/core_plugins/console/np_ready/public/lib/token_iterator/token_iterator.test.ts
Outdated
Show resolved
Hide resolved
src/legacy/core_plugins/console/np_ready/public/lib/token_iterator/token_iterator.ts
Outdated
Show resolved
Hide resolved
💔 Build Failed |
💔 Build Failed |
Update token iterator and token provider behviour to go to the first token BEHIND the cursor Update test coverage Get legacy tests working with new token iterator
💔 Build Failed |
Cleaned up interface arguments for existing insert method too.
@elasticmachine merge upstream |
… into console-token-iterator * 'console-token-iterator' of github.com:jloleysens/kibana: (184 commits) [functional/services] update webdriver lib and types (elastic#47381) Standardizing IconField implementation across the app (elastic#47196) Move ui/value_suggestions ⇒ NP data plugin (elastic#45762) Remove ui/persisted_log - Part 2 (elastic#47236) Update gulp related packages (elastic#47421) Update dependency idx to ^2.5.6 (elastic#47399) try running fewer jobs in parallel on the same worker (elastic#47403) Update webpack related packages (elastic#47402) Update jsonwebtoken related packages (elastic#47400) Update gulp related packages (major) (elastic#46665) Update dependency prettier to ^1.18.2 (elastic#47340) Update dependency @types/puppeteer to ^1.20.1 (elastic#47339) Update dependency @elastic/elasticsearch to ^7.4.0 (elastic#47338) Update dependency tar-fs to ^1.16.3 (elastic#47341) [Code] Code Integrator Component (elastic#47180) [Canvas][i18n] Sidebar (elastic#46090) Generate uuid in task Manager as Kibana uuid may not yet have been initialised [Code] Embedded Code Snippet Component (elastic#47183) Revert "Add pipeline for flaky test runner job (elastic#46740)" SearchSource: fix docvalue_fields and fields intersection logic (elastic#46724) ...
💔 Build Failed |
@elasticmachine merge upstream |
💔 Build Failed |
Retest |
💚 Build Succeeded |
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.
Awseome work @jloleysens ! I made a few comments that you can feel free to address or not. Most of them about some preferences.
There seems to be a regression though when I tested locally, trying to "Open documentation" on a request throws an error in the console and does not open the docs.
Once this is fixed I'll approve. thanks!
src/legacy/core_plugins/console/np_ready/public/application/models/legacy_editor.ts
Outdated
Show resolved
Hide resolved
@@ -0,0 +1,30 @@ | |||
/* |
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 personally prefer to group files by "feature" than by "type". So, in this case, have everything under a "token_iterator" folder. It's just a preference though.
src/legacy/core_plugins/console/np_ready/public/lib/token_iterator/token_iterator.ts
Outdated
Show resolved
Hide resolved
src/legacy/core_plugins/console/np_ready/public/interfaces/tokens_provider.ts
Outdated
Show resolved
Hide resolved
src/legacy/core_plugins/console/np_ready/public/lib/token_iterator/token_iterator.ts
Outdated
Show resolved
Hide resolved
src/legacy/core_plugins/console/np_ready/public/lib/token_iterator/token_iterator.ts
Outdated
Show resolved
Hide resolved
src/legacy/core_plugins/console/np_ready/public/lib/ace_token_provider/token_provider.test.ts
Outdated
Show resolved
Hide resolved
src/legacy/core_plugins/console/public/quarantined/src/input.ts
Outdated
Show resolved
Hide resolved
/** | ||
* Report the token under the iterator's cursor. | ||
*/ | ||
getCurrentToken(): Token | null; |
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.
Should we use class getters for those?
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.
(in response to your suggestion about getters above too)
This interface is designed to be an in-place replacement for https://github.com/ajaxorg/ace/blob/master/lib/ace/token_iterator.js.
This reduces the surface area for changes for now. But otherwise I agree, getters
would be a nice addition/change!
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.
Got it, thanks for explaining
src/legacy/core_plugins/console/np_ready/public/lib/ace_token_provider/token_provider.ts
Outdated
Show resolved
Hide resolved
💔 Build Failed |
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.
LGTM. Tested locally and the documentation link now works as expected. Thanks!
@sebelga Great, thanks! I'll fix the tests and merge! |
@elasticmachine merge upstream |
💔 Build Failed |
💔 Build Failed |
@elasticmachine merge upstream |
💚 Build Succeeded |
* Start of token provider and token iterator * Update Range interface * Implement early feedback * getTokenAt tests and update * First pass! Autocomplete.js -> Autocomplete.ts A lot of things broke! * Added factories and models * Lots of WiP * Initial wiring up of new token iterator * Fix types * Minor updates to token iterator * Fixed legacy editor.test.js tests (they were never running properly) Update token iterator and token provider behviour to go to the first token BEHIND the cursor Update test coverage Get legacy tests working with new token iterator * Address documentation Todos and implement missing `insert` method. Cleaned up interface arguments for existing insert method too. * Document range and line mode * Fix broken async test in token provider (done callback) * Fix path * Slight update to token_provider and token_iterator to make code more readable * Implement PR feedback (including fix for open documentation) * Remove token_iterator interface * initializeInput -> initializeEditor for quarantined integration tests * Update input init mock
* Start of token provider and token iterator * Update Range interface * Implement early feedback * getTokenAt tests and update * First pass! Autocomplete.js -> Autocomplete.ts A lot of things broke! * Added factories and models * Lots of WiP * Initial wiring up of new token iterator * Fix types * Minor updates to token iterator * Fixed legacy editor.test.js tests (they were never running properly) Update token iterator and token provider behviour to go to the first token BEHIND the cursor Update test coverage Get legacy tests working with new token iterator * Address documentation Todos and implement missing `insert` method. Cleaned up interface arguments for existing insert method too. * Document range and line mode * Fix broken async test in token provider (done callback) * Fix path * Slight update to token_provider and token_iterator to make code more readable * Implement PR feedback (including fix for open documentation) * Remove token_iterator interface * initializeInput -> initializeEditor for quarantined integration tests * Update input init mock
Summary
More details in phase 2.1 of this roadmap item: https://github.com/elastic/elasticsearch-team/issues/217
Before ready for review