AndreOneti / qml-formatter

Formatter, definition and autocomplete for QML language
MIT License
18 stars 2 forks source link

square bracket support #24

Open zhanglongqi opened 2 years ago

zhanglongqi commented 2 years ago

My code is like this

import QtQuick

Rectangle {
    height: 50
    property string message: "debug message"
    property var msgType: [
        "debug",
        "warning",
        "critical"
    ]
    color: "black"

    Column {
        anchors.fill: parent
        padding: 5.0
        spacing: 2
        Text {
            text: msgType.toString().toUpperCase() + ": "
            font.bold: msgType == "critical"
            font.family: "Terminal Regular"
            color: msgType === "warning" || msgType === "critical" ? "red": "yellow"
            ColorAnimation on color {
            running: msgType == "critical"
            from: "red"
            to: "black"
            duration: 1000
            loops: msgType == "critical" ? Animation.Infinite: 1
            }
        }
    Text {
        text: message
        color: msgType === "warning" || msgType === "critical" ? "red": "yellow"
        font.family: "Terminal Regular"
        }
    }
}

expected like this:

image

but we got this

image

qarmin commented 2 years ago

Smaller example

Repeater {
    model: [
        root.model[2] ]
}

is converted to

Repeater {
    model: [
        root.model[2] ]
    }

but

Repeater {
    model: [
        root.model[2]
    ]
}

works fine

vinchatl commented 2 years ago

Other example with json-like elements inside square brackets :

ComboBox {
    textRole: "text"
    valueRole: "value"
    model: [
        { value: "value1", text: "text1" },
        { value: "value2", text: "text2" }
    ]
}

Once formatted, json-like elements are put at the same indent as properties (in v1.3.0) :

ComboBox {
    textRole: "text"
    valueRole: "value"
    model: [
    { value: "value1", text: "text1" },
    { value: "value2", text: "text2" }
    ]
}

but they should remained indented.