How to get local variables names from syntaxTree

In Autocomplete example it is shown a way to get global variables, but
I’d like to know how can I get document local variables names for autocomplete.
Thank you in advance to everyone who can help me.

There’s no general mechanism for this yet, but if you’re willing to write language-specific code, you might be able to iterate over the syntax tree and collect these somehow.

Thank you for reply.