fix: Read file by path description

This commit is contained in:
Petr Mironychev
2025-10-20 18:23:18 +02:00
parent 254fac246d
commit b7322be00c
2 changed files with 13 additions and 14 deletions

View File

@ -34,33 +34,32 @@
namespace QodeAssist::Tools { namespace QodeAssist::Tools {
ReadProjectFileByNameTool::ReadProjectFileByNameTool(QObject *parent) ReadProjectFileByPathTool::ReadProjectFileByPathTool(QObject *parent)
: BaseTool(parent) : BaseTool(parent)
, m_ignoreManager(new Context::IgnoreManager(this)) , m_ignoreManager(new Context::IgnoreManager(this))
{} {}
QString ReadProjectFileByNameTool::name() const QString ReadProjectFileByPathTool::name() const
{ {
return "read_project_file_by_name"; return "read_project_file_by_path";
} }
QString ReadProjectFileByNameTool::stringName() const QString ReadProjectFileByPathTool::stringName() const
{ {
return {"Reading project file"}; return {"Reading project file"};
} }
QString ReadProjectFileByNameTool::description() const QString ReadProjectFileByPathTool::description() const
{ {
return "Read the content of a specific file from the current project by providing its " return "Read the content of a specific file from the current project by providing its "
"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: 'filepath' - 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.";
} }
QJsonObject ReadProjectFileByNameTool::getDefinition(LLMCore::ToolSchemaFormat format) const QJsonObject ReadProjectFileByPathTool::getDefinition(LLMCore::ToolSchemaFormat format) const
{ {
QJsonObject properties; QJsonObject properties;
QJsonObject filepathProperty; QJsonObject filepathProperty;
@ -90,12 +89,12 @@ QJsonObject ReadProjectFileByNameTool::getDefinition(LLMCore::ToolSchemaFormat f
return definition; return definition;
} }
LLMCore::ToolPermissions ReadProjectFileByNameTool::requiredPermissions() const LLMCore::ToolPermissions ReadProjectFileByPathTool::requiredPermissions() const
{ {
return LLMCore::ToolPermission::FileSystemRead; return LLMCore::ToolPermission::FileSystemRead;
} }
QFuture<QString> ReadProjectFileByNameTool::executeAsync(const QJsonObject &input) QFuture<QString> ReadProjectFileByPathTool::executeAsync(const QJsonObject &input)
{ {
return QtConcurrent::run([this, input]() -> QString { return QtConcurrent::run([this, input]() -> QString {
QString filePath = input["filepath"].toString(); QString filePath = input["filepath"].toString();
@ -136,7 +135,7 @@ QFuture<QString> ReadProjectFileByNameTool::executeAsync(const QJsonObject &inpu
}); });
} }
bool ReadProjectFileByNameTool::isFileInProject(const QString &filePath) const bool ReadProjectFileByPathTool::isFileInProject(const QString &filePath) const
{ {
QList<ProjectExplorer::Project *> projects = ProjectExplorer::ProjectManager::projects(); QList<ProjectExplorer::Project *> projects = ProjectExplorer::ProjectManager::projects();
Utils::FilePath targetPath = Utils::FilePath::fromString(filePath); Utils::FilePath targetPath = Utils::FilePath::fromString(filePath);
@ -161,7 +160,7 @@ bool ReadProjectFileByNameTool::isFileInProject(const QString &filePath) const
return false; return false;
} }
QString ReadProjectFileByNameTool::readFileContent(const QString &filePath) const QString ReadProjectFileByPathTool::readFileContent(const QString &filePath) const
{ {
QFile file(filePath); QFile file(filePath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {

View File

@ -24,11 +24,11 @@
namespace QodeAssist::Tools { namespace QodeAssist::Tools {
class ReadProjectFileByNameTool : public LLMCore::BaseTool class ReadProjectFileByPathTool : public LLMCore::BaseTool
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit ReadProjectFileByNameTool(QObject *parent = nullptr); explicit ReadProjectFileByPathTool(QObject *parent = nullptr);
QString name() const override; QString name() const override;
QString stringName() const override; QString stringName() const override;