diff --git a/bin/assets/plugins/debugger.json b/bin/assets/plugins/debugger.json index 56c7564e7..5690a5921 100644 --- a/bin/assets/plugins/debugger.json +++ b/bin/assets/plugins/debugger.json @@ -61,7 +61,7 @@ { "name": "lldb-dap", "url": "https://github.com/llvm/llvm-project/blob/main/lldb/tools/lldb-dap/README.md", - "type": "cppdbg", + "type": "lldb", "run": { "command": "lldb-dap", "command_fallback": "lldb-vscode" diff --git a/src/tools/ecode/plugins/debugger/debuggerplugin.cpp b/src/tools/ecode/plugins/debugger/debuggerplugin.cpp index 1fff332b4..21b2068c2 100644 --- a/src/tools/ecode/plugins/debugger/debuggerplugin.cpp +++ b/src/tools/ecode/plugins/debugger/debuggerplugin.cpp @@ -234,6 +234,7 @@ void DebuggerPlugin::resetExpressions() { void DebuggerPlugin::closeProject() { exitDebugger(); + mDapInputs.clear(); mExpressions.clear(); if ( mExpressionsHolder ) mExpressionsHolder->clear( true ); @@ -489,6 +490,35 @@ void DebuggerPlugin::loadProjectConfiguration( const std::string& path ) { mDapConfigs.emplace_back( std::move( dapConfig ) ); } } + + if ( !j.contains( "inputs" ) ) + return; + + auto& inputs = j["inputs"]; + + for ( const auto& input : inputs ) { + if ( !input.is_object() ) + continue; + DapConfigurationInput in; + std::string id = input.value( "id", "" ); + in.id = id; + if ( in.id.empty() ) + continue; + in.type = input.value( "type", "" ); + String::toLowerInPlace( in.type ); + if ( "promptstring" != in.type && "pickstring" != in.type ) + continue; + in.description = input.value( "description", "" ); + in.defaultValue = input.value( "default", "" ); + if ( input.contains( "options" ) && input["options"].is_array() ) { + auto& opts = input["options"]; + for ( const auto& opt : opts ) { + if ( opt.is_string() ) + in.options.push_back( opt ); + } + } + mDapInputs[id] = std::move( in ); + } } void DebuggerPlugin::loadProjectConfigurations() { @@ -1007,6 +1037,40 @@ void DebuggerPlugin::replaceKeysInJson( nlohmann::json& json, int randomPort ) { } } +std::unordered_map +DebuggerPlugin::needsToResolveInputs( nlohmann::json& json ) { + std::unordered_map inputs; + + const auto matchString = [this, &inputs]( nlohmann::json& e ) { + static LuaPattern ptrn( "%$%{input%:([%w_]+)%}"sv ); + if ( e.is_string() ) { + std::string val( e ); + PatternMatcher::Range matches[4]; + if ( ptrn.matches( val, matches ) ) { + std::string id( val.substr( matches[1].start, matches[1].end - matches[1].start ) ); + auto it = mDapInputs.find( id ); + if ( it != mDapInputs.end() ) + inputs[it->first] = it->second; + } + } + }; + + for ( auto& j : json ) { + if ( j.is_object() ) { + auto rinputs = needsToResolveInputs( j ); + for ( auto& i : rinputs ) + inputs[std::move( i.first )] = std::move( i.second ); + } else if ( j.is_array() ) { + for ( auto& e : j ) + matchString( e ); + } else if ( j.is_string() ) { + matchString( j ); + } + } + + return inputs; +} + void DebuggerPlugin::onRegisterDocument( TextDocument* doc ) { doc->setCommand( "debugger-continue-interrupt", [this] { if ( mDebugger && mListener ) { @@ -1346,10 +1410,13 @@ void DebuggerPlugin::runConfig( const std::string& debugger, const std::string& return; } + + auto args = configIt->args; + // needsToResolveInputs( args ); + int randomPort = Math::randi( 44000, 45000 ); ProtocolSettings protocolSettings; protocolSettings.launchCommand = configIt->request; - auto args = configIt->args; replaceKeysInJson( args, randomPort ); protocolSettings.launchRequest = args; protocolSettings.redirectStdout = debuggerIt->redirectStdout; diff --git a/src/tools/ecode/plugins/debugger/debuggerplugin.hpp b/src/tools/ecode/plugins/debugger/debuggerplugin.hpp index 79726bc6d..006effcdd 100644 --- a/src/tools/ecode/plugins/debugger/debuggerplugin.hpp +++ b/src/tools/ecode/plugins/debugger/debuggerplugin.hpp @@ -37,6 +37,14 @@ struct DapTool { bool supportsSourceRequest{ false }; }; +struct DapConfigurationInput { + std::string id; + std::string description; + std::string type; + std::string defaultValue; + std::vector options; +}; + class DebuggerPlugin : public PluginBase { public: static PluginDefinition Definition() { @@ -96,6 +104,7 @@ class DebuggerPlugin : public PluginBase { StatusDebuggerController::State mDebuggingState{ StatusDebuggerController::State::NotStarted }; std::vector mExpressions; std::shared_ptr mExpressionsHolder; + UnorderedMap mDapInputs; // Begin Hover Stuff Uint32 mHoverWaitCb{ 0 }; @@ -215,6 +224,9 @@ class DebuggerPlugin : public PluginBase { void resetExpressions(); void closeProject(); + + std::unordered_map + needsToResolveInputs( nlohmann::json& json ); }; } // namespace ecode