Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-128232

qmlls: add crude support for context properties

    XMLWordPrintable

Details

    • Task
    • Resolution: Unresolved
    • P2: Important
    • 6.11
    • 6.8
    • QML: Tooling
    • None

    Description

      Add crude support to qmlls for context properties to warn about them, and maybe also suggest them.

      Extracts from the chat:

      Basically, we should have some support at the tooling level, if only to provide proper warnings (basically, usages of context properties shouldn't show "typo fix" suggestions, but rather a message that context properties are bad)
      We don't want to encourage the use of context properties, but we also should make it somewhat easy to gradually migrate projects to best practices

      There are basically three things that we'd need:

      1. A way to to expose additional name -> type mapping for qmllint/the LSP
      2. A way to detect setContextProperty calls in the C++ code (that could even be running grep)
      3. some integration with the C++ code model to detect the actual type of what is passed to setContextProperty

      1 + 2 would already be enough to complete context properties itself if we map them to var; 3. is probably too much effort, given that the clangd based code model doesn't have that integration point

      We can require that the user uses qmlls, declarative type registration and Qt 6 for this task.

      Scenarios where we might want to warn:
      = complain about context property instead of unqualified access warning, = keep current unqualified access warning, = not sure whether to warn about unqualified access or context property

      1. Context property in Qml Component (could be an undeclared required property)
        // file1.qml
        import QtQuick
        Item {
            property Component c: Item { function f() { return myContextProperty1; } }
        }
        
      1. Context property in Qml Component with required property (one required property is defined, so all missing properties have to be context property for the QML Engine to not reject the component)
        // file2.qml
        import QtQuick
        Item {
            property Component c2: Item {
                required property int i;
                function f() { return myContextProperty1; }
            }
        }
        
      2. Context property in Inline Component (could be an undeclared required property)
        // file3.qml
        import QtQuick
        Item {
            component IC: Item { function f() { return myContextProperty1; } }
        }
        
      3. Context property in Inline Component with required property (one required property is defined, so all missing properties have to be context property for the QML Engine to not reject the component)
        // file4.qml
        import QtQuick
        Item {
            component IC: Item {
                required property int i;
                function f() { return myContextProperty1; }
            }
        }
        
      4. Context property used in QML top-level type (could be an undeclared required property)
        // file5.qml
        import QtQuick
        Item {
            function f() { return myContextProperty1; }
        }
        
      5. Context property used in QML top-level with required property (one required property is defined, so all missing properties have to be context property for the QML Engine to not reject the component)
        // file6.qml
        import QtQuick
        Item {
            required property int i
            function f() { return myContextProperty1; }
        }
        
      6. Context property used in QML top-level with required property shadowing an unrelated context property (one required property is defined, so all missing properties have to be context property for the QML Engine to not reject the component)
        // file7.qml
        import QtQuick
        Item {
            required property int myContextProperty2
            function f() { return myContextProperty1; }
        }
        
      7. Context property used in QML top-level with a shadowed required property (this scenario is not even an unqualified access)
        // file8.qml
        import QtQuick
        Item {
            required property int myContextProperty1
            function f() { return myContextProperty1; }
        }
        
      1. Context property used in QML child (this is an unqualified access, it could be
        // file5.qml
        import QtQuick
        Item {
            function f() { return myContextProperty1; }
        }
        

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-128232
          # Subject Branch Project Status CR V

          Activity

            People

              sami.shalayel Sami Shalayel
              sami.shalayel Sami Shalayel
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews