aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlcompiler/qqmljsscopesbyid_p.h
diff options
context:
space:
mode:
authorSami Shalayel <sami.shalayel@qt.io>2024-04-15 17:40:14 +0200
committerSami Shalayel <sami.shalayel@qt.io>2024-04-18 11:46:36 +0200
commit6fd68ab3f4a629cc36be83e6378db85e797acd74 (patch)
treeba1a5eeac73f3da1cfdb3228331e9acb4776d67f /src/qmlcompiler/qqmljsscopesbyid_p.h
parent5dd4720bd2a5d84127edd692209267cafb4b68a8 (diff)
qmlls: assume bound identifiers in completions
Add a new option flag to QmlTypeResolver to allow resolving id's while assuming that Components are bounds (even if they are currently not bound). This allows qmlls to provide completions even if the user forgot to set the pragma, instead of not suggesting anything at all after "someIdThatIsOnlyVisibleWhenComponentsAreBound.". Fixes: QTBUG-124459 Change-Id: I658c2f5d678f94f99a94a9e06aaf6d19db9b1147 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 1bcb8587ab6b7068d1af8897804820853e7bc9d0) Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qmlcompiler/qqmljsscopesbyid_p.h')
-rw-r--r--src/qmlcompiler/qqmljsscopesbyid_p.h23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/qmlcompiler/qqmljsscopesbyid_p.h b/src/qmlcompiler/qqmljsscopesbyid_p.h
index ab97aeaccf..c9dca9ae34 100644
--- a/src/qmlcompiler/qqmljsscopesbyid_p.h
+++ b/src/qmlcompiler/qqmljsscopesbyid_p.h
@@ -22,6 +22,12 @@
QT_BEGIN_NAMESPACE
+enum QQmlJSScopesByIdOption: char {
+ Default = 0,
+ AssumeComponentsAreBound = 1,
+};
+Q_DECLARE_FLAGS(QQmlJSScopesByIdOptions, QQmlJSScopesByIdOption);
+
class QQmlJSScopesById
{
public:
@@ -34,11 +40,12 @@ public:
void setValueTypesAreAddressable(bool addressable) { m_valueTypesAreAddressable = addressable; }
bool valueTypesAreAddressable() const { return m_valueTypesAreAddressable; }
- QString id(const QQmlJSScope::ConstPtr &scope, const QQmlJSScope::ConstPtr &referrer) const
+ QString id(const QQmlJSScope::ConstPtr &scope, const QQmlJSScope::ConstPtr &referrer,
+ QQmlJSScopesByIdOptions options = Default) const
{
const QQmlJSScope::ConstPtr referrerRoot = componentRoot(referrer);
for (auto it = m_scopesById.begin(), end = m_scopesById.end(); it != end; ++it) {
- if (*it == scope && isComponentVisible(componentRoot(*it), referrerRoot))
+ if (*it == scope && isComponentVisible(componentRoot(*it), referrerRoot, options))
return it.key();
}
return QString();
@@ -49,7 +56,8 @@ public:
Returns the scope that has id \a id in the component to which \a referrer belongs to.
If no such scope exists, a null scope is returned.
*/
- QQmlJSScope::ConstPtr scope(const QString &id, const QQmlJSScope::ConstPtr &referrer) const
+ QQmlJSScope::ConstPtr scope(const QString &id, const QQmlJSScope::ConstPtr &referrer,
+ QQmlJSScopesByIdOptions options = Default) const
{
Q_ASSERT(!id.isEmpty());
const auto range = m_scopesById.equal_range(id);
@@ -58,7 +66,7 @@ public:
const QQmlJSScope::ConstPtr referrerRoot = componentRoot(referrer);
for (auto it = range.first; it != range.second; ++it) {
- if (isComponentVisible(componentRoot(*it), referrerRoot))
+ if (isComponentVisible(componentRoot(*it), referrerRoot, options))
return *it;
}
@@ -95,10 +103,11 @@ private:
return scope;
}
- bool isComponentVisible(
- const QQmlJSScope::ConstPtr &observed, const QQmlJSScope::ConstPtr &observer) const
+ bool isComponentVisible(const QQmlJSScope::ConstPtr &observed,
+ const QQmlJSScope::ConstPtr &observer,
+ QQmlJSScopesByIdOptions options) const
{
- if (!m_componentsAreBound)
+ if (!m_componentsAreBound && !options.testAnyFlag(AssumeComponentsAreBound))
return observed == observer;
for (QQmlJSScope::ConstPtr scope = observer; scope; scope = scope->parentScope()) {