@@ -50,20 +50,15 @@ kdevcxx_with_ai::kdevcxx_with_ai(QObject * parent, QVariantList const &) : KDeve
5050 * been properly set up with an API key. If the API key is missing, it prompts
5151 * the user to enter the API key by displaying an information dialog.
5252 */
53+
5354void kdevcxx_with_ai::on_first_time ()
5455 {
5556 auto aisettings = aiprocess::load_ai_settings ();
5657 aiprocess::warn (" api_key {}" , aiprocess::obfuscate_text (aisettings.api_key ));
5758 aiprocess::warn (" cxx_rules {}" , aisettings.cxx_rules );
5859 if (aisettings.api_key .empty ())
5960 {
60- info_dialog dialog (
61- " KDevCxx_With_Ai key setup" ,
62- " Please go to KDevelop settings and enter your API key before calling any functions and adjust your rules for "
63- " AI.\n "
64- " You can change them at any time without restarting KDevelop.\n "
65- " Changes to AI settings will take effect on every execution."
66- );
61+ info_dialog dialog ( " KDevCxx_With_Ai Initialization" , kdevcxxai::fist_time_message );
6762 dialog.exec ();
6863 }
6964 }
@@ -72,95 +67,13 @@ using namespace std::string_view_literals;
7267
7368void kdevcxx_with_ai::on_process_with_ai ()
7469 {
75- #if 1
76- auto * view = KTextEditor::Editor::instance ()->application ()->activeMainWindow ()->activeView ();
77- if (!view || !view->selection ()) [[unlikely]]
78- return ;
79-
80- kdevcxxai::process_with_ai (*view, settings);
81- #else
82- {
83- auto aisettings{aiprocess::load_ai_settings()};
84- if(aisettings.api_key.empty())
85- {
86- info_dialog dialog{
87- "KDevCxx_With_Ai key setup",
88- "Please go to KDevelop settings and enter your API key before calling any functions and adjust your language "
89- "rules for AI.\n"
90- "You can change them at any time without restarting KDevelop.\n"
91- "Changes to AI settings will take effect on every execution."
92- };
93- dialog.exec();
94- return;
95- }
96- }
9770
98- using namespace std::chrono_literals;
9971 auto * view = KTextEditor::Editor::instance ()->application ()->activeMainWindow ()->activeView ();
100-
10172 if (!view || !view->selection ()) [[unlikely]]
10273 return ;
10374
104- auto * document = view->document();
105- if(!document) [[unlikely]]
106- {
107- warn("Invalid view->document");
108- return;
109- }
110-
111- info("Processing OpenAI request ...");
112- QProgressDialog progressDialog{"Processing OpenAI Request...", "Cancel", 0, 100};
113- progressDialog.setWindowModality(Qt::WindowModal);
114- progressDialog.show();
115-
116- QString selected_text = view->selectionText();
117-
118- auto async_result = std::async(
119- std::launch::async,
120- [](QString text) -> expected<aiprocess::model_response_text_t, aiprocess::process_with_ai_error>
121- { return aiprocess::process_with_ai(text.toStdString()); },
122- selected_text
123- );
124-
125- debug("async to OpenAI executed ...");
126- std::this_thread::yield();
127-
128- while(async_result.wait_for(50ms) != std::future_status::ready)
129- QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
130-
131- auto result = async_result.get();
132- debug("async to OpenAI done ...");
133-
134- if(!result)
135- {
136- aiprocess::li::error("Got error from async {}\n", result.error());
137- KMessageBox::error(
138- view,
139- QString::fromStdString(stralgo::stl::merge(
140- "Error processing AI request "sv,
141- simple_enum::enum_name(result.error()),
142- "\ncheck detailed log at ~/.config/kdevcxx_with_ai/"sv,
143- settings.log_path
144- )),
145- "Error during processing AI request"
146- );
147- return;
148- }
149-
150- std::string cur_work_dir{};
151- if(auto path = kdevcxxai::get_view_file_path(*view); path.has_value())
152- cur_work_dir = std::move(path.value());
153-
154- auto const & response = *result;
155- auto new_text = aiprocess::process_openai_json_response(response, std::move(cur_work_dir));
156- debug("Proocessed response Command Text: {}\nCode Text: {}\n", response.command, response.recived_text);
157-
158- if(new_text.empty()) [[unlikely]]
159- return;
75+ kdevcxxai::process_with_ai (*view, settings);
16076
161- document->replaceText(view->selectionRange(), QString::fromStdString(new_text));
162- debug("document->replaceText called ...");
163- #endif
16477 }
16578
16679void kdevcxx_with_ai::createActionsForMainWindow (Sublime::MainWindow *, QString &, KActionCollection & actions)
@@ -208,4 +121,4 @@ void kdevcxx_with_ai::unload() {}
208121kdevcxx_with_ai::~kdevcxx_with_ai () {}
209122
210123#include " kdevcxx_with_ai.moc"
211- #include " moc_kdevcxx_with_ai.cpp"
124+ // #include "moc_kdevcxx_with_ai.cpp"
0 commit comments