diff options
author | Sami Shalayel <sami.shalayel@qt.io> | 2023-12-21 11:04:19 +0100 |
---|---|---|
committer | Sami Shalayel <sami.shalayel@qt.io> | 2024-01-16 08:07:18 +0100 |
commit | d06ed7fdd8beec490e453ce493e53041f58a2107 (patch) | |
tree | ba1ad3a2a47df8eb8226f76f8c16c61222878016 /tests/auto/qml/qmlformat | |
parent | 1a545f4bcc28909d57d6e265f88c6b9eba52096c (diff) |
qmlls: insert semicolons behind dots as completion workaround
IDE's usually ask completion requests whenever users starts typing a
'.'. For this patch, we assume that the user is currently writing code,
that the '.' he just entered is followed by a newline and that the line
below the cursor is unrelated, which should be a pretty realistic
scenario of writing code.
For example, imagine a user typing in following code:
```
x: root.<current cursor>
SomeQualifiedModule.Item {}
```
The LSP client will request completion suggestions when the user types
in `root.` and qmlls will be confused about the completion, as it will
see a QmlObject binding in the Dom representation.
Another example are JS statements, where the parser stops working when
he sees
```
root.<current cursor>
for (;;) {}
```
because it tries to construct the function call `root.for` and has
troubles with the semicolons inside the function call argument.
To go around this problem, insert semicolons when the symbol that
requested the completion is a dot and when this dot is followed by a
newline.
In qqmlcompletionsupport, create a new Dom representation with the
patched code, and keep it out the QQmlCodeModel to avoid bothering other
modules, like the linting module, with the inserted "invisible"
semicolon (invisible in the eyes of the user).
Now, when the parser is run again on the patched code, it will see
```
root.;
```
and will happily create the correct field member expression using its
recovery mode. One could also have inserted any identifier like
'_dummyIdentifier' followed by a semicolon to get:
```
root._dummyIdentifier;
```
which would have worked too I believe.
Add two tests, one in tst_qmlls_modules to test if the patched Dom can
be used to provide the completions, and on in tst_qmlls_utils to test if
the "normal" dom construction works on (hand)patched versions of the
files. tst_qmlls_utils cannot test the patching itself as that happens
in the qqmlcompletionsupport module.
The afterDots.qml files are invalid and as such should be ignored by
tst_qmlformat.
Pick-to: 6.7
Fixes: QTBUG-119839
Change-Id: Ib914b78512894c423792588842d635d3d1467922
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlformat')
-rw-r--r-- | tests/auto/qml/qmlformat/tst_qmlformat.cpp | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlformat/tst_qmlformat.cpp b/tests/auto/qml/qmlformat/tst_qmlformat.cpp index b2a44a18c5..f5486362d0 100644 --- a/tests/auto/qml/qmlformat/tst_qmlformat.cpp +++ b/tests/auto/qml/qmlformat/tst_qmlformat.cpp @@ -139,6 +139,9 @@ void TestQmlformat::initTestCase() m_invalidFiles << "tests/auto/qmlls/utils/data/completions/missingRHS.parserfail.qml"; m_invalidFiles << "tests/auto/qmlls/utils/data/completions/attachedPropertyMissingRHS.qml"; m_invalidFiles << "tests/auto/qmlls/utils/data/completions/groupedPropertyMissingRHS.qml"; + m_invalidFiles << "tests/auto/qmlls/utils/data/completions/afterDots.qml"; + m_invalidFiles << "tests/auto/qmlls/modules/data/completions/bindingAfterDot.qml"; + m_invalidFiles << "tests/auto/qmlls/modules/data/completions/defaultBindingAfterDot.qml"; // Files that get changed: // rewrite of import "bla/bla/.." to import "bla" |