aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qmlls/qqmlsemantictokens.cpp32
-rw-r--r--tests/auto/qmlls/utils/data/highlights/componentBound.qml19
-rw-r--r--tests/auto/qmlls/utils/data/highlights/componentNoBound.qml19
-rw-r--r--tests/auto/qmlls/utils/tst_qmlls_highlighting.cpp16
4 files changed, 83 insertions, 3 deletions
diff --git a/src/qmlls/qqmlsemantictokens.cpp b/src/qmlls/qqmlsemantictokens.cpp
index 96c166f57e..734b178d79 100644
--- a/src/qmlls/qqmlsemantictokens.cpp
+++ b/src/qmlls/qqmlsemantictokens.cpp
@@ -673,9 +673,35 @@ void HighlightingVisitor::highlightBySemanticAnalysis(const DomItem &item, QQmlJ
case QQmlLSUtils::MethodIdentifier:
m_highlights.addHighlight(loc, QmlHighlightKind::QmlMethod);
return;
- case QQmlLSUtils::QmlObjectIdIdentifier:
- m_highlights.addHighlight(loc, QmlHighlightKind::QmlLocalId);
- return;
+ case QQmlLSUtils::QmlObjectIdIdentifier: {
+ const auto qmlfile = item.fileObject().as<QmlFile>();
+ if (!qmlfile) {
+ m_highlights.addHighlight(loc, QmlHighlightKind::Unknown);
+ return;
+ }
+ const auto resolver = qmlfile->typeResolver();
+ if (!resolver) {
+ m_highlights.addHighlight(loc, QmlHighlightKind::Unknown);
+ return;
+ }
+ const auto objects = resolver->objectsById();
+ if (expression->name.has_value()) {
+ const auto &name = expression->name.value();
+ const auto boundName =
+ objects.id(expression->semanticScope, item.qmlObject().semanticScope());
+ if (!boundName.isEmpty() && name == boundName) {
+ // If the name is the same as the bound name, then it is a local id.
+ m_highlights.addHighlight(loc, QmlHighlightKind::QmlLocalId);
+ return;
+ } else {
+ m_highlights.addHighlight(loc, QmlHighlightKind::QmlExternalId);
+ return;
+ }
+ } else {
+ m_highlights.addHighlight(loc, QmlHighlightKind::QmlExternalId);
+ return;
+ }
+ }
case QQmlLSUtils::SingletonIdentifier:
m_highlights.addHighlight(loc, QmlHighlightKind::QmlType);
return;
diff --git a/tests/auto/qmlls/utils/data/highlights/componentBound.qml b/tests/auto/qmlls/utils/data/highlights/componentBound.qml
new file mode 100644
index 0000000000..8ae2f0fb74
--- /dev/null
+++ b/tests/auto/qmlls/utils/data/highlights/componentBound.qml
@@ -0,0 +1,19 @@
+// Copyright (C) 2025 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+import QtQuick
+pragma ComponentBehavior: Bound
+
+Item {
+ id: outer
+
+ Component {
+ id: myComponent
+
+ Rectangle {
+ Component.onCompleted: {
+ outer.width.toFixed() // localId, field, method
+ }
+ }
+ }
+}
diff --git a/tests/auto/qmlls/utils/data/highlights/componentNoBound.qml b/tests/auto/qmlls/utils/data/highlights/componentNoBound.qml
new file mode 100644
index 0000000000..d4d89d11d0
--- /dev/null
+++ b/tests/auto/qmlls/utils/data/highlights/componentNoBound.qml
@@ -0,0 +1,19 @@
+// Copyright (C) 2025 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+import QtQuick
+// pragma ComponentBehavior: Bo
+
+Item {
+ id: outer
+
+ Component {
+ id: myComponent
+
+ Rectangle {
+ Component.onCompleted: {
+ outer.width.toFixed() // externalId, field, method
+ }
+ }
+ }
+}
diff --git a/tests/auto/qmlls/utils/tst_qmlls_highlighting.cpp b/tests/auto/qmlls/utils/tst_qmlls_highlighting.cpp
index 16add97c5e..0da077586e 100644
--- a/tests/auto/qmlls/utils/tst_qmlls_highlighting.cpp
+++ b/tests/auto/qmlls/utils/tst_qmlls_highlighting.cpp
@@ -764,6 +764,22 @@ void tst_qmlls_highlighting::highlights_data()
<< Token(QQmlJS::SourceLocation(271, 11, 11, 60),
int(SemanticTokenProtocolTypes::Method), 0);
}
+ { // known member of parent scope
+ const auto filePath = m_highlightingDataDir + "/componentBound.qml";
+ const auto fileItem = fileObject(filePath);
+ QTest::addRow("outerIDWithComponentBound")
+ << fileItem
+ << Token(QQmlJS::SourceLocation(296, 5, 15, 17),
+ int(SemanticTokenProtocolTypes::Variable), 0);
+ }
+ { // known member of parent scope with no component bound
+ const auto filePath = m_highlightingDataDir + "/componentNoBound.qml";
+ const auto fileItem = fileObject(filePath);
+ QTest::addRow("outerIDWithNoComponentBound")
+ << fileItem
+ << Token(QQmlJS::SourceLocation(296, 5, 15, 17),
+ int(SemanticTokenProtocolTypes::Variable), 0);
+ }
}
void tst_qmlls_highlighting::highlights()