Commit 82741973 authored by Christian Kamm's avatar Christian Kamm

Implement function to get the QmlJS AST path to a given location.

Will be useful for improved scope chain building.
parent c2898973
......@@ -510,6 +510,21 @@ AST::Node *SemanticInfo::declaringMember(int cursorPosition) const
return declaringMember;
}
QList<AST::Node *> SemanticInfo::astPath(int cursorPosition) const
{
QList<AST::Node *> path;
foreach (const Range &range, ranges) {
if (range.begin.isNull() || range.end.isNull()) {
continue;
} else if (cursorPosition >= range.begin.position() && cursorPosition <= range.end.position()) {
path += range.ast;
}
}
return path;
}
AST::Node *SemanticInfo::nodeUnderCursor(int pos) const
{
if (! document)
......
......@@ -115,6 +115,9 @@ public:
// Returns the AST node under cursor
QmlJS::AST::Node *nodeUnderCursor(int cursorPosition) const;
// Returns the list of nodes that enclose the given position.
QList<QmlJS::AST::Node *> astPath(int cursorPosition) const;
public: // attributes
QmlJS::Document::Ptr document;
QmlJS::Snapshot snapshot;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment