How do I build my auto completion list w/ an ANTLR parser?

SyntaxEditor for WPF Forum

Posted 9 years ago by Craig - Varigence, Inc.
Version: 10.2.0531
Avatar
Greetings,

I have a WPF application that uses the syntax editor with a language that I have an ANTLR grammar for. I've generated the lexer and parser C# code for the language, along with also having a langdef file for syntax highlighting.

My problem is that I want to use those to auto-generate my IntelliPrompt list as the user types. Or at least use it to determine the next valid token type(s), so that can drive how I build the completion list. Looking at the QuickStart sample for IntelliPrompt, you appear to rely heavily on reading tokens and determining the context from the text. Isn't that what the parser is for?

Furthermore, looking at older samples from the WinForms SyntaxEditor, you seemed to have a much cleaner approach, with the SimpleSyntaxLanguage's ShowIntelliPromptMemberList simply grabing the compilation unit, which contained a member list.

Can you provide a sample which shows how to leverage the parser to do the heavy lifting for me? Or, for Intelliprompt purposes, is there really no point to having a parser since I'm stuck building the list in code anyway? Is there a feature that's still coming that will help enable this scenario?

Thanks very much,

-Craig

Comments (1)

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Craig,

Just making sure you have the latest 2010.2 build for the samples you're referring to, where we have 15 or so samples in the Getting Started series (we rewrote the Getting Started series for 2010.2). In there the context factory does use a combination of AST and token scanning to create the context object. In a later sample in the series, the context is used by a completion provider to build the completion list items.

The WinForms version sample did a subset of these things. I don't believe it showed how to build a context object and just did some basic context sort of building logic right in ShowIntelliPromptMemberList. In the WPF version, we show a better design where context building is separate from IntelliPrompt, and is how we recommend doing things.

The Simple language is pretty basic too. When you have a more complex language like C#, you will be doing a lot more with the AST to construct your context, as you'll be using it to determine containing namespaces, types, and will use it to scan back through statements to find declared variables, etc.

The reason we do hybrid token scanning and AST examination is that when large documents are loaded, the AST will almost never be in sync with what is being edited. Since parsing for large docs could be delayed a couple seconds from what is in the UI. Thus it's better to do token scanning or at least a small expression-only parse of the live tokens in the document to get contextual info near the caret and rely on AST data to give you more insight on what contains or comes before that area of code.

But as always, we're open to suggestions for improvement. We want this product to continue to be far more robust than anything out there.


Actipro Software Support

The latest build of this product (v2019.1 build 0683) 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.