Intelliprompt with AST examination and ThreadedParseRequestDispatcher

SyntaxEditor for WPF Forum

Posted 8 years ago by Valéry Sablonnière - Staubli
Version: 15.1.0623
Avatar

I have an issue with the intelliprompt completion list when I use the
ThreadedParseRequestDispatcher.
My CompletionProvider uses token scanning and AST examination.
When the request session is called, I use a token reader to determine the
current context and the AST to create the completion items.

example

if I type 'myVar' and then '.', I want to show the fields of the
variable myVar.
I type 'myVa', a parse is requested, I get a ParseData in my document and I type
'r.', the completion list is requested, my completion provider scans the tokens
('myVar' and '.') and knows the context (After a dot, I have to show the fields
of the expression before the dot), gets the offset before the dot, translates it
to the snapshot version of the ParseData, gets the AST node for this offset BUT
the node is 'myVa' and no variable corresponds to this variable, so the
completion list is empty.

What is the best way to do this (with token scanning and AST examination) ?
I don't want to use only token scanning because I may have a complex expression
before a dot, and the AST is there to do this job, right ?
I don't want to block UI if the parsing operation takes time, so the
ThreadedParseRequestDispatcher is mandatory.

Best regards,

Comments (2)

Answer - Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

With these scenarios, the tokens are always in sync with what is in the editor while the parse data AST is generally close but slightly out of sync due to the parser doing its work asynchronously.  What we do in our advanced language add-ons like C#/VB is scan tokens to the start of the current expression.  We grab that entire text and manually execute our parser on it but in an "expression" sort of context (meaning as if an Expression non-terminal is the root node).  We then get whatever full AST is currently in the document and find the node that contains the offset at which the expression started.  Then we take the expression AST and tell it that its parent is that other AST node, thus creating sort of a virtual link up into the full AST from the expression.  When we go to run our resolver, we pass the expression AST info in as context and it's able to then walk up the tree and into the normal full tree to get surrounding type/member context.  Hope that helps!


Actipro Software Support

Posted 8 years ago by Valéry Sablonnière - Staubli
Avatar

Thank you, that helps a lot, this is a good idea and it's efficient.

The latest build of this product (v24.1.1) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.