-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
6.7
-
None
-
ccc830877 (6.8), a3863b2d8 (dev), 240d2d190 (dev), bc6b4940a (dev), d8a1e840e (6.10), a46ee0635 (6.10), 70ab48778 (6.10), fcd85f201 (6.9), e4cbd81ca (6.9), 6436e8716 (6.9), 68fca3511 (tqtc/lts-6.8), 3848ec04e (tqtc/lts-6.8), ca263ec76 (tqtc/lts-6.8)
Problems
Briefly here are the problems:
Comments around MethodParameters are lost. In both "standalone" ES and when ES is used inside QmlObjectInproper formatting when Comment is between the function keyword and the functionIdentifier (not a common case though, but there might be more common problems from that set or when it manifests it spoils the code)Commented Body of the Method or Class results in a loss or duplication and wrong placement in the "standalone" ES (relatively bad, but not really a common usecase maybe?), but in case of QmlObject a \n character is added (not bad, but just weird, haven't seen smth similar).- If a Body of the item is commented, it moved up. (almost non-important, but for the sake of completeness of the observation and I personally haven't seen similar formatter behaviors)
For standalone ES, Prettier (https://prettier.io/) can be used for references.
High level architecture (Current State) and Issues
See https://qtgroup.atlassian.net/wiki/x/F4BdDg
Some Dragons with Comment attachment
- We probably don't need to Link comments to the `DomItem,FileLocationRegion`-s and to `AST::Node, offset` and can probably work just with SourceLocation-s
- CommentLinker lacks encapsulation / modularity. For example CommentLinker takes in a constructor a reference to an integer (lastPostCommentPostEnd) which is used and modified during the linkCommentWithElement, however that integer variable outlives the lifetime of the CommentLinker.[1].
Another opportunity for encapsulation and modularity is the way CommentLinker stores intermediately processed information.[2] - findSpacesAroundComment is not tested and it's not clear whether there might be a cleaner/more straightforward approach.
- The whole algorithm of CommentLinker::linkCommentWithElement is not documented, not covered by unit tests. The high level order is not really clear, but lower level function like checkElementAfterComment, checkElementBeforeComment, checkElementInside are hard to debug, reason about and make changes (if you find it otherwise, pls reach out to me and help me to figure it out). There is no knowledge about the corner cases, but there are many questions whether there could be a leaner solution.
Refactoring attempts / inspo
- Refactor CommentCollector API and introduce more modularity https://codereview.qt-project.org/c/qt/qtdeclarative/+/551774
- More "one step at a time" style refactoring of CommentCollector https://codereview.qt-project.org/c/qt/qtdeclarative/+/552710/1
- Rough attempt to introduce unit tests and figure out what's going on https://codereview.qt-project.org/c/qt/qtdeclarative/+/552703
Notes / References
[1] see the usage of lastPostCommentPostEnd and m_lastPostCommentPostEnd
[2] Even though some of the coupling most likely imposed by the complexity of how ASTRangesVisitor deals with ranges of "Elements", but it's still might be beneficial to separate handling / storing Comment-specific Info (like CommentLocation, m_spaces) and m_ranges. Currently everything is initialised altogether in the CommentLinker constructor. For me personally it's also quite hard to have Iterators initialized at the constructor stage...
- blocks
-
QTBUG-98766 qmlformat handles large code base and complex projects
-
- Open
-
-
QTBUG-117849 qmlformat: support formatting of plain JS files
-
- Closed
-
- is required for
-
QTCREATORBUG-33333 QML Formatter improvement
-
- Closed
-
- relates to
-
QTBUG-126010 qmlformat: comment after a curly brace { moved to a separate line
-
- Reported
-
-
QTBUG-124257 Incorrect SourceLocation of the comment, calculated by engine
-
- Closed
-
-
QTBUG-133679 qmlformat: Post-Comment moves ',' to next line
-
- Reported
-
-
QTBUG-137944 qmlformat moves qmlint comments, removes function argument annotations
-
- In Progress
-
-
QTBUG-133316 qmldom/qmlformat: Comments are broken in certain positions
-
- Closed
-
-
QTBUG-133685 qmlformat: Post-Comment moves ';'
-
- Closed
-
-
QTCREATORBUG-33333 QML Formatter improvement
-
- Closed
-