Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
6.7
-
None
-
ff6d16d58 (dev), ada7ce820 (6.7), dfb65530f (dev), f6fc3cc66 (dev), 35bba9ab7 (dev), b0cc4d024 (dev), 9ee160941 (dev)
Description
It seems that comment formatting is broken in qmlls 6.7: comments either disappear after formatting or they end up at the wrong places.
The reason for that is a bad cooperation between the new FileLocationRegions introduced by the autocompletion feature and the comment placement method AstComments::collectComment(). collectComments() will try to place comments next to the nearest FileLocationRegion, which now might be one that was introduced by the autocompletion feature.
In qmlformat and tst_qmlformat, this is not a problem because the FileLocations were not modified in the "normal" Dom. In qmlls, on the other hand, we add extra FileLocations during the Dom construction and then the formatting gets impacted by that bug.
The comments being at wrong places is explained by collectComment() attaching the comment to the wrong FileLocationRegion. Some comments, however, disappear in the formatted code: this is due to inconsistencies in the writeOut() methods, for example QmlObject::writeOut() will do:
ow.writeRegion(LeftBraceRegion, u" {").newline(); /* ... */ ow.ensureNewline().write(u"}");}}
where writeRegion() will add comments before/after the LeftBraceRegion but write() will ignore any comment attached to the RightBraceRegion filelocationregion, for example in:
QtObject { // this comment is attached to the RightBraceRegion and will disappear when formatted in qmlls when using with https://codereview.qt-project.org/c/qt/qtdeclarative/+/526982/4, }
Comments being moved or deleted during formatting is not too bad as the user can always revert the formatting via CTRL-Z. But it is still a weird for the user if the same code that would get formatted correctly via qmlformat does not work correctly in qmlls.
Another reproducer that works on dev without https://codereview.qt-project.org/c/qt/qtdeclarative/+/526982/4 :
import QtQml QtObject { // This to enum enum Foo { A = 3, // This is A B, // This is B C = 4, // This is C D // This is D } }
Attachments
Issue Links
- resulted from
-
QTBUG-113727 qmlls: improve Code completion using new QQmlLSUtils stuff
- Closed
For Gerrit Dashboard: QTBUG-120484 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
528017,8 | qmlls: fix formatting of comments | dev | qt/qtdeclarative | Status: MERGED | +2 | 0 |
530937,3 | qmldomcomments:Get rid of redundant items | dev | qt/qtdeclarative | Status: MERGED | +2 | 0 |
530938,3 | qqmldomcomments: Add comment type in Comment class | dev | qt/qtdeclarative | Status: MERGED | +2 | 0 |
530939,10 | qqmldomcomments: link comments to nodes or regions by CommentCollector | dev | qt/qtdeclarative | Status: MERGED | +2 | 0 |
531081,2 | qmlls: fix formatting of comments | 6.7 | qt/qtdeclarative | Status: MERGED | +2 | 0 |
531230,8 | qqmldomcomments: remove dead code | dev | qt/qtdeclarative | Status: MERGED | +2 | 0 |
531687,10 | Filter down item regions that comments can attach to | dev | qt/qtdeclarative | Status: MERGED | +2 | 0 |