mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-10-21 11:26:40 -04:00
fix: Change parameter for read file tool
This commit is contained in:
@ -55,7 +55,7 @@ QString ReadProjectFileByNameTool::description() const
|
|||||||
"absolute file path. "
|
"absolute file path. "
|
||||||
"The file must exist, be within the project scope, and not excluded by "
|
"The file must exist, be within the project scope, and not excluded by "
|
||||||
".qodeassistignore.\n"
|
".qodeassistignore.\n"
|
||||||
"Input parameter: 'filename' - the absolute path to the file (e.g., "
|
"Input parameter: 'filepath' - the absolute path to the file (e.g., "
|
||||||
"'/path/to/project/src/main.cpp').\n"
|
"'/path/to/project/src/main.cpp').\n"
|
||||||
"Use 'list_project_files' tool first to get the exact file paths.";
|
"Use 'list_project_files' tool first to get the exact file paths.";
|
||||||
}
|
}
|
||||||
@ -63,17 +63,17 @@ QString ReadProjectFileByNameTool::description() const
|
|||||||
QJsonObject ReadProjectFileByNameTool::getDefinition(LLMCore::ToolSchemaFormat format) const
|
QJsonObject ReadProjectFileByNameTool::getDefinition(LLMCore::ToolSchemaFormat format) const
|
||||||
{
|
{
|
||||||
QJsonObject properties;
|
QJsonObject properties;
|
||||||
QJsonObject filenameProperty;
|
QJsonObject filepathProperty;
|
||||||
filenameProperty["type"] = "string";
|
filepathProperty["type"] = "string";
|
||||||
filenameProperty["description"] = "The absolute file path to read";
|
filepathProperty["description"] = "The absolute file path to read";
|
||||||
properties["filename"] = filenameProperty;
|
properties["filepath"] = filepathProperty;
|
||||||
|
|
||||||
QJsonObject definition;
|
QJsonObject definition;
|
||||||
definition["type"] = "object";
|
definition["type"] = "object";
|
||||||
definition["properties"] = properties;
|
definition["properties"] = properties;
|
||||||
|
|
||||||
QJsonArray required;
|
QJsonArray required;
|
||||||
required.append("filename");
|
required.append("filepath");
|
||||||
definition["required"] = required;
|
definition["required"] = required;
|
||||||
|
|
||||||
switch (format) {
|
switch (format) {
|
||||||
@ -98,13 +98,12 @@ LLMCore::ToolPermissions ReadProjectFileByNameTool::requiredPermissions() const
|
|||||||
QFuture<QString> ReadProjectFileByNameTool::executeAsync(const QJsonObject &input)
|
QFuture<QString> ReadProjectFileByNameTool::executeAsync(const QJsonObject &input)
|
||||||
{
|
{
|
||||||
return QtConcurrent::run([this, input]() -> QString {
|
return QtConcurrent::run([this, input]() -> QString {
|
||||||
QString filePath = input["filename"].toString();
|
QString filePath = input["filepath"].toString();
|
||||||
if (filePath.isEmpty()) {
|
if (filePath.isEmpty()) {
|
||||||
QString error = "Error: filename parameter is required";
|
QString error = "Error: filepath parameter is required";
|
||||||
throw std::invalid_argument(error.toStdString());
|
throw std::invalid_argument(error.toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate that file exists
|
|
||||||
QFileInfo fileInfo(filePath);
|
QFileInfo fileInfo(filePath);
|
||||||
if (!fileInfo.exists() || !fileInfo.isFile()) {
|
if (!fileInfo.exists() || !fileInfo.isFile()) {
|
||||||
QString error = QString("Error: File '%1' does not exist").arg(filePath);
|
QString error = QString("Error: File '%1' does not exist").arg(filePath);
|
||||||
@ -113,13 +112,11 @@ QFuture<QString> ReadProjectFileByNameTool::executeAsync(const QJsonObject &inpu
|
|||||||
|
|
||||||
QString canonicalPath = fileInfo.canonicalFilePath();
|
QString canonicalPath = fileInfo.canonicalFilePath();
|
||||||
|
|
||||||
// Check if file is part of the project
|
|
||||||
if (!isFileInProject(canonicalPath)) {
|
if (!isFileInProject(canonicalPath)) {
|
||||||
QString error = QString("Error: File '%1' is not part of the project").arg(filePath);
|
QString error = QString("Error: File '%1' is not part of the project").arg(filePath);
|
||||||
throw std::runtime_error(error.toStdString());
|
throw std::runtime_error(error.toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if file is ignored
|
|
||||||
auto project = ProjectExplorer::ProjectManager::projectForFile(
|
auto project = ProjectExplorer::ProjectManager::projectForFile(
|
||||||
Utils::FilePath::fromString(canonicalPath));
|
Utils::FilePath::fromString(canonicalPath));
|
||||||
if (project && m_ignoreManager->shouldIgnore(canonicalPath, project)) {
|
if (project && m_ignoreManager->shouldIgnore(canonicalPath, project)) {
|
||||||
@ -128,7 +125,6 @@ QFuture<QString> ReadProjectFileByNameTool::executeAsync(const QJsonObject &inpu
|
|||||||
throw std::runtime_error(error.toStdString());
|
throw std::runtime_error(error.toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read file content
|
|
||||||
QString content = readFileContent(canonicalPath);
|
QString content = readFileContent(canonicalPath);
|
||||||
if (content.isNull()) {
|
if (content.isNull()) {
|
||||||
QString error = QString("Error: Could not read file '%1'").arg(canonicalPath);
|
QString error = QString("Error: Could not read file '%1'").arg(canonicalPath);
|
||||||
@ -150,12 +146,16 @@ bool ReadProjectFileByNameTool::isFileInProject(const QString &filePath) const
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
Utils::FilePaths projectFiles = project->files(ProjectExplorer::Project::SourceFiles);
|
Utils::FilePaths projectFiles = project->files(ProjectExplorer::Project::SourceFiles);
|
||||||
|
|
||||||
for (const auto &projectFile : std::as_const(projectFiles)) {
|
for (const auto &projectFile : std::as_const(projectFiles)) {
|
||||||
if (projectFile == targetPath) {
|
if (projectFile == targetPath) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Utils::FilePath projectDir = project->projectDirectory();
|
||||||
|
if (targetPath.isChildOf(projectDir)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
Reference in New Issue
Block a user