Yes, you'll have to create your own CompletionProvider that parses the code to determine what variables are in scope at the caret position. For an example, check out PerlCompletionProvider
That's the simplest way to do it - every time the user types Ctrl+Space (or a trigger key), the code in the editor is parsed then and there. The vast majority of the time, this is fast enough. However, for a super robust solution you should consider creating a Parser implementation that will get notified whenever the user edits the document, so that it can be re-parsed. Then code completion will only force a re-parsing if the AST (or whatever you keep in memory) is "dirty". See JavaParser
, and the Java code completion in general, in RSTALanguageSupport, for an example of doing it this way.
But again, the method used in PerlCompletionProvider is probably sufficient. It's super-easy to do too, if you're parsing a language that makes variable declarations easy to identify, such as prefixing them all with '$' or declaring them with "var". I'd take advantage of CodeBlock and other utility classes
in the library to make things easier.