fix: Creating dir for new file

This commit is contained in:
Petr Mironychev
2025-11-03 13:56:25 +01:00
parent c6e77c59d3
commit 6937b48fbf

View File

@ -49,8 +49,9 @@ QString CreateNewFileTool::stringName() const
QString CreateNewFileTool::description() const QString CreateNewFileTool::description() const
{ {
return "Create a new empty file at the specified path. " return "Create a new empty file at the specified path. "
"The directory path must exist. Provide absolute file path. After crate files add file " "If the directory path does not exist, it will be created automatically. "
"to project file (CMakeLists.txt or .cmake or .pri)"; "Provide absolute file path. After creating files, add the file "
"to the project file";
} }
QJsonObject CreateNewFileTool::getDefinition(LLMCore::ToolSchemaFormat format) const QJsonObject CreateNewFileTool::getDefinition(LLMCore::ToolSchemaFormat format) const
@ -100,7 +101,6 @@ QFuture<QString> CreateNewFileTool::executeAsync(const QJsonObject &input)
QFileInfo fileInfo(filePath); QFileInfo fileInfo(filePath);
QString absolutePath = fileInfo.absoluteFilePath(); QString absolutePath = fileInfo.absoluteFilePath();
// Check if the file path is within the project
bool isInProject = Context::ProjectUtils::isFileInProject(absolutePath); bool isInProject = Context::ProjectUtils::isFileInProject(absolutePath);
if (!isInProject) { if (!isInProject) {
@ -121,8 +121,11 @@ QFuture<QString> CreateNewFileTool::executeAsync(const QJsonObject &input)
QDir dir = fileInfo.absoluteDir(); QDir dir = fileInfo.absoluteDir();
if (!dir.exists()) { if (!dir.exists()) {
throw ToolRuntimeError(QString("Error: Directory does not exist: '%1'") if (!dir.mkpath(".")) {
.arg(dir.absolutePath())); throw ToolRuntimeError(
QString("Error: Could not create directory: '%1'").arg(dir.absolutePath()));
}
LOG_MESSAGE(QString("Created directory path: %1").arg(dir.absolutePath()));
} }
QFile file(absolutePath); QFile file(absolutePath);