diff options
author | Sami Shalayel <sami.shalayel@qt.io> | 2023-11-29 16:48:04 +0100 |
---|---|---|
committer | Sami Shalayel <sami.shalayel@qt.io> | 2023-12-05 17:50:35 +0100 |
commit | 99c8a040f6e2a8a8733e94fbd07986b4f5982211 (patch) | |
tree | e3d56d3a59c041e65a504bf36b18856dfcace7e7 /src/qml/parser/qqmljs.g | |
parent | 2313dc93733b6fa46dd0de5711b9f4053768552e (diff) |
qmlls: completions in variable declarations
Add the equal token sourcelocation into a ScriptPattern. This is
somewhat cumbersome because the parser has no direct access to it.
Instead, create a new ExpressionNode type called InitializerExpression:
it contains an ExpressionNode and an equaltoken, and is populated in the
parser for Initializer and Initializer_In rules. It also implements some
pure virtual methods to not be abstract, and has its own
Kind_InitializerExpression.
The PatternElement constructor extracts the location of the equaltoken
from the InitializerExpression in its constructor, and saves it in its
new member equaltoken.
Later on, the Dom constructor will be able to add the location of the
equal token to the Dom, such that qmlls's completion can decide whether
or not completion is required in variable declaration statements.
With this commit, qmlls will provide completions only after the above
mentioned equal token. The explanation is in a comment in qqmllsutils,
but the rough idea is that everything before the '=' is a variable name
(so it should not be in use yet, to avoid shadowing and confusing QML
programs) and that everything behind a '=' is a default value that can
be any arbitrary expression in JS. This default value can be a method
name, a property name, etc, so provide completion at this place.
Also takes care of completions inside of deconstructions nested inside
variable declarations.
Task-number: QTBUG-117445
Change-Id: Ie58ffda4de9636796a9a690537affef85ede398d
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/parser/qqmljs.g')
-rw-r--r-- | src/qml/parser/qqmljs.g | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/qml/parser/qqmljs.g b/src/qml/parser/qqmljs.g index 6d9d11800c..bc5955245a 100644 --- a/src/qml/parser/qqmljs.g +++ b/src/qml/parser/qqmljs.g @@ -2167,7 +2167,9 @@ Initializer: T_EQ AssignmentExpression; Initializer_In: T_EQ AssignmentExpression_In; /. case $rule_number: { - sym(1) = sym(2); + auto node = new (pool) AST::InitializerExpression(sym(2).Expression); + node->equalToken = loc(1); + sym(1).Expression = node; } break; ./ |