mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2026-02-20 05:53:13 -05:00
refactor: Remove current visible files in ide
This commit is contained in:
@ -142,7 +142,6 @@ add_qtc_plugin(QodeAssist
|
|||||||
|
|
||||||
QuickRefactorHandler.hpp QuickRefactorHandler.cpp
|
QuickRefactorHandler.hpp QuickRefactorHandler.cpp
|
||||||
tools/ToolsFactory.hpp tools/ToolsFactory.cpp
|
tools/ToolsFactory.hpp tools/ToolsFactory.cpp
|
||||||
tools/ReadVisibleFilesTool.hpp tools/ReadVisibleFilesTool.cpp
|
|
||||||
tools/ToolHandler.hpp tools/ToolHandler.cpp
|
tools/ToolHandler.hpp tools/ToolHandler.cpp
|
||||||
tools/ListProjectFilesTool.hpp tools/ListProjectFilesTool.cpp
|
tools/ListProjectFilesTool.hpp tools/ListProjectFilesTool.cpp
|
||||||
tools/ToolsManager.hpp tools/ToolsManager.cpp
|
tools/ToolsManager.hpp tools/ToolsManager.cpp
|
||||||
|
|||||||
@ -1,132 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2025 Petr Mironychev
|
|
||||||
*
|
|
||||||
* This file is part of QodeAssist.
|
|
||||||
*
|
|
||||||
* QodeAssist is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* QodeAssist is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "ReadVisibleFilesTool.hpp"
|
|
||||||
#include "ToolExceptions.hpp"
|
|
||||||
|
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
|
||||||
#include <coreplugin/editormanager/ieditor.h>
|
|
||||||
#include <logger/Logger.hpp>
|
|
||||||
#include <projectexplorer/projectmanager.h>
|
|
||||||
#include <QJsonArray>
|
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QtConcurrent>
|
|
||||||
|
|
||||||
namespace QodeAssist::Tools {
|
|
||||||
|
|
||||||
ReadVisibleFilesTool::ReadVisibleFilesTool(QObject *parent)
|
|
||||||
: BaseTool(parent)
|
|
||||||
, m_ignoreManager(new Context::IgnoreManager(this))
|
|
||||||
{}
|
|
||||||
|
|
||||||
QString ReadVisibleFilesTool::name() const
|
|
||||||
{
|
|
||||||
return "read_visible_files";
|
|
||||||
}
|
|
||||||
|
|
||||||
QString ReadVisibleFilesTool::stringName() const
|
|
||||||
{
|
|
||||||
return {"Reading currently opened and visible files in IDE editors"};
|
|
||||||
}
|
|
||||||
|
|
||||||
QString ReadVisibleFilesTool::description() const
|
|
||||||
{
|
|
||||||
return "Read content from all currently visible editor tabs, including unsaved changes. "
|
|
||||||
"Returns file paths and content. No parameters required.";
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonObject ReadVisibleFilesTool::getDefinition(LLMCore::ToolSchemaFormat format) const
|
|
||||||
{
|
|
||||||
QJsonObject definition;
|
|
||||||
definition["type"] = "object";
|
|
||||||
definition["properties"] = QJsonObject();
|
|
||||||
definition["required"] = QJsonArray();
|
|
||||||
|
|
||||||
switch (format) {
|
|
||||||
case LLMCore::ToolSchemaFormat::OpenAI:
|
|
||||||
return customizeForOpenAI(definition);
|
|
||||||
case LLMCore::ToolSchemaFormat::Claude:
|
|
||||||
return customizeForClaude(definition);
|
|
||||||
case LLMCore::ToolSchemaFormat::Ollama:
|
|
||||||
return customizeForOllama(definition);
|
|
||||||
case LLMCore::ToolSchemaFormat::Google:
|
|
||||||
return customizeForGoogle(definition);
|
|
||||||
}
|
|
||||||
|
|
||||||
return definition;
|
|
||||||
}
|
|
||||||
|
|
||||||
LLMCore::ToolPermissions ReadVisibleFilesTool::requiredPermissions() const
|
|
||||||
{
|
|
||||||
return LLMCore::ToolPermission::FileSystemRead;
|
|
||||||
}
|
|
||||||
|
|
||||||
QFuture<QString> ReadVisibleFilesTool::executeAsync(const QJsonObject &input)
|
|
||||||
{
|
|
||||||
Q_UNUSED(input)
|
|
||||||
|
|
||||||
return QtConcurrent::run([this]() -> QString {
|
|
||||||
auto editors = Core::EditorManager::visibleEditors();
|
|
||||||
|
|
||||||
if (editors.isEmpty()) {
|
|
||||||
QString error = "Error: No visible files in the editor";
|
|
||||||
throw ToolRuntimeError(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList results;
|
|
||||||
|
|
||||||
for (auto editor : editors) {
|
|
||||||
if (!editor || !editor->document()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString filePath = editor->document()->filePath().toFSPathString();
|
|
||||||
|
|
||||||
auto project = ProjectExplorer::ProjectManager::projectForFile(
|
|
||||||
editor->document()->filePath());
|
|
||||||
if (project && m_ignoreManager->shouldIgnore(filePath, project)) {
|
|
||||||
LOG_MESSAGE(
|
|
||||||
QString("Ignoring visible file due to .qodeassistignore: %1").arg(filePath));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray contentBytes = editor->document()->contents();
|
|
||||||
QString fileContent = QString::fromUtf8(contentBytes);
|
|
||||||
|
|
||||||
QString fileResult;
|
|
||||||
if (fileContent.isEmpty()) {
|
|
||||||
fileResult
|
|
||||||
= QString("File: %1\n\nThe file is empty or could not be read").arg(filePath);
|
|
||||||
} else {
|
|
||||||
fileResult = QString("File: %1\n\nContent:\n%2").arg(filePath, fileContent);
|
|
||||||
}
|
|
||||||
|
|
||||||
results.append(fileResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (results.isEmpty()) {
|
|
||||||
QString error = "Error: All visible files are excluded by .qodeassistignore";
|
|
||||||
throw ToolRuntimeError(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
return results.join("\n\n" + QString(80, '=') + "\n\n");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace QodeAssist::Tools
|
|
||||||
@ -1,45 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2025 Petr Mironychev
|
|
||||||
*
|
|
||||||
* This file is part of QodeAssist.
|
|
||||||
*
|
|
||||||
* QodeAssist is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* QodeAssist is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <context/IgnoreManager.hpp>
|
|
||||||
#include <llmcore/BaseTool.hpp>
|
|
||||||
|
|
||||||
namespace QodeAssist::Tools {
|
|
||||||
|
|
||||||
class ReadVisibleFilesTool : public LLMCore::BaseTool
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit ReadVisibleFilesTool(QObject *parent = nullptr);
|
|
||||||
|
|
||||||
QString name() const override;
|
|
||||||
QString stringName() const override;
|
|
||||||
QString description() const override;
|
|
||||||
QJsonObject getDefinition(LLMCore::ToolSchemaFormat format) const override;
|
|
||||||
LLMCore::ToolPermissions requiredPermissions() const override;
|
|
||||||
|
|
||||||
QFuture<QString> executeAsync(const QJsonObject &input = QJsonObject()) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
Context::IgnoreManager *m_ignoreManager;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace QodeAssist::Tools
|
|
||||||
@ -33,7 +33,6 @@
|
|||||||
#include "GetIssuesListTool.hpp"
|
#include "GetIssuesListTool.hpp"
|
||||||
#include "ListProjectFilesTool.hpp"
|
#include "ListProjectFilesTool.hpp"
|
||||||
#include "ProjectSearchTool.hpp"
|
#include "ProjectSearchTool.hpp"
|
||||||
#include "ReadVisibleFilesTool.hpp"
|
|
||||||
#include "TodoTool.hpp"
|
#include "TodoTool.hpp"
|
||||||
|
|
||||||
namespace QodeAssist::Tools {
|
namespace QodeAssist::Tools {
|
||||||
@ -46,7 +45,6 @@ ToolsFactory::ToolsFactory(QObject *parent)
|
|||||||
|
|
||||||
void ToolsFactory::registerTools()
|
void ToolsFactory::registerTools()
|
||||||
{
|
{
|
||||||
registerTool(new ReadVisibleFilesTool(this));
|
|
||||||
registerTool(new ListProjectFilesTool(this));
|
registerTool(new ListProjectFilesTool(this));
|
||||||
registerTool(new GetIssuesListTool(this));
|
registerTool(new GetIssuesListTool(this));
|
||||||
registerTool(new CreateNewFileTool(this));
|
registerTool(new CreateNewFileTool(this));
|
||||||
|
|||||||
Reference in New Issue
Block a user