From 8274197366a227fcc69833d3645e535f888594f6 Mon Sep 17 00:00:00 2001 From: Christian Kamm <christian.d.kamm@nokia.com> Date: Fri, 19 Feb 2010 10:16:33 +0100 Subject: [PATCH] Implement function to get the QmlJS AST path to a given location. Will be useful for improved scope chain building. --- src/plugins/qmljseditor/qmljseditor.cpp | 15 +++++++++++++++ src/plugins/qmljseditor/qmljseditor.h | 3 +++ 2 files changed, 18 insertions(+) diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp index 021643535fc..c0ebfcf273b 100644 --- a/src/plugins/qmljseditor/qmljseditor.cpp +++ b/src/plugins/qmljseditor/qmljseditor.cpp @@ -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) diff --git a/src/plugins/qmljseditor/qmljseditor.h b/src/plugins/qmljseditor/qmljseditor.h index dc8d93a3006..dfa5228fd7b 100644 --- a/src/plugins/qmljseditor/qmljseditor.h +++ b/src/plugins/qmljseditor/qmljseditor.h @@ -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; -- GitLab