mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-11-13 05:22:49 -05:00
feat: Add build tool
This commit is contained in:
@ -126,6 +126,7 @@ add_qtc_plugin(QodeAssist
|
|||||||
tools/FindSymbolTool.hpp tools/FindSymbolTool.cpp
|
tools/FindSymbolTool.hpp tools/FindSymbolTool.cpp
|
||||||
tools/FindFileTool.hpp tools/FindFileTool.cpp
|
tools/FindFileTool.hpp tools/FindFileTool.cpp
|
||||||
tools/CreateNewFileTool.hpp tools/CreateNewFileTool.cpp
|
tools/CreateNewFileTool.hpp tools/CreateNewFileTool.cpp
|
||||||
|
tools/BuildProjectTool.hpp tools/BuildProjectTool.cpp
|
||||||
providers/ClaudeMessage.hpp providers/ClaudeMessage.cpp
|
providers/ClaudeMessage.hpp providers/ClaudeMessage.cpp
|
||||||
providers/OpenAIMessage.hpp providers/OpenAIMessage.cpp
|
providers/OpenAIMessage.hpp providers/OpenAIMessage.cpp
|
||||||
providers/OllamaMessage.hpp providers/OllamaMessage.cpp
|
providers/OllamaMessage.hpp providers/OllamaMessage.cpp
|
||||||
|
|||||||
@ -164,16 +164,6 @@ ChatRootView {
|
|||||||
toolContent: model.content
|
toolContent: model.content
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Component {
|
|
||||||
id: fileEditSuggestionComponent
|
|
||||||
|
|
||||||
FileEditChangesItem {
|
|
||||||
id: fileEditItem
|
|
||||||
|
|
||||||
width: chatListView.width - 10
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ScrollView {
|
ScrollView {
|
||||||
|
|||||||
128
tools/BuildProjectTool.cpp
Normal file
128
tools/BuildProjectTool.cpp
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
/*
|
||||||
|
* 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 "BuildProjectTool.hpp"
|
||||||
|
|
||||||
|
#include <logger/Logger.hpp>
|
||||||
|
#include <projectexplorer/buildmanager.h>
|
||||||
|
#include <projectexplorer/project.h>
|
||||||
|
#include <projectexplorer/projectmanager.h>
|
||||||
|
#include <projectexplorer/target.h>
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QMetaObject>
|
||||||
|
|
||||||
|
namespace QodeAssist::Tools {
|
||||||
|
|
||||||
|
BuildProjectTool::BuildProjectTool(QObject *parent)
|
||||||
|
: BaseTool(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QString BuildProjectTool::name() const
|
||||||
|
{
|
||||||
|
return "build_project";
|
||||||
|
}
|
||||||
|
|
||||||
|
QString BuildProjectTool::stringName() const
|
||||||
|
{
|
||||||
|
return "Building project";
|
||||||
|
}
|
||||||
|
|
||||||
|
QString BuildProjectTool::description() const
|
||||||
|
{
|
||||||
|
return "Build the current project in Qt Creator. "
|
||||||
|
"Returns build status and any compilation errors/warnings. "
|
||||||
|
"Optional 'rebuild' parameter: set to true to force a clean rebuild (default: false).";
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject BuildProjectTool::getDefinition(LLMCore::ToolSchemaFormat format) const
|
||||||
|
{
|
||||||
|
QJsonObject definition;
|
||||||
|
definition["type"] = "object";
|
||||||
|
|
||||||
|
QJsonObject properties;
|
||||||
|
properties["rebuild"] = QJsonObject{
|
||||||
|
{"type", "boolean"},
|
||||||
|
{"description", "Force a clean rebuild instead of incremental build (default: false)"}};
|
||||||
|
|
||||||
|
definition["properties"] = properties;
|
||||||
|
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 BuildProjectTool::requiredPermissions() const
|
||||||
|
{
|
||||||
|
return LLMCore::ToolPermission::None;
|
||||||
|
}
|
||||||
|
|
||||||
|
QFuture<QString> BuildProjectTool::executeAsync(const QJsonObject &input)
|
||||||
|
{
|
||||||
|
auto *project = ProjectExplorer::ProjectManager::startupProject();
|
||||||
|
if (!project) {
|
||||||
|
LOG_MESSAGE("BuildProjectTool: No active project found");
|
||||||
|
return QtFuture::makeReadyFuture(
|
||||||
|
QString("Error: No active project found. Please open a project in Qt Creator."));
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_MESSAGE(QString("BuildProjectTool: Active project is '%1'").arg(project->displayName()));
|
||||||
|
|
||||||
|
if (ProjectExplorer::BuildManager::isBuilding(project)) {
|
||||||
|
LOG_MESSAGE("BuildProjectTool: Build is already in progress");
|
||||||
|
return QtFuture::makeReadyFuture(
|
||||||
|
QString("Error: Build is already in progress. Please wait for it to complete."));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool rebuild = input.value("rebuild").toBool(false);
|
||||||
|
|
||||||
|
LOG_MESSAGE(QString("BuildProjectTool: Starting %1").arg(rebuild ? "rebuild" : "build"));
|
||||||
|
|
||||||
|
QMetaObject::invokeMethod(
|
||||||
|
qApp,
|
||||||
|
[project, rebuild]() {
|
||||||
|
if (rebuild) {
|
||||||
|
ProjectExplorer::BuildManager::rebuildProjectWithDependencies(
|
||||||
|
project, ProjectExplorer::ConfigSelection::Active);
|
||||||
|
} else {
|
||||||
|
ProjectExplorer::BuildManager::buildProjectWithDependencies(
|
||||||
|
project, ProjectExplorer::ConfigSelection::Active);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Qt::QueuedConnection);
|
||||||
|
|
||||||
|
return QtFuture::makeReadyFuture(
|
||||||
|
QString("Build %1 started for project '%2'. Check the Compile Output pane for progress.")
|
||||||
|
.arg(rebuild ? "rebuild" : "build")
|
||||||
|
.arg(project->displayName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace QodeAssist::Tools
|
||||||
42
tools/BuildProjectTool.hpp
Normal file
42
tools/BuildProjectTool.hpp
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* 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 <llmcore/BaseTool.hpp>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
namespace QodeAssist::Tools {
|
||||||
|
|
||||||
|
class BuildProjectTool : public LLMCore::BaseTool
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit BuildProjectTool(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;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace QodeAssist::Tools
|
||||||
@ -24,6 +24,7 @@
|
|||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
#include "BuildProjectTool.hpp"
|
||||||
#include "CreateNewFileTool.hpp"
|
#include "CreateNewFileTool.hpp"
|
||||||
#include "FindFileTool.hpp"
|
#include "FindFileTool.hpp"
|
||||||
#include "FindSymbolTool.hpp"
|
#include "FindSymbolTool.hpp"
|
||||||
@ -51,6 +52,7 @@ void ToolsFactory::registerTools()
|
|||||||
registerTool(new FindSymbolTool(this));
|
registerTool(new FindSymbolTool(this));
|
||||||
registerTool(new FindFileTool(this));
|
registerTool(new FindFileTool(this));
|
||||||
registerTool(new CreateNewFileTool(this));
|
registerTool(new CreateNewFileTool(this));
|
||||||
|
registerTool(new BuildProjectTool(this));
|
||||||
|
|
||||||
LOG_MESSAGE(QString("Registered %1 tools").arg(m_tools.size()));
|
LOG_MESSAGE(QString("Registered %1 tools").arg(m_tools.size()));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user