2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2012-04-12 15:51:56 +02:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2012-04-12 15:51:56 +02:00
|
|
|
|
|
|
|
|
#include "qmljstools_global.h"
|
|
|
|
|
|
2015-03-04 16:46:23 +01:00
|
|
|
#include <qmljs/qmljsdocument.h>
|
|
|
|
|
#include <qmljs/qmljscontext.h>
|
2012-04-12 15:51:56 +02:00
|
|
|
#include <qmljs/qmljsstaticanalysismessage.h>
|
2015-03-04 16:46:23 +01:00
|
|
|
#include <qmljs/parser/qmljsengine_p.h>
|
2012-04-12 15:51:56 +02:00
|
|
|
|
|
|
|
|
#include <QTextCursor>
|
|
|
|
|
|
2015-03-04 16:46:23 +01:00
|
|
|
namespace QmlJS {
|
|
|
|
|
class ScopeChain;
|
|
|
|
|
namespace AST { class Node; }
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-12 15:51:56 +02:00
|
|
|
namespace QmlJSTools {
|
|
|
|
|
|
|
|
|
|
class QMLJSTOOLS_EXPORT Range
|
|
|
|
|
{
|
|
|
|
|
public:
|
2018-11-24 10:22:37 +01:00
|
|
|
// attributes
|
|
|
|
|
QmlJS::AST::Node *ast = nullptr;
|
2012-04-12 15:51:56 +02:00
|
|
|
QTextCursor begin;
|
|
|
|
|
QTextCursor end;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class QMLJSTOOLS_EXPORT SemanticInfo
|
|
|
|
|
{
|
|
|
|
|
public:
|
2018-11-24 10:22:37 +01:00
|
|
|
SemanticInfo() = default;
|
|
|
|
|
explicit SemanticInfo(QmlJS::ScopeChain *rootScopeChain);
|
2012-04-12 15:51:56 +02:00
|
|
|
|
|
|
|
|
bool isValid() const;
|
|
|
|
|
int revision() const;
|
|
|
|
|
|
|
|
|
|
// Returns the AST path
|
|
|
|
|
QList<QmlJS::AST::Node *> astPath(int cursorPosition) const;
|
|
|
|
|
|
|
|
|
|
// Returns the AST node at the offset (the last member of the astPath)
|
|
|
|
|
QmlJS::AST::Node *astNodeAt(int cursorPosition) const;
|
|
|
|
|
|
|
|
|
|
// Returns the list of declaration-type nodes that enclose the given position.
|
|
|
|
|
// It is more robust than astPath because it tracks ranges with text cursors
|
|
|
|
|
// and will thus be correct even if the document was changed and not yet
|
|
|
|
|
// reparsed. It does not return the full path of AST nodes.
|
|
|
|
|
QList<QmlJS::AST::Node *> rangePath(int cursorPosition) const;
|
|
|
|
|
|
|
|
|
|
// Returns the declaring member
|
|
|
|
|
QmlJS::AST::Node *rangeAt(int cursorPosition) const;
|
|
|
|
|
QmlJS::AST::Node *declaringMemberNoProperties(int cursorPosition) const;
|
|
|
|
|
|
|
|
|
|
// Returns a scopeChain for the given path
|
|
|
|
|
QmlJS::ScopeChain scopeChain(const QList<QmlJS::AST::Node *> &path = QList<QmlJS::AST::Node *>()) const;
|
|
|
|
|
|
|
|
|
|
void setRootScopeChain(QSharedPointer<const QmlJS::ScopeChain> rootScopeChain);
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
|
|
|
|
QmlJS::Document::Ptr document;
|
|
|
|
|
QmlJS::Snapshot snapshot;
|
|
|
|
|
QmlJS::ContextPtr context;
|
|
|
|
|
QList<Range> ranges;
|
2020-02-28 17:51:32 +01:00
|
|
|
QHash<QString, QList<QmlJS::SourceLocation> > idLocations;
|
2012-04-12 15:51:56 +02:00
|
|
|
|
|
|
|
|
// these are in addition to the parser messages in the document
|
|
|
|
|
QList<QmlJS::DiagnosticMessage> semanticMessages;
|
|
|
|
|
QList<QmlJS::StaticAnalysis::Message> staticAnalysisMessages;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QSharedPointer<const QmlJS::ScopeChain> m_rootScopeChain;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace QmlJSTools
|
|
|
|
|
|
2012-04-13 11:57:34 +02:00
|
|
|
Q_DECLARE_METATYPE(QmlJSTools::SemanticInfo)
|