diff options
author | Semih Yavuz <semih.yavuz@qt.io> | 2024-04-04 18:15:09 +0200 |
---|---|---|
committer | Semih Yavuz <semih.yavuz@qt.io> | 2024-05-07 13:34:45 +0200 |
commit | 9b45edfda190ff6bf94995e489633322a3a4ee33 (patch) | |
tree | ac00e4aaf8eaf636563c9cd2842fa90fe62766a5 /src/qmldom/qqmldomcomments_p.h | |
parent | fb647bbfe5dd6bf7f5ff6c28a258c922b3d66bfc (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 'src/qmldom/qqmldomcomments_p.h')
-rw-r--r-- | src/qmldom/qqmldomcomments_p.h | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/qmldom/qqmldomcomments_p.h b/src/qmldom/qqmldomcomments_p.h index 732a74162a..f8fe46c098 100644 --- a/src/qmldom/qqmldomcomments_p.h +++ b/src/qmldom/qqmldomcomments_p.h @@ -38,7 +38,7 @@ class QMLDOM_EXPORT CommentInfo { Q_DECLARE_TR_FUNCTIONS(CommentInfo) public: - CommentInfo(QStringView); + CommentInfo(QStringView, QQmlJS::SourceLocation loc); QStringView preWhitespace() const { return rawComment.mid(0, commentBegin); } @@ -54,6 +54,10 @@ public: return rawComment.mid(commentEnd, rawComment.size() - commentEnd); } + // Comment source location populated during lexing doesn't include start strings // or /* + // Returns the location starting from // or /* + QQmlJS::SourceLocation sourceLocation() const { return commentLocation; } + quint32 commentBegin = 0; quint32 commentEnd = 0; quint32 commentContentBegin = 0; @@ -65,6 +69,7 @@ public: int nContentNewlines = 0; QStringView rawComment; QStringList warnings; + QQmlJS::SourceLocation commentLocation; }; class QMLDOM_EXPORT Comment @@ -90,7 +95,7 @@ public: int newlinesBefore() const { return m_newlinesBefore; } void setNewlinesBefore(int n) { m_newlinesBefore = n; } QStringView rawComment() const { return m_comment; } - CommentInfo info() const { return CommentInfo(m_comment); } + CommentInfo info() const { return CommentInfo(m_comment, m_location); } void write(OutWriter &lw, SourceLocation *commentLocation = nullptr) const; CommentType type() const { return m_type; } @@ -101,8 +106,6 @@ public: } friend bool operator!=(const Comment &c1, const Comment &c2) { return !(c1 == c2); } - QQmlJS::SourceLocation sourceLocation() const { return m_location; }; - private: QStringView m_comment; QQmlJS::SourceLocation m_location; |