Skip to content

Commit

Permalink
Initial work on AI plugin for CodeLite
Browse files Browse the repository at this point in the history
  • Loading branch information
eranif committed Jul 21, 2024
1 parent d1ff88d commit 2392c2b
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@
[submodule "hunspell"]
path = submodules/hunspell
url = https://github.com/hunspell/hunspell.git
[submodule "submodules/llama.cpp"]
path = submodules/llama.cpp
url = https://github.com/ggerganov/llama.cpp.git
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,8 @@ add_subdirectory(cc-wrapper)

# include the yaml-cpp directory
include_directories("${CL_SRC_ROOT}/yaml-cpp/include")
add_subdirectory("${CL_SRC_ROOT}/submodules/llama.cpp")
add_subdirectory("${CL_SRC_ROOT}/submodules/llama.cpp/examples/main")

if(WXC_APP)
add_subdirectory(wxcrafter)
Expand Down Expand Up @@ -965,6 +967,7 @@ else()
add_subdirectory(HelpPlugin)
add_subdirectory(WebTools)
add_subdirectory(SmartCompletion)
add_subdirectory(assistance.ai)

if(UNIX
AND NOT APPLE
Expand Down
7 changes: 2 additions & 5 deletions LiteEditor/frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1015,8 +1015,7 @@ void clMainFrame::AddKeyboardAccelerators()
mgr->AddAccelerator(_("C++"), { { "swap_files", _("Swap Header/Implementation file"), "F12" },
{ "find_decl", _("Goto Declaration") },
{ "find_impl", _("Goto Implementation") },
{ "open_include_file", _("Open Include File") },
{ "add_include_file", _("Add Include File"), "Ctrl-Shift-I" } });
{ "open_include_file", _("Open Include File") } });
mgr->AddAccelerator(_("C++ | Code Generation / Refactoring"),
{ { "setters_getters", _("Generate Setters/Getters...") },
{ "move_impl", _("Move Function Implementation to...") },
Expand Down Expand Up @@ -5457,9 +5456,7 @@ void clMainFrame::OnSettingsChanged(wxCommandEvent& e)
m_mainFrameTitleTemplate = clConfig::Get().Read(kConfigFrameTitlePattern, wxString("$workspace $fullpath"));
}

void clMainFrame::OnDetachEditor(wxCommandEvent& e)
{ /*GetMainBook()->DetachActiveEditor();*/
}
void clMainFrame::OnDetachEditor(wxCommandEvent& e) { /*GetMainBook()->DetachActiveEditor();*/ }

void clMainFrame::OnDetachEditorUI(wxUpdateUIEvent& e) { e.Enable(GetMainBook()->GetActiveEditor() != NULL); }

Expand Down
90 changes: 90 additions & 0 deletions assistance.ai/AssistanceAI.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright : (C) 2008 by Eran Ifrah
// file name : codeformatter.cpp
//
// -------------------------------------------------------------------------
// A
// _____ _ _ _ _
// / __ \ | | | | (_) |
// | / \/ ___ __| | ___| | _| |_ ___
// | | / _ \ / _ |/ _ \ | | | __/ _ )
// | \__/\ (_) | (_| | __/ |___| | || __/
// \____/\___/ \__,_|\___\_____/_|\__\___|
//
// F i l e
//
// This program 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 2 of the License, or
// (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
#include "AssistanceAI.hpp"

#include "clKeyboardManager.h"
#include "globals.h"
#include "macromanager.h"

#include <wx/app.h> //wxInitialize/wxUnInitialize
#include <wx/ffile.h>
#include <wx/filename.h>
#include <wx/log.h>
#include <wx/menu.h>
#include <wx/msgdlg.h>
#include <wx/progdlg.h>
#include <wx/wupdlock.h>
#include <wx/xrc/xmlres.h>

namespace
{
AssistanceAI* thePlugin = NULL;
}

// Allocate the code formatter on the heap, it will be freed by
// the application
CL_PLUGIN_API IPlugin* CreatePlugin(IManager* manager)
{
if (thePlugin == 0) {
thePlugin = new AssistanceAI(manager);
}
return thePlugin;
}

CL_PLUGIN_API PluginInfo* GetPluginInfo()
{
static PluginInfo info;
info.SetAuthor("Eran Ifrah");
info.SetName("AssistanceAI");
info.SetDescription(_("A built-in AI assistance"));
info.SetVersion("v1.0");
return &info;
}

CL_PLUGIN_API int GetPluginInterfaceVersion() { return PLUGIN_INTERFACE_VERSION; }

AssistanceAI::AssistanceAI(IManager* manager)
: IPlugin(manager)
{
m_longName = _("A built-in AI assistance");
m_shortName = _("A built-in AI assistance");

clKeyboardManager::Get()->AddAccelerator(_("Assistance AI"),
{ { "show_ai_chat", _("Show AI Chat Window"), "Ctrl-Shift-I" } });
}

AssistanceAI::~AssistanceAI() {}

void AssistanceAI::CreateToolBar(clToolBarGeneric* toolbar) { wxUnusedVar(toolbar); }

void AssistanceAI::CreatePluginMenu(wxMenu* pluginsMenu) { wxUnusedVar(pluginsMenu); }

void AssistanceAI::HookPopupMenu(wxMenu* menu, MenuType type)
{
wxUnusedVar(type);
wxUnusedVar(menu);
}

void AssistanceAI::UnPlug() {}
39 changes: 39 additions & 0 deletions assistance.ai/AssistanceAI.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright : (C) 2024 by Eran Ifrah
// file name : AssistanceAI.h
//
// -------------------------------------------------------------------------
// A
// _____ _ _ _ _
// / __ \ | | | | (_) |
// | / \/ ___ __| | ___| | _| |_ ___
// | | / _ \ / _ |/ _ \ | | | __/ _ )
// | \__/\ (_) | (_| | __/ |___| | || __/
// \____/\___/ \__,_|\___\_____/_|\__\___|
//
// F i l e
//
// This program 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 2 of the License, or
// (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
#pragma once

#include "cl_command_event.h"
#include "plugin.h"

class AssistanceAI : public IPlugin
{
public:
AssistanceAI(IManager* manager);
virtual ~AssistanceAI();
virtual void CreateToolBar(clToolBarGeneric* toolbar);
virtual void CreatePluginMenu(wxMenu* pluginsMenu);
virtual void HookPopupMenu(wxMenu* menu, MenuType type);
virtual void UnPlug();
};
53 changes: 53 additions & 0 deletions assistance.ai/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# set the plugin name here
set(PLUGIN_NAME "AssistanceAI")

# Our project is called 'plugin' this is how it will be called in visual studio, and in our makefiles.
project(${PLUGIN_NAME})

# It was noticed that when using MinGW gcc it is essential that 'core' is mentioned before 'base'.

# wxWidgets include (this will do all the magic to configure everything)
include("${wxWidgets_USE_FILE}")

# Include paths
include_directories("${CL_SRC_ROOT}/Plugin" "${CL_SRC_ROOT}/sdk/wxsqlite3/include" "${CL_SRC_ROOT}/CodeLite"
"${CL_SRC_ROOT}/CodeLite/ssh" "${CL_SRC_ROOT}/PCH" "${CL_SRC_ROOT}/Interfaces")

add_definitions(-DWXUSINGDLL_WXSQLITE3)
add_definitions(-DWXUSINGDLL_CL)
add_definitions(-DWXUSINGDLL_SDK)
add_definitions(-DASTYLE_LIB)

if(USE_PCH AND NOT MINGW)
add_definitions(-include "${CL_PCH_FILE}")
add_definitions(-Winvalid-pch)
endif()

if(UNIX AND NOT APPLE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
endif()

if(APPLE)
add_definitions(-fPIC)
endif()

file(GLOB SRCS "*.cpp")

# Define the output
add_library(${PLUGIN_NAME} SHARED ${SRCS})

target_precompile_headers(${PLUGIN_NAME} REUSE_FROM PCH)

# Remove the "lib" prefix from the plugin name
set_target_properties(${PLUGIN_NAME} PROPERTIES PREFIX "")
target_link_libraries(${PLUGIN_NAME} ${LINKER_OPTIONS} ${wxWidgets_LIBRARIES} libcodelite plugin)

cl_install_plugin(${PLUGIN_NAME})
cl_install_file_shared(${CL_SRC_ROOT}/Runtime/astyle.sample)
cl_install_file_shared(${CL_SRC_ROOT}/Runtime/php.sample)

if(MINGW)
# install clang-format
msys_install_clang64_tool(clang-format.exe ${CL_INSTALL_BIN})
endif()
1 change: 1 addition & 0 deletions submodules/llama.cpp
Submodule llama.cpp added at c3776c

0 comments on commit 2392c2b

Please sign in to comment.