Commit Graph

16 Commits

Author SHA1 Message Date
Ulf Hermann 66af11c6cb Avoid various inefficiencies
Coverity-Id: 435555
Coverity-Id: 435556
Coverity-Id: 435557
Coverity-Id: 435559
Coverity-Id: 435561
Coverity-Id: 435562
Coverity-Id: 435563
Coverity-Id: 435564
Coverity-Id: 435565
Coverity-Id: 435566
Coverity-Id: 435567
Coverity-Id: 435568
Coverity-Id: 435569
Change-Id: If482bde0189b72297f09e3ff28c825364d68fd89
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2024-01-30 17:14:09 +01:00
Dmitrii Akshintsev ade897c021 QQmlJS::Dom::OutWriter. Refactoring
The refactoring consists of:
- Changing writeOut & writeOutForFile API
to return boolean instead of MutableDomItem, which better reflects
the existing usecases improving consistency of the data model*
Moreover, previous API was exposing DomItem, which was not "committed
to base" (MutableDomItem.commitToBase()), meaning it was exposing the
"unmerged" Item alongside with the "temporary environment"
- Refactoring & renaming OutWriter::updatedFile
breaking it into smaller chunks preserving
only necessary functionality
- Adding some comments / documentation

Before this commit, the writeOut API was "exposing",so called,
"updatedFile", which is basically the copy of the original fileItem +
renewed scriptExpressions which were modified during the writeOut of
the original fileItem.
The idea behind the "mutating" Dom API is that one has to create a
 MutableDomItem, do some changes to it and then "commit" them.
This process is also facilitated by the creation of separate Env.
(git analogy might be handy here:
We create a separate branch, where all the mutation will happen and then
we "merge" this branch)
However, in the writeOutForFile usecase this "updatedFile" was needed
only for the verifying of the consistency of the "writtenOut" DOM,
however the API was exposing it further back to the caller sites,
without "committing".
The potential issue here is inconsistency of the data Model.
On one side we have an original File Item owned by the Base Env,
on the other side we have an "updatedFile" which is owned by another Env.
Taking into account that there are no usecases requiring "exposing"
"updatedFile", but also no need for "committing" the changes,
It's arguably better to keep that temporary "updatedFile" locally,
not exposing it outside the writeOutForFile function. Thereby improving
consistency of the data model.

Change-Id: If45eca4b4d6d703e2a76d0580f124d0292af5ed8
Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
2024-01-25 18:35:04 +01:00
Dmitrii Akshintsev bce3842fa0 QmlFormat. Minor refactoring of the qmlformat.cpp
Breaking  main (qmlformat.cpp) into smaller chunks,
providing better separation of concerns and improving readability

Change-Id: Iadc236d73d3da5e150cdfd41a34baa12d63da6a8
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2024-01-23 20:34:26 +01:00
Dmitrii Akshintsev 3805424abc DOM refactoring. Move loadPendingDependencies to DomEnvironment
One of the goals of this refactoring is to move DomTop specific
functionality from DomItem API to the corresponding DomEnvironment
and DomUniverse.

This commit moves loading of the dependencies (which are added to
the pending load queue implicitly as part of the callbacks of the
loadFile when DomEnv is created without the flag "NoDependencies") to
the DomEnvironment interface

Moreover, once work with dependencies is happening through the
DomEnvironment explicitly, it allows us to get rid of "self"
parameter.

Task-number: QTBUG-119550
Change-Id: Ib3deb97eabe091ffded8c8c782ee08f8024468f2
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
2024-01-18 18:46:18 +01:00
Dmitrii Akshintsev bb4391a93e DOM refactoring. Remove DomItem::loadItem. enable_shared_from_this for DomEnv*
As it was mentioned in the previous commits in the chain one of the
goals of the refactoring is to introduce clearer separation of
concerns.
Only DomTop types are allowed to load files, hence it's arguable
should be reflected in the interfaces explicitly.
With the help of previous commits the relevant pieces of this
function were moved to the corresponding DomEnvironment and DomUniverse
types.
This commit finally removes loadFile from the DomItem API.

*It's also worth noting that in order to minimaze refactoring
efforts and to keep the public API simple (not requiring
DomItem &self argument on the top level), this commit also makes
DomEnvironment a child of the std::enable_shared_from_this.
This somewhat "breaks" the initial design approach inscribed
in the DOM API allowing DomEnvironemt to get a shared_ptr to itself
bypassing corresponding DomItem.ownerAs<> API.
However, in the tradeoff of preserving consistency of the previous
design and the explicitness of the interface, I would value the latter,
hence I find this change acceptable.

Change-Id: Ic2ce3fc80876be6bdbec93e4d273e4c6b7a2b218
Task-number: QTBUG-119550
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2024-01-18 11:12:30 +01:00
Semih Yavuz 8aa5d17618 qmlformat: fix formatting with -F option
qmlformat accepts -F option to format a list of files given in another
file. That should supposed to be inplace, but qmlformat would send
output to stdout. To fix this, force inplace formatting if the
options.files are not empty.

Change-Id: If62dd3edde91460eba5812b1d7aea1b7422f46bf
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2023-10-16 18:28:49 +02:00
Ulf Hermann 27dcc63e00 QmlDom: Don't pass ErrorMessage by value
When iterating, pass it by const ref. When "adding" pass it by rvalue
ref. In the few places where that clashes, copy it explicitly.

Coverity-Id: 417092
Change-Id: I93b2d671c38a2f44334929fd7ec9c2f1a18caac8
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
2023-09-15 15:32:40 +02:00
Sami Shalayel 6913084b0d Remove DomItem::loadFile code-duplication and use correct environments
The loadFile overload (in DomItem, DomEnvironment and DomUnivers) for
different files (in-memory files and files that needs to be loaded from
disk) are either copypasted or just calling the other overload.

Encapsulate the file-related arguments of all loadFile overloads into a
new struct called FileToLoad, such that the copypasted overloads can be
removed. Use the static factory function FileToLoad::fromMemory and
FileToLoad::fromFileSystem to create the FileToLoad struct.

In addition, FileToLoad allows to specify the environment in which a
file should be loaded. Prior this commit, myEnv.loadFile() was creating
a new environment for each loaded file.

Change-Id: I3b6acb681cb77faefdaa447d985bdfbe4f6a9ce2
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-03-29 19:07:25 +02:00
Sami Shalayel 3a985babf9 qmlls: move into own private static library
Qmlls was completely implemented in the ./tools directory, which made
its code complicated to test and try out. Also, it required some "dirty"
hacks in the actual tests (including files from others targets to be
able to use them) and made testing new features for qmlls more
complicated.

To remedy this, the qmlls code was split into a tool (qmlls) and
a static library (QmlLSPrivate). The tool only contains
tools/qmlls/qmllanguageservertool.cpp (which has the qmlls main method)
and links to QmlLSPrivate, that contains all the other qmlls-related
code. This way, the tests can also link to QmlLSPrivate and test out
individual functions there without needing to include files from other
targets.

Also rename all the files to make syncqt happy (adding "_p" to headers
and prepending "q" to headers and files and includeguards), and use
QString::fromUtf8() to silence the QString()-constructor deprecation
warnings.

On the way, move tools/shared/qqmltoolingsettings.* into its own private
static library, instead of recompiling it for each tool that requires
it. Move the qqmltoolingsettings stuff into the qt namespace to be
usable.

Also, add qmlls as a dependency to the qmlls tests to avoid testing an
outdated qmlls-binary.

This commit prepares qmlls's code to implement the go-to and
find-usages features.

Task-number: QTBUG-109006
Change-Id: I91eed689c68a0c53fb88006de335b0f852cc1a83
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-02-07 19:23:13 +01:00
Xavier BESSON 0e4acad6ab qmlformat: add 'ensure new line between functions' option
Fixes: QTBUG-108659
Change-Id: I3e21727bd946089d89ce9c42f640f05230de8c8e
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-11-24 11:30:03 +01:00
Xavier BESSON c016ab30c9 qmlformat: add 'ensure new line between objects' option
This option allows to format files into more 'refreshing' ones.
It improves readability thanks to a clearer visualization of objects inside files.

Change-Id: Ic3592e87ae16d14d70317d09d819cc5d331be822
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-11-14 13:11:49 +01:00
Semih Yavuz bc6c900b15 qmlformat: do not generate backup files
qmlformat used to backup the original input file up to 2 copies when used
with --inplace mode. Change this hardcoded number into 0 and generate no
backup file.

Fixes: QTBUG-107685
Change-Id: Ifca86968fa65be0fd678012fc2e41b9ed8601d21
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-10-24 18:03:05 +00:00
Lucie Gérard 0dc4fd240a Use SPDX license identifiers
Replace the current license disclaimer in files by
a SPDX-License-Identifier.
Files that have to be modified by hand are modified.
License files are organized under LICENSES directory.

Pick-to: 6.4
Task-number: QTBUG-67283
Change-Id: I63563bbeb6f60f89d2c99660400dca7fab78a294
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2022-06-11 08:05:15 +02:00
Maximilian Goldstein e14d13bea6 qmlformat: Implement settings file
Implements controlling qmlformat via a settings file as can be done for qmllint.

[ChangeLog][General][qmlformat] Adds the ability to set linting options
via a settings file rather than using command line parameters. Use
--write-defaults to generate a template with default values for editing.
Use --ignore-settings to disable this feature.

Fixes: QTBUG-86415
Change-Id: I282c3b994ca6cc491a27b45f531f1ba1c2652ef7
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-10-26 12:03:40 +02:00
Maximilian Goldstein 81ad9f39af qmlformat: Use the Qt version instead of 1.0
This makes way more sense than just sticking to 1.0 forever or introducing our own tooling versioning and is consistent with qmllint.

Pick-to: 6.2
Change-Id: Id797191e6b343b97831409e8d5f888761f91b1d5
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-06-22 11:06:36 +02:00
Fawzi Mohamed dc5d14c396 qmlformat: use QmlDom
Replace qmlformat with the formatter using qml dom

Change-Id: Ie90814260f2d3b9e589ce04381d5ad1880c5b519
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-06-05 00:08:00 +02:00