Skip to content
Snippets Groups Projects
Commit 82741973 authored by Christian Kamm's avatar Christian Kamm
Browse files

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

Will be useful for improved scope chain building.
parent c2898973
No related branches found
No related tags found
No related merge requests found
...@@ -510,6 +510,21 @@ AST::Node *SemanticInfo::declaringMember(int cursorPosition) const ...@@ -510,6 +510,21 @@ AST::Node *SemanticInfo::declaringMember(int cursorPosition) const
return declaringMember; 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 AST::Node *SemanticInfo::nodeUnderCursor(int pos) const
{ {
if (! document) if (! document)
......
...@@ -115,6 +115,9 @@ public: ...@@ -115,6 +115,9 @@ public:
// Returns the AST node under cursor // Returns the AST node under cursor
QmlJS::AST::Node *nodeUnderCursor(int cursorPosition) const; 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 public: // attributes
QmlJS::Document::Ptr document; QmlJS::Document::Ptr document;
QmlJS::Snapshot snapshot; QmlJS::Snapshot snapshot;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment