Skip to content

Commit 54f4687

Browse files
committed
move kdev plugin into subdir
1 parent 1490064 commit 54f4687

17 files changed

+89
-258
lines changed

src/CMakeLists.txt

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,3 @@
11

22
add_subdirectory(plugin_common)
3-
4-
set(CXX_WITH_GPT_UI plugin_settings.ui)
5-
qt5_wrap_ui(CXX_WITH_GPT_UI_HEADERS ${CXX_WITH_GPT_UI})
6-
7-
set(kdevcxx_with_ai_SRCS
8-
kdevcxx_with_ai.cc
9-
plugin_settings.cc
10-
markdown_view.cc
11-
kdevcxx_with_ai_config_page.cc
12-
${CXX_WITH_GPT_UI_HEADERS}
13-
)
14-
15-
kdevplatform_add_plugin(kdevcxx_with_ai
16-
SOURCES ${kdevcxx_with_ai_SRCS}
17-
)
18-
19-
target_link_libraries(kdevcxx_with_ai
20-
kdevcxx_with_ai::plugin_commn
21-
KDev::Interfaces
22-
Qt5::WebEngineWidgets
23-
${BASIC_LINK_FLAGS}
24-
)
25-
target_compile_options( kdevcxx_with_ai PRIVATE "-fexceptions")
26-
set_target_properties(kdevcxx_with_ai PROPERTIES OUTPUT_NAME "kdevcxx_with_ai")
27-
28-
install(TARGETS kdevcxx_with_ai DESTINATION ${PLUGIN_INSTALL_DIR})
29-
install(FILES kdevcxx_with_ai.json DESTINATION ${KDE_INSTALL_KSERVICES5DIR})
30-
message(STATUS "PLUGIN_INSTALL_DIR ${PLUGIN_INSTALL_DIR}")
31-
message(STATUS "KDE_INSTALL_KSERVICES5DIR ${KDE_INSTALL_KSERVICES5DIR}")
32-
33-
add_executable( markdown_view EXCLUDE_FROM_ALL)
34-
target_sources(markdown_view PRIVATE
35-
markdown_view.cc
36-
markdown_view_test.cc
37-
)
38-
target_link_libraries(markdown_view Qt5::Widgets Qt5::WebEngineWidgets)
39-
3+
add_subdirectory(kdevcxx_with_ai)

src/document_read_only.h

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/kdevcxx_with_ai/CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
set(CMAKE_AUTOMOC ON)
2+
# set(CXX_WITH_GPT_UI plugin_settings.ui)
3+
# qt5_wrap_ui(CXX_WITH_GPT_UI_HEADERS ${CXX_WITH_GPT_UI})
4+
5+
set(kdevcxx_with_ai_SRCS
6+
kdevcxx_with_ai.cc
7+
kdevcxx_with_ai_config_page.cc
8+
${CXX_WITH_GPT_UI_HEADERS}
9+
)
10+
11+
kdevplatform_add_plugin(kdevcxx_with_ai
12+
SOURCES ${kdevcxx_with_ai_SRCS}
13+
)
14+
15+
target_link_libraries(kdevcxx_with_ai
16+
kdevcxx_with_ai::plugin_commn
17+
KDev::Interfaces
18+
${BASIC_LINK_FLAGS}
19+
)
20+
target_compile_options( kdevcxx_with_ai PRIVATE "-fexceptions")
21+
set_target_properties(kdevcxx_with_ai PROPERTIES OUTPUT_NAME "kdevcxx_with_ai")
22+
23+
install(TARGETS kdevcxx_with_ai DESTINATION ${PLUGIN_INSTALL_DIR})
24+
install(FILES kdevcxx_with_ai.json DESTINATION ${KDE_INSTALL_KSERVICES5DIR})
25+
message(STATUS "PLUGIN_INSTALL_DIR ${PLUGIN_INSTALL_DIR}")
26+
message(STATUS "KDE_INSTALL_KSERVICES5DIR ${KDE_INSTALL_KSERVICES5DIR}")

src/kdevcxx_with_ai.cc renamed to src/kdevcxx_with_ai/kdevcxx_with_ai.cc

Lines changed: 4 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
5354
void 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

7368
void 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

16679
void kdevcxx_with_ai::createActionsForMainWindow(Sublime::MainWindow *, QString &, KActionCollection & actions)
@@ -208,4 +121,4 @@ void kdevcxx_with_ai::unload() {}
208121
kdevcxx_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"
File renamed without changes.
File renamed without changes.

src/plugin_common/CMakeLists.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,25 @@ add_library( kdevcxx_with_ai::plugin_commn ALIAS plugin_commn )
99
target_sources(plugin_commn PRIVATE
1010
plugin_common.cc
1111
info_dialog.cc
12+
markdown_view.cc
1213
)
1314

1415
target_link_libraries(plugin_commn PUBLIC
1516
ai_processing::core
16-
# Qt5::Widgets
17+
Qt5::Widgets
18+
Qt5::WebEngineWidgets
1719
KF5::TextEditor
1820
${BASIC_LINK_FLAGS}
1921
)
2022
target_compile_options( plugin_commn PUBLIC "-fexceptions")
2123

2224
target_include_directories( plugin_commn PUBLIC include ${CMAKE_CURRENT_SOURCE_DIR} )
25+
26+
27+
# add_executable( markdown_view EXCLUDE_FROM_ALL)
28+
# target_sources(markdown_view PRIVATE
29+
# markdown_view.cc
30+
# markdown_view_test.cc
31+
# )
32+
# target_link_libraries(markdown_view Qt5::Widgets Qt5::WebEngineWidgets)
33+
#

src/plugin_common/include/plugin_common.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ struct app_settings_t;
1717

1818
namespace kdevcxxai
1919
{
20+
inline constexpr auto fist_time_message
21+
= "Kindly navigate to the KDevelop settings to provide your API key for activation.\n"
22+
" Additionally, fine-tune the AI behavior by adjusting the rule set to your preference.\n"
23+
"Modifications to the API key or rules can be made at any moment and will be applied immediately,\n"
24+
"negating the necessity for a KDevelop restart.\n"
25+
"Alterations to AI settings will be effective upon the next invocation.";
26+
2027
enum class get_view_file_path_error
2128
{
2229
no_document,

0 commit comments

Comments
 (0)