From 1d64f94446ecc6e58037d774920a650082e0159b Mon Sep 17 00:00:00 2001 From: Petr Mironychev <9195189+Palm1r@users.noreply.github.com> Date: Thu, 19 Feb 2026 18:31:58 +0100 Subject: [PATCH] refactor: Remove current visible files in ide --- CMakeLists.txt | 1 - tools/ReadVisibleFilesTool.cpp | 132 --------------------------------- tools/ReadVisibleFilesTool.hpp | 45 ----------- tools/ToolsFactory.cpp | 2 - 4 files changed, 180 deletions(-) delete mode 100644 tools/ReadVisibleFilesTool.cpp delete mode 100644 tools/ReadVisibleFilesTool.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 48faf02..a334cc3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -142,7 +142,6 @@ add_qtc_plugin(QodeAssist QuickRefactorHandler.hpp QuickRefactorHandler.cpp tools/ToolsFactory.hpp tools/ToolsFactory.cpp - tools/ReadVisibleFilesTool.hpp tools/ReadVisibleFilesTool.cpp tools/ToolHandler.hpp tools/ToolHandler.cpp tools/ListProjectFilesTool.hpp tools/ListProjectFilesTool.cpp tools/ToolsManager.hpp tools/ToolsManager.cpp diff --git a/tools/ReadVisibleFilesTool.cpp b/tools/ReadVisibleFilesTool.cpp deleted file mode 100644 index 8f42986..0000000 --- a/tools/ReadVisibleFilesTool.cpp +++ /dev/null @@ -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 . - */ - -#include "ReadVisibleFilesTool.hpp" -#include "ToolExceptions.hpp" - -#include -#include -#include -#include -#include -#include -#include - -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 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 diff --git a/tools/ReadVisibleFilesTool.hpp b/tools/ReadVisibleFilesTool.hpp deleted file mode 100644 index edd2354..0000000 --- a/tools/ReadVisibleFilesTool.hpp +++ /dev/null @@ -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 . - */ - -#pragma once - -#include -#include - -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 executeAsync(const QJsonObject &input = QJsonObject()) override; - -private: - Context::IgnoreManager *m_ignoreManager; -}; - -} // namespace QodeAssist::Tools diff --git a/tools/ToolsFactory.cpp b/tools/ToolsFactory.cpp index 2d4bfe7..5fe2e19 100644 --- a/tools/ToolsFactory.cpp +++ b/tools/ToolsFactory.cpp @@ -33,7 +33,6 @@ #include "GetIssuesListTool.hpp" #include "ListProjectFilesTool.hpp" #include "ProjectSearchTool.hpp" -#include "ReadVisibleFilesTool.hpp" #include "TodoTool.hpp" namespace QodeAssist::Tools { @@ -46,7 +45,6 @@ ToolsFactory::ToolsFactory(QObject *parent) void ToolsFactory::registerTools() { - registerTool(new ReadVisibleFilesTool(this)); registerTool(new ListProjectFilesTool(this)); registerTool(new GetIssuesListTool(this)); registerTool(new CreateNewFileTool(this));