}
PySelection selection = new PySelection(info.getDocument(), userSelection);
int startLineIndexIndocCoords = selection.getStartLineIndex();
int startLineIndexInASTCoords = startLineIndexIndocCoords + 1; //from doc to ast
Module module = info.getModuleAdapter().getASTNode();
SimpleNode currentScope = module;
try {
FindScopeVisitor scopeVisitor = new FindScopeVisitor(startLineIndexInASTCoords,
selection.getCursorColumn() + 1);
module.accept(scopeVisitor);
ILocalScope scope = scopeVisitor.scope;
FastStack scopeStack = scope.getScopeStack();
currentScope = (SimpleNode) scopeStack.peek(); //at least the module should be there if we don't have anything.
} catch (Exception e1) {
Log.log(e1);
}
GetNodeForExtractLocalVisitor visitor = new GetNodeForExtractLocalVisitor(startLineIndexInASTCoords);
try {
currentScope.accept(visitor);
} catch (Exception e) {
throw new RuntimeException(e);
}
SimpleNode lastNodeBeforePassedLine = visitor.getLastInContextBeforePassedLine();
if (lastNodeBeforePassedLine != null) {
final int[] line = new int[] { Integer.MAX_VALUE };
try {
Visitor v = new Visitor() {
protected Object unhandled_node(SimpleNode node) throws Exception {
if (node.beginLine > 0) {
line[0] = Math.min(line[0], node.beginLine - 1);
} else {
Log.log("Found node with beginLine <= 0:" + node + " line: " + node.beginLine);
}
return this;
}
};
lastNodeBeforePassedLine.accept(v);
} catch (Exception e) {
Log.log(e);
}
if (line[0] != Integer.MAX_VALUE) {
lineForLocal = line[0];