Using parser's expected next tokens in completion?

Okay, I have keyword completion working pretty well in my custom language plugin.  It's even context-aware in a fairly simplisitc sense (class vs. trigger vs. inline query) in terms of the keywords that are presented.  However, it still presents keywords that make no sense in a given location according to the grammar.  I'm hoping there's some very simple way to ask the parser for the next token candidates based on its current position so I can filter appropriately.  For example, if you requested completion in a Java source file at the following location:

public <cursor> class MyClass

you should only be presented with tokens for type modifiers, e.g., abstract, static, final, etc., and not flow control tokens such as if, for, while, etc.  Ideally I'd be able to do this without having to replicate the grammar logic explicitly.  Is this possible?  Hopefully it's just some no-brainer option that I've overlooked!

Thanks in advance!

1 comment
Comment actions Permalink

Hmmm...I just found this previous thread asking essentially the same question:

http://devnet.jetbrains.com/message/5499054

I guess the parser context isn't really available at the time of completion, at least not in any usable form.  Bummer...it would be nice to ask the parser for the tokens, terminals and non-terminals, that are considered valid at the insertion point given the currently matching rule.  I guess I'll just have to look at the context myself and filter as appropriate.

0

Please sign in to leave a comment.