Skip to content

Commit

Permalink
DAP WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
SpartanJ committed Dec 28, 2024
1 parent 72a3d09 commit 42e7369
Show file tree
Hide file tree
Showing 4 changed files with 225 additions and 6 deletions.
44 changes: 44 additions & 0 deletions bin/assets/plugins/debugger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"dap": [
{
"name": "gdb",
"url": "https://www.gnu.org/software/gdb",
"run": {
"command": "gdb --interpreter=dap"
},
"configurations": [
{
"name": "launch binary",
"command": "launch",
"arguments": {
"program": "${file}",
"args": "${args}",
"cwd": "${cwd}",
"env": "${env}",
"stopOnEntry": "${stopOnEntry}"
}
}
]
},
{
"name": "lldb-dab",
"url": "https://github.com/llvm/llvm-project/blob/main/lldb/tools/lldb-dap/README.md",
"run": {
"command": "lldb-dap"
},
"configurations": [
{
"name": "launch binary",
"command": "launch",
"arguments": {
"program": "${file}",
"args": "${args}",
"cwd": "${cwd}",
"env": "${env}",
"stopOnEntry": "${stopOnEntry}"
}
}
]
}
]
}
16 changes: 10 additions & 6 deletions src/tools/ecode/ecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
#include "iconmanager.hpp"
#include "keybindingshelper.hpp"
#include "pathhelper.hpp"
#include "plugins/autocomplete/autocompleteplugin.hpp"
#include "plugins/formatter/formatterplugin.hpp"
#include "plugins/git/gitplugin.hpp"
#include "plugins/linter/linterplugin.hpp"
#include "plugins/lsp/lspclientplugin.hpp"
#include "plugins/xmltools/xmltoolsplugin.hpp"
#include "settingsactions.hpp"
#include "settingsmenu.hpp"
#include "uibuildsettings.hpp"
Expand All @@ -23,6 +17,15 @@
#include <iostream>
#include <nlohmann/json.hpp>

//! Plugins
#include "plugins/autocomplete/autocompleteplugin.hpp"
#include "plugins/formatter/formatterplugin.hpp"
#include "plugins/debugger/debuggerplugin.hpp"
#include "plugins/git/gitplugin.hpp"
#include "plugins/linter/linterplugin.hpp"
#include "plugins/lsp/lspclientplugin.hpp"
#include "plugins/xmltools/xmltoolsplugin.hpp"

#if EE_PLATFORM == EE_PLATFORM_LINUX
// For malloc_trim, which is a GNU extension
extern "C" {
Expand Down Expand Up @@ -572,6 +575,7 @@ void App::initPluginManager() {
} );
}
};
mPluginManager->registerPlugin( DebuggerPlugin::Definition() );
mPluginManager->registerPlugin( LinterPlugin::Definition() );
mPluginManager->registerPlugin( FormatterPlugin::Definition() );
mPluginManager->registerPlugin( AutoCompletePlugin::Definition() );
Expand Down
132 changes: 132 additions & 0 deletions src/tools/ecode/plugins/debugger/debuggerplugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#include "debuggerplugin.hpp"
#include <eepp/system/filesystem.hpp>
#include <eepp/system/scopedop.hpp>
#include <nlohmann/json.hpp>

using namespace EE::UI;
using namespace EE::UI::Doc;

using namespace std::literals;

using json = nlohmann::json;

#if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN || defined( __EMSCRIPTEN_PTHREADS__ )
#define DEBUGGER_THREADED 1
#else
#define DEBUGGER_THREADED 0
#endif

namespace ecode {

Plugin* DebuggerPlugin::New( PluginManager* pluginManager ) {
return eeNew( DebuggerPlugin, ( pluginManager, false ) );
}

Plugin* DebuggerPlugin::NewSync( PluginManager* pluginManager ) {
return eeNew( DebuggerPlugin, ( pluginManager, true ) );
}

DebuggerPlugin::DebuggerPlugin( PluginManager* pluginManager, bool sync ) :
PluginBase( pluginManager ) {
if ( sync ) {
load( pluginManager );
} else {
#if defined( DEBUGGER_THREADED ) && DEBUGGER_THREADED == 1
mThreadPool->run( [this, pluginManager] { load( pluginManager ); } );
#else
load( pluginManager );
#endif
}
}

DebuggerPlugin::~DebuggerPlugin() {
waitUntilLoaded();
mShuttingDown = true;
}

void DebuggerPlugin::load( PluginManager* pluginManager ) {
Clock clock;
AtomicBoolScopedOp loading( mLoading, true );
pluginManager->subscribeMessages( this,
[this]( const auto& notification ) -> PluginRequestHandle {
return processMessage( notification );
} );

std::string path = pluginManager->getPluginsPath() + "debugger.json";
if ( FileSystem::fileExists( path ) ||
FileSystem::fileWrite( path, "{\n \"config\":{},\n \"keybindings\":{}\n}\n" ) ) {
mConfigPath = path;
}
std::string data;
if ( !FileSystem::fileGet( path, data ) )
return;
mConfigHash = String::hash( data );

json j;
try {
j = json::parse( data, nullptr, true, true );
} catch ( const json::exception& e ) {
Log::error( "DebuggerPlugin::load - Error parsing config from path %s, error: %s, config "
"file content:\n%s",
path.c_str(), e.what(), data.c_str() );
// Recreate it
j = json::parse( "{\n \"config\":{},\n \"keybindings\":{},\n}\n", nullptr, true, true );
}

bool updateConfigFile = false;

if ( j.contains( "config" ) ) {
}

if ( mKeyBindings.empty() ) {
}

if ( j.contains( "keybindings" ) ) {
auto& kb = j["keybindings"];
std::initializer_list<std::string> list = {};
for ( const auto& key : list ) {
if ( kb.contains( key ) ) {
if ( !kb[key].empty() )
mKeyBindings[key] = kb[key];
} else {
kb[key] = mKeyBindings[key];
updateConfigFile = true;
}
}
}

if ( updateConfigFile ) {
std::string newData = j.dump( 2 );
if ( newData != data ) {
FileSystem::fileWrite( path, newData );
mConfigHash = String::hash( newData );
}
}

if ( getUISceneNode() ) {
// Init UI
}

subscribeFileSystemListener();
mReady = true;
fireReadyCbs();
setReady( clock.getElapsedTime() );
}

PluginRequestHandle DebuggerPlugin::processMessage( const PluginMessage& msg ) {
switch ( msg.type ) {
case PluginMessageType::WorkspaceFolderChanged: {

break;
}
case ecode::PluginMessageType::UIReady: {
// Init UI if not initialized
break;
}
default:
break;
}
return PluginRequestHandle::empty();
}

} // namespace ecode
39 changes: 39 additions & 0 deletions src/tools/ecode/plugins/debugger/debuggerplugin.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once

#include "../plugin.hpp"
#include "../pluginmanager.hpp"

using namespace EE::UI::Models;
using namespace EE::UI;

namespace ecode {

class DebuggerPlugin : public PluginBase {
public:
static PluginDefinition Definition() {
return { "debugger", "Debugger", "Debugger integration",
DebuggerPlugin::New, { 0, 0, 1 }, DebuggerPlugin::NewSync };
}

static Plugin* New( PluginManager* pluginManager );

static Plugin* NewSync( PluginManager* pluginManager );

virtual ~DebuggerPlugin();

std::string getId() override { return Definition().id; }

std::string getTitle() override { return Definition().name; }

std::string getDescription() override { return Definition().description; }

protected:
DebuggerPlugin( PluginManager* pluginManager, bool sync );

void load( PluginManager* pluginManager );

PluginRequestHandle processMessage( const PluginMessage& msg );

};

} // namespace ecode

0 comments on commit 42e7369

Please sign in to comment.