Skip to content

Conversation

@testforstephen
Copy link
Contributor

@testforstephen testforstephen commented Apr 12, 2021

The steps:

  1. Visit AST tree to find the variable tokens in each lines.

    ASTVisitor can identify if a node is a variable declaration and a simple name. And then based on resolveBinding, it's easy to tell if the name is a variable/field binding.

  2. Resolve the values of the variable tokens.

    Once the variable names in each lines are found, next step is to resolve values for these variables. Usually the variables come from four places, we can use different methods to get the values.

    • Local variables declared in current method body
    • Formal parameters declared in method declaration.
    • Field variables of the enclosing instance.
    • Captured variables from outer scope. For example, local type is accessing variables of enclosing method, and lambda expression body is accessing to variables of enclosing method.

    For the first two kinds, they are visible local variables of the current stack frame, and by default their values will be expanded by Variables View. So we're going to return them with VariableLookup kind to tell client to look them up in Variables View directly.

    For the last two kinds, their values are hidden as properties of 'this' object and require additional evaluation to get their values. So we're going to return them with Evaluation kind, and then calling the debuggee runtime to evaluate their values.

@testforstephen
Copy link
Contributor Author

testforstephen commented Apr 12, 2021

Local type stores the captured variables from the enclosing method in "this" object. "val$<name>" are captured local variables of enclosing method, and "this$<index>" are captured instance of the enclosing instance.

image

Lambda stores the captured variables in a synthetic frame.
image

}
}

private static IMethod findEnclosingMethod(ITypeRoot root, int stoppedOffset) throws JavaModelException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is JDTUtils.findElementsAtSelection() suitable for this task?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it doesn't apply to this task. The purpose of that helper is to find the definition element of the selection. For example, the offset is at the String▮, it returns the String.class element. But what we want is the enclosing method method.

void method() {
    Stringa = "test";
}

@testforstephen testforstephen merged commit e521ed1 into microsoft:master Apr 21, 2021
@testforstephen testforstephen deleted the jinbo_inlinevalues branch April 21, 2021 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants