Skip to content

Modernize the codebase #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ai_processing/include/ai_processing.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ enum struct process_with_ai_error
consteval auto adl_enum_bounds(process_with_ai_error)
{
using enum process_with_ai_error;
return simple_enum::adl_info{other_error, no_valid_command};
return simple_enum::adl_info{.first = other_error, .last = no_valid_command};
}

struct model_response_text_t
Expand Down
12 changes: 6 additions & 6 deletions ai_processing/include/aiprocess/app_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace aiprocess
{

enum struct backend_type_e
enum struct backend_type_e : std::uint8_t
{
kate,
kdevelop
Expand All @@ -22,15 +22,15 @@ enum struct backend_type_e
consteval auto adl_enum_bounds(backend_type_e)
{
using enum backend_type_e;
return simple_enum::adl_info{kate, kdevelop};
return simple_enum::adl_info{.first = kate, .last = kdevelop};
}

inline constexpr string_view kdevcxx_with_ai_app_settings_file_name{"kdevcxx_with_ai_app_settings.json"};
inline constexpr string_view kate_with_ai_app_settings_file_name{"kate_with_ai_app_settings.json"};

inline constexpr string_view kdevcxx_with_ai_ai_settings_file_name{"kdevcxx_with_ai_ai_settings.json"};

enum struct app_settings_version_e
enum struct app_settings_version_e : std::uint8_t
{
v1 = 1,

Expand All @@ -40,7 +40,7 @@ enum struct app_settings_version_e
consteval auto adl_enum_bounds(app_settings_version_e)
{
using enum app_settings_version_e;
return simple_enum::adl_info{v1, latest};
return simple_enum::adl_info{.first = v1, .last = latest};
}

struct app_settings_t
Expand Down Expand Up @@ -80,7 +80,7 @@ auto store_app_settings(app_settings_t const & cfg) noexcept -> bool;
extern template auto store_app_settings<backend_type_e::kdevelop>(app_settings_t const & cfg) noexcept -> bool;
extern template auto store_app_settings<backend_type_e::kate>(app_settings_t const & cfg) noexcept -> bool;

enum struct ai_settings_version_e
enum struct ai_settings_version_e : std::uint8_t
{
v1 = 1,
v2,
Expand All @@ -90,7 +90,7 @@ enum struct ai_settings_version_e
consteval auto adl_enum_bounds(ai_settings_version_e)
{
using enum ai_settings_version_e;
return simple_enum::adl_info{v1, latest};
return simple_enum::adl_info{.first = v1, .last = latest};
}

//
Expand Down
2 changes: 1 addition & 1 deletion ai_processing/include/aiprocess/change_current_dir.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ enum struct change_directory_error
consteval auto adl_enum_bounds(change_directory_error)
{
using enum change_directory_error;
return simple_enum::adl_info{unhandled_exception, filesystem_error};
return simple_enum::adl_info{.first = unhandled_exception, .last = filesystem_error};
}

[[nodiscard]]
Expand Down
2 changes: 1 addition & 1 deletion ai_processing/include/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct url_components

// auto parse(std::string_view url) -> url_components;

enum struct send_text_to_gpt_error
enum struct send_text_to_gpt_error : std::uint8_t
{
network_error,
other_exception,
Expand Down
4 changes: 2 additions & 2 deletions ai_processing/source/ai_processing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ try
{
using enum process_with_ai_error;

aiprocess::ai_settings_t aisettings{aiprocess::load_ai_settings()};
const aiprocess::ai_settings_t aisettings{aiprocess::load_ai_settings()};
info("checking api key ..");
if(!is_valid_openai_bearer_key(aisettings.api_key)) [[unlikely]]
return unexpected_error(invalid_api_key, "invalid key bailing out");
Expand All @@ -149,7 +149,7 @@ try
if(command_text.empty()) [[unlikely]]
return unexpected_error(no_valid_command, "command_text is empty nothing to do ..");

std::string code_text = user_data.substr(end_pos + command_end_delim.length());
const std::string code_text = user_data.substr(end_pos + command_end_delim.length());

#ifndef ENABLE_CHAT_COMPLETIONS
ai_command_json command{.prompt = fmt::format("[{},{}] {}", ai_rules, command_text, code_text)};
Expand Down
6 changes: 3 additions & 3 deletions ai_processing/source/log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static auto create_log_sink(std::string const & path, std::string const & filena
return std::make_shared<spdlog::sinks::basic_file_sink_mt>(stralgo::stl::merge(path, '/', filename), false);
}

static std::shared_ptr<spdlog::logger> create_logger(std::string name, spdlog::sinks_init_list sinks)
static std::shared_ptr<spdlog::logger> create_logger(std::string const & name, spdlog::sinks_init_list sinks)
{
auto logger = std::make_shared<spdlog::logger>(name, sinks.begin(), sinks.end());
logger->flush_on(spdlog::level::err);
Expand All @@ -43,8 +43,8 @@ static std::shared_ptr<spdlog::logger> create_logger(std::string name, spdlog::s

void setup_loggers(app_settings_t const & cfg)
{
std::string app_path{get_config_path()};
std::string log_path{stralgo::stl::merge(app_path, '/', cfg.log_path)};
const std::string app_path{get_config_path()};
const std::string log_path{stralgo::stl::merge(app_path, '/', cfg.log_path)};

console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
console_sink->set_level(cfg.console_log_level);
Expand Down
14 changes: 7 additions & 7 deletions src/kate_with_ai/kate_with_ai.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,36 @@ using aiprocess::warn;

K_PLUGIN_FACTORY_WITH_JSON(kate_with_aiFactory, "kate_with_ai.json", registerPlugin<kate_with_ai>();)

kate_with_ai::kate_with_ai(QObject * parent, QList<QVariant> const &) : KTextEditor::Plugin(parent)
kate_with_ai::kate_with_ai(QObject * parent, QList<QVariant> const &) : KTextEditor::Plugin{parent}
{
log(aiprocess::level::info, "Starting plugin Kate_With_Ai");
settings = aiprocess::load_app_settings<aiprocess::backend_type_e::kate>();
aiprocess::setup_loggers(settings);
info("Settings loaded");
}

kate_with_ai::~kate_with_ai() {}
kate_with_ai::~kate_with_ai() = default;

int kate_with_ai::configPages() const { return 1; }

KTextEditor::ConfigPage * kate_with_ai::configPage(int number, QWidget * parent)
{
if(number == 0)
return new kate_with_ai_config_page(parent);
return new kate_with_ai_config_page{parent};
return nullptr; // No other pages to return
}

QObject * kate_with_ai::createView(KTextEditor::MainWindow * main_window)
{
auto * view = new kate_with_ai_view(this, main_window);
auto * view = new kate_with_ai_view{this, main_window};
return view;
}

kate_with_ai_view::kate_with_ai_view(kate_with_ai * plugin, KTextEditor::MainWindow * main_window) :
plugin_{plugin},
main_window_(main_window)
main_window_{main_window}
{
openai_process_action = new QAction(tr("Process with OpenAI"), this);
openai_process_action = new QAction{tr("Process with OpenAI"), this};
connect(openai_process_action, &QAction::triggered, this, &kate_with_ai_view::on_process_with_ai);

// Connect to the signal that notifies about the current view change
Expand All @@ -63,7 +63,7 @@ kate_with_ai_view::kate_with_ai_view(kate_with_ai * plugin, KTextEditor::MainWin

void kate_with_ai_view::on_view_changed(KTextEditor::View * view) { init_view(view); }

void kate_with_ai_view::init_view(KTextEditor::View * view)
void kate_with_ai_view::init_view(KTextEditor::View * view) const
{
if(!view) [[unlikely]]
return;
Expand Down
11 changes: 6 additions & 5 deletions src/kate_with_ai/kate_with_ai.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ class kate_with_ai_view;
class kate_with_ai : public KTextEditor::Plugin
{
Q_OBJECT
Q_DISABLE_COPY_MOVE(kate_with_ai)
friend class kate_with_ai_view;

aiprocess::app_settings_t settings;

public:
explicit kate_with_ai(QObject * parent, QList<QVariant> const & = QList<QVariant>());
explicit kate_with_ai(QObject * parent, QList<QVariant> const & = QList<QVariant>{});
~kate_with_ai() override;

QObject * createView(KTextEditor::MainWindow * mainWindow) override;
[[nodiscard]] auto createView(KTextEditor::MainWindow * main_window) -> QObject * override;

int configPages() const override;
KTextEditor::ConfigPage * configPage(int number, QWidget * parent) override;
[[nodiscard]] auto configPages() const -> int override;
[[nodiscard]] auto configPage(int number, QWidget * parent) -> KTextEditor::ConfigPage* override;
};

class kate_with_ai_view : public QWidget
Expand All @@ -45,7 +46,7 @@ private Q_SLOTS:
void on_context_menu_about_to_show(KTextEditor::View * view, QMenu * menu);

private:
void init_view(KTextEditor::View * view);
void init_view(KTextEditor::View * view) const;
void on_process_with_ai();

kate_with_ai * plugin_;
Expand Down
12 changes: 7 additions & 5 deletions src/kate_with_ai/kate_with_ai_config_page.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,22 @@
#include <aiprocess/log.h>
#endif

kate_with_ai_config_page::kate_with_ai_config_page(QWidget * parent) : KTextEditor::ConfigPage(parent)
kate_with_ai_config_page::kate_with_ai_config_page(QWidget * parent) : KTextEditor::ConfigPage{parent}
{
kdevcxxai::config_page::construct<aiprocess::backend_type_e::kate>(
*this, ui, std::bind(&kate_with_ai_config_page::emit_changed, this)
);
}

void kate_with_ai_config_page::emit_changed() { Q_EMIT changed(); }
kate_with_ai_config_page::~kate_with_ai_config_page() = default;

QString kate_with_ai_config_page::name() const { return i18n("OpenAI Configuration"); }
void kate_with_ai_config_page::emit_changed() { emit changed(); }

QString kate_with_ai_config_page::fullName() const { return i18n("Configure Open AI Settings"); }
auto kate_with_ai_config_page::name() const -> QString { return i18n("OpenAI Configuration"); }

QIcon kate_with_ai_config_page::icon() const { return QIcon::fromTheme(QLatin1String("preferences-other")); }
auto kate_with_ai_config_page::fullName() const -> QString { return i18n("Configure Open AI Settings"); }

auto kate_with_ai_config_page::icon() const -> QIcon { return QIcon::fromTheme("preferences-other"); }

void kate_with_ai_config_page::apply() { kdevcxxai::config_page::apply<aiprocess::backend_type_e::kate>(ui); }

Expand Down
8 changes: 5 additions & 3 deletions src/kate_with_ai/kate_with_ai_config_page.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
class kate_with_ai_config_page : public KTextEditor::ConfigPage
{
Q_OBJECT
Q_DISABLE_COPY_MOVE(kate_with_ai_config_page)

public:
explicit kate_with_ai_config_page(QWidget * parent = nullptr);
~kate_with_ai_config_page() override;

QString name() const override;
QString fullName() const override;
QIcon icon() const override;
[[nodiscard]] auto name() const -> QString override;
[[nodiscard]] auto fullName() const -> QString override;
[[nodiscard]] auto icon() const -> QIcon override;

void apply() override;
void reset() override;
Expand Down
11 changes: 5 additions & 6 deletions src/kdevcxx_with_ai/kdevcxx_with_ai.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ using aiprocess::warn;

K_PLUGIN_FACTORY_WITH_JSON(cxx_with_gptFactory, "kdevcxx_with_ai.json", registerPlugin<kdevcxx_with_ai>();)

kdevcxx_with_ai::kdevcxx_with_ai(QObject * parent, QVariantList const &) :
KDevelop::IPlugin(QStringLiteral("kdevcxx_with_ai"), parent, KPluginMetaData())
kdevcxx_with_ai::kdevcxx_with_ai(QObject * parent, QVariantList const &) : KDevelop::IPlugin{"kdevcxx_with_ai", parent}
{
log(aiprocess::level::info, "Starting plugin KDevCxx_With_Ai");
settings = aiprocess::load_app_settings<aiprocess::backend_type_e::kdevelop>();
Expand Down Expand Up @@ -76,7 +75,7 @@ void kdevcxx_with_ai::on_process_with_ai()

void kdevcxx_with_ai::createActionsForMainWindow(Sublime::MainWindow *, QString &, KActionCollection & actions)
{
QAction * process_with_ai_action = new QAction(QIcon(QStringLiteral(":/icons/my_icon.png")), tr("Process with OpenAI"), this);
auto * process_with_ai_action = new QAction{QIcon(":/icons/my_icon.png"), tr("Process with OpenAI"), this};
process_with_ai_action->setToolTip(tr("Do something interesting with AI"));

process_with_ai_action->setShortcut(settings.activation_keys);
Expand All @@ -95,7 +94,7 @@ auto kdevcxx_with_ai::contextMenuExtension(KDevelop::Context * context, QWidget
{
info("Context menu registered for AI");
// This is just an example; customize it based on your plugin's functionality
QAction * process_with_ai_action = new QAction(QIcon::fromTheme(QStringLiteral("system-run")), tr("Process with OpenAI"), parent);
auto * process_with_ai_action = new QAction{QIcon::fromTheme("system-run"), tr("Process with OpenAI"), parent};
connect(process_with_ai_action, &QAction::triggered, this, &kdevcxx_with_ai::on_process_with_ai);

// Add your action to the extension
Expand All @@ -110,13 +109,13 @@ int kdevcxx_with_ai::configPages() const { return 1; }
auto kdevcxx_with_ai::configPage(int number, QWidget * parent) -> KDevelop::ConfigPage *
{
if(number == 0)
return new kdevcxx_with_ai_config_page(this, parent);
return new kdevcxx_with_ai_config_page{this, parent};
return nullptr; // No other pages to return
}

void kdevcxx_with_ai::unload() {}

kdevcxx_with_ai::~kdevcxx_with_ai() {}
kdevcxx_with_ai::~kdevcxx_with_ai() = default;

#include "kdevcxx_with_ai.moc"
// #include "moc_kdevcxx_with_ai.cpp"
9 changes: 5 additions & 4 deletions src/kdevcxx_with_ai/kdevcxx_with_ai.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,22 @@
class kdevcxx_with_ai : public KDevelop::IPlugin
{
Q_OBJECT
Q_DISABLE_COPY_MOVE(kdevcxx_with_ai)
aiprocess::app_settings_t settings;

public:
kdevcxx_with_ai(QObject * parent, QVariantList const & args);
~kdevcxx_with_ai() override;

auto contextMenuExtension(KDevelop::Context * context, QWidget * parent) -> KDevelop::ContextMenuExtension override;
[[nodiscard]] auto contextMenuExtension(KDevelop::Context * context, QWidget * parent) -> KDevelop::ContextMenuExtension override;

auto createActionsForMainWindow(Sublime::MainWindow * window, QString & xmlFile, KActionCollection & actions)
-> void override;

void unload() override;
auto unload() -> void override;

KDevelop::ConfigPage * configPage(int number, QWidget * parent) override;
int configPages() const override;
[[nodiscard]] auto configPage(int number, QWidget * parent) ->KDevelop::ConfigPage* override;
[[nodiscard]] auto configPages() const -> int override;

private Q_SLOTS:

Expand Down
12 changes: 7 additions & 5 deletions src/kdevcxx_with_ai/kdevcxx_with_ai_config_page.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,22 @@
#endif

kdevcxx_with_ai_config_page::kdevcxx_with_ai_config_page(KDevelop::IPlugin * plugin, QWidget * parent) :
KDevelop::ConfigPage(plugin, nullptr, parent)
KDevelop::ConfigPage{plugin, nullptr, parent}
{
kdevcxxai::config_page::construct<aiprocess::backend_type_e::kdevelop>(
*this, ui, std::bind(&kdevcxx_with_ai_config_page::emit_changed, this)
);
}

void kdevcxx_with_ai_config_page::emit_changed() { Q_EMIT changed(); }
kdevcxx_with_ai_config_page::~kdevcxx_with_ai_config_page() = default;

QString kdevcxx_with_ai_config_page::name() const { return i18n("OpenAI Configuration"); }
void kdevcxx_with_ai_config_page::emit_changed() { emit changed(); }

QString kdevcxx_with_ai_config_page::fullName() const { return i18n("Configure Open AI Settings"); }
auto kdevcxx_with_ai_config_page::name() const -> QString { return i18n("OpenAI Configuration"); }

QIcon kdevcxx_with_ai_config_page::icon() const { return QIcon::fromTheme(QLatin1String("preferences-other")); }
auto kdevcxx_with_ai_config_page::fullName() const -> QString { return i18n("Configure Open AI Settings"); }

auto kdevcxx_with_ai_config_page::icon() const -> QIcon { return QIcon::fromTheme("preferences-other"); }

void kdevcxx_with_ai_config_page::apply() { kdevcxxai::config_page::apply<aiprocess::backend_type_e::kdevelop>(ui); }

Expand Down
7 changes: 4 additions & 3 deletions src/kdevcxx_with_ai/kdevcxx_with_ai_config_page.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ class kdevcxx_with_ai_config_page : public KDevelop::ConfigPage

public:
explicit kdevcxx_with_ai_config_page(KDevelop::IPlugin * plugin, QWidget * parent = nullptr);
~kdevcxx_with_ai_config_page() override;

QString name() const override;
QString fullName() const override;
QIcon icon() const override;
auto name() const -> QString override;
auto fullName() const -> QString override;
auto icon() const -> QIcon override;

void apply() override;
void reset() override;
Expand Down
2 changes: 1 addition & 1 deletion src/plugin_common/include/plugin_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ inline constexpr auto fist_time_message
"negating the necessity for a KDevelop restart.\n"
"Alterations to AI settings will be effective upon the next invocation.");

enum class get_view_file_path_error
enum class get_view_file_path_error : std::uint8_t
{
no_document,
unhandled_exception
Expand Down
Loading