QMLJSEditor: Fix calling qmlformat on save

Since the "format(...)" function would always create a temporary
file first and then let qmlformat work on that it could not find a
user supplied .qmlformat.ini in the project folder.

To fix this we now create the temporary file next to the actual file.
That way the qmlformat tool (and others) can find their config files
in the tree hierarchy.

Fixes: QTCREATORBUG-29668
Change-Id: I708efbd4bba014bc5743d901725b6fdaa06fefd8
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Marcus Tillmanns
2024-08-12 11:22:42 +02:00
parent 782e7326e1
commit 310ec8d6a1

View File

@@ -62,8 +62,9 @@ static FormatOutput format(const FormatInput &input)
switch (input.command.processing()) {
case Command::FileProcessing: {
// Save text to temporary file
Utils::TempFileSaver sourceFile(Utils::TemporaryDirectory::masterDirectoryPath()
+ "/qtc_beautifier_XXXXXXXX." + input.filePath.suffix());
Utils::TempFileSaver sourceFile(
input.filePath.parentDir()
/ (input.filePath.fileName() + "_format_XXXXXXXX." + input.filePath.suffix()));
sourceFile.setAutoRemove(true);
sourceFile.write(input.sourceData.toUtf8());
if (!sourceFile.finalize()) {