Skip to content
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

Merged
merged 25 commits into from Oct 22, 2019
Merged

Conversation

jloleysens
Copy link
Contributor

@jloleysens jloleysens commented Sep 27, 2019

Summary

More details in phase 2.1 of this roadmap item: https://github.com/elastic/elasticsearch-team/issues/217

Before ready for review

  • Get CI working again
  • Finish TODOs
  • More manual Testing

@jloleysens jloleysens added Feature:Console Dev Tools Console Feature enhancement New value added to drive a business result refactoring Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more v7.6.0 labels Sep 27, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/es-ui

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Contributor

@cjcenizal cjcenizal left a 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.

let acc = '';
return tokens.map(token => {
const column = acc.length + 1;
acc += token.value || '';
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 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
@elasticmachine
Copy link
Contributor

💔 Build Failed

Cleaned up interface arguments for existing insert method too.
@jloleysens
Copy link
Contributor Author

@elasticmachine merge upstream

elasticmachine and others added 3 commits October 7, 2019 03:30
… 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)
  ...
@elasticmachine
Copy link
Contributor

💔 Build Failed

@jloleysens
Copy link
Contributor Author

@elasticmachine merge upstream

@elasticmachine
Copy link
Contributor

💔 Build Failed

@jloleysens
Copy link
Contributor Author

Retest

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Contributor

@sebelga sebelga left a 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.

Screen Shot 2019-10-14 at 17 07 45

Once this is fixed I'll approve. thanks!

@@ -0,0 +1,30 @@
/*
Copy link
Contributor

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.

/**
* Report the token under the iterator's cursor.
*/
getCurrentToken(): Token | null;
Copy link
Contributor

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?

Copy link
Contributor Author

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!

Copy link
Contributor

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

@elasticmachine
Copy link
Contributor

💔 Build Failed

@sebelga sebelga self-requested a review October 22, 2019 07:21
Copy link
Contributor

@sebelga sebelga left a 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!

@jloleysens
Copy link
Contributor Author

@sebelga Great, thanks! I'll fix the tests and merge!

@jloleysens
Copy link
Contributor Author

@elasticmachine merge upstream

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@jloleysens
Copy link
Contributor Author

@elasticmachine merge upstream

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@jloleysens jloleysens merged commit 86b72d3 into elastic:master Oct 22, 2019
@jloleysens jloleysens deleted the console-token-iterator branch October 22, 2019 14:31
jloleysens added a commit to jloleysens/kibana that referenced this pull request Oct 28, 2019
* 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
jloleysens added a commit that referenced this pull request Oct 28, 2019
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Console Dev Tools Console Feature refactoring Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more v7.6.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants