Details
-
Task
-
Resolution: Unresolved
-
P2: Important
-
6.8
-
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 practicesThere are basically three things that we'd need:
- A way to to expose additional name -> type mapping for qmllint/the LSP
- A way to detect setContextProperty calls in the C++ code (that could even be running grep)
- 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
- Context property in Qml Component
(could be an undeclared required property)
// file1.qml import QtQuick Item { property Component c: Item { function f() { return myContextProperty1; } } }
- 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; } } }
- Context property in Inline Component
(could be an undeclared required property)
// file3.qml import QtQuick Item { component IC: Item { function f() { return myContextProperty1; } } }
- 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; } } }
- Context property used in QML top-level type
(could be an undeclared required property)
// file5.qml import QtQuick Item { function f() { return myContextProperty1; } }
- 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; } }
- 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; } }
- 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; } }
- 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
- is required for
-
QTBUG-119890 qmllint warnings: reach feature parity with QtCreator
-
- In Progress
-
- resulted from
-
QTCREATORBUG-25689 Do not highlighting registered property in editor
-
- Closed
-
-
QTCREATORBUG-25316 AutoComplete of properties inside of a context property does not always work
-
- Closed
-
-
QTCREATORBUG-26071 QQmlContext setContextProperty providing property tooltip inconsistently
-
- Closed
-
Gerrit Reviews
For Gerrit Dashboard: QTBUG-128232 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
638530,14 | qqmljscontextproperties: "grep" for setContextProperty calls | dev | qt/qtdeclarative | Status: NEW | +2 | +1 |
638531,15 | qmlls: add support for context properties warnings | dev | qt/qtdeclarative | Status: NEW | +1 | 0 |
638819,7 | QQmlJSLinter: add crude context properties warnings | dev | qt/qtdeclarative | Status: NEW | 0 | 0 |
638821,9 | qmllint: add option for context property warnings | dev | qt/qtdeclarative | Status: NEW | +2 | 0 |
641605,2 | qmllintsuggestions: allow to re-lint a file | dev | qt/qtdeclarative | Status: NEW | +2 | 0 |
641606,5 | qmlls: search context properties for new root urls | dev | qt/qtdeclarative | Status: NEW | +1 | 0 |
641467,3 | tst_qmlls_modules: encapsulate expected warnings | dev | qt/qtdeclarative | Status: MERGED | +2 | 0 |