forked from qt-creator/qt-creator
Json: Fix indenter for json files.
Change-Id: Id864509dd78a70fc34a3798b80f7e1c8991181f4 Reviewed-on: http://codereview.qt-project.org/6038 Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Fawzi Mohamed <fawzi.mohamed@nokia.com>
This commit is contained in:
@@ -90,6 +90,7 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
|
|||||||
switch (kind) {
|
switch (kind) {
|
||||||
case Identifier: enter(objectdefinition_or_js); continue;
|
case Identifier: enter(objectdefinition_or_js); continue;
|
||||||
case Import: enter(top_qml); continue;
|
case Import: enter(top_qml); continue;
|
||||||
|
case LeftBrace: enter(top_js); enter(expression); continue; // if a file starts with {, it's likely json
|
||||||
default: enter(top_js); continue;
|
default: enter(top_js); continue;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
|||||||
@@ -170,6 +170,9 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
|
|||||||
if (parentState.type == expression && state(1).type == binding_assignment) {
|
if (parentState.type == expression && state(1).type == binding_assignment) {
|
||||||
*savedIndentDepth = state(2).savedIndentDepth;
|
*savedIndentDepth = state(2).savedIndentDepth;
|
||||||
*indentDepth = *savedIndentDepth + m_indentSize;
|
*indentDepth = *savedIndentDepth + m_indentSize;
|
||||||
|
} else if (parentState.type == objectliteral_assignment) {
|
||||||
|
*savedIndentDepth = parentState.savedIndentDepth;
|
||||||
|
*indentDepth = *savedIndentDepth + m_indentSize;
|
||||||
} else if (!lastToken) {
|
} else if (!lastToken) {
|
||||||
*indentDepth = tokenPosition + 1;
|
*indentDepth = tokenPosition + 1;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ private Q_SLOTS:
|
|||||||
void labelledStatements1();
|
void labelledStatements1();
|
||||||
void labelledStatements2();
|
void labelledStatements2();
|
||||||
void labelledStatements3();
|
void labelledStatements3();
|
||||||
|
void json1();
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Line {
|
struct Line {
|
||||||
@@ -1198,6 +1199,33 @@ void tst_QMLCodeFormatter::labelledStatements3()
|
|||||||
checkIndent(data);
|
checkIndent(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QMLCodeFormatter::json1()
|
||||||
|
{
|
||||||
|
QList<Line> data;
|
||||||
|
data << Line("{")
|
||||||
|
<< Line(" \"lab\": \"abc\",")
|
||||||
|
<< Line(" \"foo\": \"baroooo\",")
|
||||||
|
<< Line(" \"foo\": [ \"baroooo\", \"foo\" ],")
|
||||||
|
<< Line(" \"foo\": [")
|
||||||
|
<< Line(" \"baroooo\",")
|
||||||
|
<< Line(" \"doo\"")
|
||||||
|
<< Line(" ],")
|
||||||
|
<< Line(" \"lab\": \"abc\",")
|
||||||
|
<< Line(" \"object\": {")
|
||||||
|
<< Line(" \"lab\": \"abc\",")
|
||||||
|
<< Line(" \"foo\": \"baroooo\",")
|
||||||
|
<< Line(" \"foo\": [ \"baroooo\", \"foo\" ],")
|
||||||
|
<< Line(" \"foo\": [")
|
||||||
|
<< Line(" \"baroooo\",")
|
||||||
|
<< Line(" \"doo\"")
|
||||||
|
<< Line(" ],")
|
||||||
|
<< Line(" \"lab\": \"abc\"")
|
||||||
|
<< Line(" }")
|
||||||
|
<< Line("}")
|
||||||
|
;
|
||||||
|
checkIndent(data);
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_APPLESS_MAIN(tst_QMLCodeFormatter)
|
QTEST_APPLESS_MAIN(tst_QMLCodeFormatter)
|
||||||
#include "tst_qmlcodeformatter.moc"
|
#include "tst_qmlcodeformatter.moc"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user