Looking to build a typeahead like search with chevrotain, how to handle async backend calls in visitor? #2014
Replies: 1 comment 1 reply
-
If I understand correctly you are trying to implement content assist / auto-complete during user input. One option you can check is Langium which builds on-top of Chevrotain to implement language servers. If you prefer to build the logic yourselfI am not sure I fully understood your description, So I will instead reference a use-case where I worked on content assist.
Main logic parts:
Sync vs Async semantic providersI don't think this is a big issue, the parsing and figuring the syntactic parts are synchronized. e.g.: lets imagine the grammar in your search box is similar to SQL:
Basically don't try to introduce async flows inside Chevrotain APIs (parsing/visitor). |
Beta Was this translation helpful? Give feedback.
-
I'm looking to build a search feature using chevrotain for my product and I'm was able setup the parser and visitor for the grammar we use in our search box. We use the same grammar for many products that then, will individual create there own visitors to transform the search grammar to there own DSL.
Next step for this is that we want to show typeahead results that load as the user is typing the query in the search box.
The basic idea I have now is that I use the recoveryMode of the parser, so that as the user is type I still reach the visitor, where I then reach the context to decide which fetch should be called based on the context stack. This fetch is outside the visitor and is invoked by a event creation.
Is this a good solution, or is there a implementation of this that I can reference where this scenario is already solved?
Beta Was this translation helpful? Give feedback.
All reactions