From 99c8a040f6e2a8a8733e94fbd07986b4f5982211 Mon Sep 17 00:00:00 2001 From: Sami Shalayel Date: Wed, 29 Nov 2023 16:48:04 +0100 Subject: 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 Reviewed-by: Fabian Kosmale --- src/qml/parser/qqmljs.g | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/qml/parser/qqmljs.g') 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; ./ -- cgit v1.2.3