aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorSemih Yavuz <semih.yavuz@qt.io>2024-04-23 20:19:05 +0200
committerSemih Yavuz <semih.yavuz@qt.io>2024-05-07 13:35:05 +0200
commit592a830d0cee0a92148ebb4d0a3ae522f1f5b300 (patch)
treefc903b776492350f5cae4c6f4e04b3bdb16fe216 /tests/auto
parenta9d7ef753027df07731e53a6b350cf41b760f74e (diff)
semantichighlighting: add highlights for imports
Imports can have the syntax of "import <Module> [VersionNumer] [as Qualifer]. Module and Qualifier elements are mapped to Namespace field in the protocol. Version number will be colorized as number. If the import uri type is directory, then it should be colorized as strings. Task-number: QTBUG-1200000 Change-Id: I8674c8eba21d427e7df174db9753ccbcd2f46bdf Reviewed-by: Dmitrii Akshintsev <dmitrii.akshintsev@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qmlls/utils/data/highlights/imports.qml9
-rw-r--r--tests/auto/qmlls/utils/tst_qmlls_highlighting.cpp22
2 files changed, 31 insertions, 0 deletions
diff --git a/tests/auto/qmlls/utils/data/highlights/imports.qml b/tests/auto/qmlls/utils/data/highlights/imports.qml
new file mode 100644
index 0000000000..1e69077070
--- /dev/null
+++ b/tests/auto/qmlls/utils/data/highlights/imports.qml
@@ -0,0 +1,9 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+import QtQuick
+import QtQml 2.15
+import "X" as Patron
+
+Item {
+}
diff --git a/tests/auto/qmlls/utils/tst_qmlls_highlighting.cpp b/tests/auto/qmlls/utils/tst_qmlls_highlighting.cpp
index 778b513368..5ee3d1720d 100644
--- a/tests/auto/qmlls/utils/tst_qmlls_highlighting.cpp
+++ b/tests/auto/qmlls/utils/tst_qmlls_highlighting.cpp
@@ -195,6 +195,28 @@ void tst_qmlls_highlighting::highlights_data()
<< Token(QQmlJS::SourceLocation(232, 5, 13, 9),
int(SemanticTokenTypes::Comment), 0);
}
+ { // Imports
+ const auto filePath = m_highlightingDataDir + "/imports.qml";
+ const auto fileItem = fileObject(filePath);
+ QTest::addRow("import-keyword")
+ << fileItem
+ << Token(QQmlJS::SourceLocation(112, 6, 4, 1), int(SemanticTokenTypes::Keyword), 0);
+ QTest::addRow("module-uri") << fileItem
+ << Token(QQmlJS::SourceLocation(119, 7, 4, 8),
+ int(SemanticTokenTypes::Namespace), 0);
+ QTest::addRow("directory-uri")
+ << fileItem
+ << Token(QQmlJS::SourceLocation(152, 3, 6, 8), int(SemanticTokenTypes::String), 0);
+ QTest::addRow("as-keyword") << fileItem
+ << Token(QQmlJS::SourceLocation(156, 2, 6, 12),
+ int(SemanticTokenTypes::Keyword), 0);
+ QTest::addRow("version-number")
+ << fileItem
+ << Token(QQmlJS::SourceLocation(140, 4, 5, 14), int(SemanticTokenTypes::Number), 0);
+ QTest::addRow("qualified-namespace") << fileItem
+ << Token(QQmlJS::SourceLocation(159, 6, 6, 15),
+ int(SemanticTokenTypes::Namespace), 0);
+ }
}
void tst_qmlls_highlighting::highlights()