I need to get a list of variables at the scope of a current line. For example, when user clicks inside of the function I need to find all variables declared within that function and show those variables to the user.
I need to get a list of variables at the scope of a current line. For example, when user clicks inside of the function I need to find all variables declared within that function and show those variables to the user.
Hi Sergey,
You could do something similar to our completion list code which gets a context object like:
new CSharpContextFactory().CreateContext(view.Selection.EndSnapshotOffset, DotNetContextKind.SelfAndSiblings);
Then get a resolved result set like:
var resultSet = context.Resolve();
If you run through the results in the set, look for IVariableResolverResult instances. Those should be local variables.
Thank you, that works.
My next task will be to enumerate whole script and show it as a tree, similar to Visual Studio “Locals” window. I understand that I can get IAstNode of Document.ParseData like that:
IDotNetParseData parseData = this.Document.ParseData as IDotNetParseData;
And then I can traverse parseData.Ast enumerating its Children, but what I do not know, is how to apply Resolver to each IAstNode, or if there is a better way to get a code tree in a resolved state.
Please log in to a validated account to post comments.