Posted 12 years ago by Sergey Kaminskiy
Version: 12.2.0573
Avatar

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.

Comments (3)

Answer - Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

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.


Actipro Software Support

Posted 12 years ago by Sergey Kaminskiy
Avatar

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.

Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Sergey,

Sorry but we don't have anything that resolves the entire tree of an AST. However you could use the previously suggested technique to find all accessible members, parameters, and variables. Parameter results will be IParameterResolverResults and members will be ITypeMemberResolverResults. You'd only need to filter down members to field or property ones.


Actipro Software Support

The latest build of this product (v24.1.3) was released 29 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.