aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUladzislau Paulovich <selatnick@gmail.com>2019-06-09 02:27:01 +0300
committerselatnick <selatnick@gmail.com>2019-06-11 15:23:17 +0000
commit8f7cbd6416debf2214977a43edeb5f90b5cee702 (patch)
tree2f9804425a066fea22133d3842669047e5252b71
parent8dc16d55c26af46101365434f0f29847c3959cc7 (diff)
qml | Fix trailing comments formatting
Change-Id: I0461c4616cff15b7010e3844850d32e9f07469ea Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
-rw-r--r--src/libs/qmljs/qmljsreformatter.cpp6
-rw-r--r--tests/auto/qml/reformatter/comments.qml8
2 files changed, 14 insertions, 0 deletions
diff --git a/src/libs/qmljs/qmljsreformatter.cpp b/src/libs/qmljs/qmljsreformatter.cpp
index deea5d94048..6ac55b2ccec 100644
--- a/src/libs/qmljs/qmljsreformatter.cpp
+++ b/src/libs/qmljs/qmljsreformatter.cpp
@@ -96,6 +96,7 @@ class Rewriter : protected Visitor
int _lastNewlineOffset = -1;
bool _hadEmptyLine = false;
int _binaryExpDepth = 0;
+ bool _hasOpenComment = false;
public:
Rewriter(Document::Ptr doc)
@@ -201,6 +202,9 @@ protected:
void out(const QString &str, const SourceLocation &lastLoc = SourceLocation())
{
+ if (_hasOpenComment) {
+ newLine();
+ }
if (lastLoc.isValid()) {
QList<SourceLocation> comments = _doc->engine()->comments();
for (; _nextComment < comments.size(); ++_nextComment) {
@@ -371,6 +375,7 @@ protected:
{
// if preceded by a newline, it's an empty line!
_hadEmptyLine = _line.trimmed().isEmpty();
+ _hasOpenComment = false;
// if the preceding line wasn't empty, reindent etc.
if (!_hadEmptyLine) {
@@ -524,6 +529,7 @@ protected:
out(" ");
out(toString(nextCommentLoc));
+ _hasOpenComment = true;
}
}
}
diff --git a/tests/auto/qml/reformatter/comments.qml b/tests/auto/qml/reformatter/comments.qml
index 4ced7eb0e89..d2caa1b555e 100644
--- a/tests/auto/qml/reformatter/comments.qml
+++ b/tests/auto/qml/reformatter/comments.qml
@@ -21,5 +21,13 @@ Item {
{
console.log("test")
}
+
+ var a = 1
+ if (a > 0) {
+ console.log("positive")
+ } // Final condition
+ else {
+ console.log("negative or zero")
+ }
}
}