aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSemih Yavuz <semih.yavuz@qt.io>2024-04-04 18:15:09 +0200
committerSemih Yavuz <semih.yavuz@qt.io>2024-05-07 13:34:45 +0200
commit9b45edfda190ff6bf94995e489633322a3a4ee33 (patch)
treeac00e4aaf8eaf636563c9cd2842fa90fe62766a5 /tests
parentfb647bbfe5dd6bf7f5ff6c28a258c922b3d66bfc (diff)
qmldomcomments: include comment start string in the comment location
Parser doesn't take comment start strings into account. So, // or /* is not the part of the source location. Add this via this post-processing. The full comment region is required for semantic highlighting. This is obviously not the correct layer for a fix. The actual fix should go in the parser level which is tracked by QTBUG-124897. Task-number: QTBUG-124897 Task-number: QTBUG-120000 Change-Id: I1759edf512c21809955531ba6d5dfe4ec2f7d678 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qmldom/domdata/domitem/fileLocationRegions/comments.qml12
-rw-r--r--tests/auto/qmldom/domitem/tst_qmldomitem.h41
2 files changed, 53 insertions, 0 deletions
diff --git a/tests/auto/qmldom/domdata/domitem/fileLocationRegions/comments.qml b/tests/auto/qmldom/domdata/domitem/fileLocationRegions/comments.qml
new file mode 100644
index 0000000000..a69505c544
--- /dev/null
+++ b/tests/auto/qmldom/domdata/domitem/fileLocationRegions/comments.qml
@@ -0,0 +1,12 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+import QtQml
+
+/*
+splitting
+multiline
+*/
+// single line
+/* another comment */
+QtObject {}
diff --git a/tests/auto/qmldom/domitem/tst_qmldomitem.h b/tests/auto/qmldom/domitem/tst_qmldomitem.h
index 4464333b6e..97cc26bbd7 100644
--- a/tests/auto/qmldom/domitem/tst_qmldomitem.h
+++ b/tests/auto/qmldom/domitem/tst_qmldomitem.h
@@ -3404,6 +3404,47 @@ private slots:
QVERIFY(comments.contains(u"/*Ast Comment*/ "_s));
}
+ void commentLocations()
+ {
+ auto envPtr = DomEnvironment::create(
+ QStringList(),
+ QQmlJS::Dom::DomEnvironment::Option::SingleThreaded
+ | QQmlJS::Dom::DomEnvironment::Option::NoDependencies);
+
+ const auto filePath = baseDir + u"/fileLocationRegions/comments.qml"_s;
+ QFile f(filePath);
+ QVERIFY(f.open(QIODevice::ReadOnly | QIODevice::Text));
+ QString code = f.readAll();
+ DomItem file;
+ envPtr->loadFile(FileToLoad::fromMemory(envPtr, filePath, code),
+ [&file](Path, const DomItem &, const DomItem &newIt) {
+ file = newIt.fileObject();
+ });
+ envPtr->loadPendingDependencies();
+
+ const auto expctedCommentLocations = QSet {
+ QQmlJS::SourceLocation(0, 41, 1, 1),
+ QQmlJS::SourceLocation(42,68, 2, 1),
+ QQmlJS::SourceLocation(126,25, 6, 1),
+ QQmlJS::SourceLocation(152,14, 10, 1),
+ QQmlJS::SourceLocation(167,21, 11, 1)
+ };
+
+ QSet<SourceLocation> locs;
+ file.fileObject(GoTo::MostLikely).visitTree(Path(), [&locs](Path, const DomItem &item, bool){
+ if (item.internalKind() == DomType::Comment) {
+ const auto comment = item.as<Comment>();
+ if (comment) {
+ locs << comment->info().sourceLocation();
+ }
+ }
+ return true;
+ }, VisitOption::Default, emptyChildrenVisitor, emptyChildrenVisitor);
+
+
+ QCOMPARE(locs, expctedCommentLocations);
+ }
+
private:
QString baseDir;
QStringList qmltypeDirs;