From 0330f38caecfb6da420bd7bb79a5e7e5fcc27db4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sat, 4 Jan 2025 21:11:21 -0300 Subject: [PATCH] More improvements. --- src/eepp/ui/abstract/uiabstracttableview.cpp | 3 +- src/tools/ecode/ecode.cpp | 2 - .../debugger/debuggerclientlistener.cpp | 114 +++++++++++++----- .../debugger/debuggerclientlistener.hpp | 4 + .../ecode/plugins/debugger/debuggerplugin.cpp | 3 +- .../debugger/statusdebuggercontroller.cpp | 37 ++---- .../debugger/statusdebuggercontroller.hpp | 1 + 7 files changed, 106 insertions(+), 58 deletions(-) diff --git a/src/eepp/ui/abstract/uiabstracttableview.cpp b/src/eepp/ui/abstract/uiabstracttableview.cpp index a8d4f8899..07d55102a 100644 --- a/src/eepp/ui/abstract/uiabstracttableview.cpp +++ b/src/eepp/ui/abstract/uiabstracttableview.cpp @@ -281,7 +281,8 @@ void UIAbstractTableView::updateHeaderSize() { Float totalWidth = 0; for ( size_t i = 0; i < count; i++ ) { const ColumnData& col = columnData( i ); - totalWidth += col.width; + if ( col.visible ) + totalWidth += col.width; } mHeader->setPixelsSize( totalWidth, getHeaderHeight() ); } diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index b5f635e53..7dcc32ca1 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -578,9 +578,7 @@ void App::initPluginManager() { } }; -#ifdef EE_DEBUG mPluginManager->registerPlugin( DebuggerPlugin::Definition() ); -#endif mPluginManager->registerPlugin( LinterPlugin::Definition() ); mPluginManager->registerPlugin( FormatterPlugin::Definition() ); mPluginManager->registerPlugin( AutoCompletePlugin::Definition() ); diff --git a/src/tools/ecode/plugins/debugger/debuggerclientlistener.cpp b/src/tools/ecode/plugins/debugger/debuggerclientlistener.cpp index ed758f939..9cc4347c8 100644 --- a/src/tools/ecode/plugins/debugger/debuggerclientlistener.cpp +++ b/src/tools/ecode/plugins/debugger/debuggerclientlistener.cpp @@ -22,23 +22,20 @@ class ThreadsModel : public Model { mThreads( threads ), mi18nFn( std::move( fn ) ) {} virtual size_t rowCount( const ModelIndex& ) const { return mThreads.size(); } - virtual size_t columnCount( const ModelIndex& ) const { return 2; } + virtual size_t columnCount( const ModelIndex& ) const { return 1; } virtual std::string columnName( const size_t& colIdx ) const { switch ( colIdx ) { case 0: - return mi18nFn( "id", "ID" ); - case 1: - return mi18nFn( "name", "Name" ); + return mi18nFn( "thread_id", "Thread ID" ); } return ""; } virtual Variant data( const ModelIndex& modelIndex, ModelRole role ) const { - if ( role == ModelRole::Display ) { - return modelIndex.column() == 0 - ? Variant( String::toString( mThreads[modelIndex.row()].id ) ) - : Variant( mThreads[modelIndex.row()].name.c_str() ); + if ( role == ModelRole::Display && modelIndex.column() == 0 ) { + return Variant( String::format( "#%d (%s)", mThreads[modelIndex.row()].id, + mThreads[modelIndex.row()].name.c_str() ) ); } return {}; } @@ -60,6 +57,22 @@ class ThreadsModel : public Model { invalidate(); } + const Thread& getThread( size_t index ) const { + Lock l( mResourceLock ); + eeASSERT( index < mThreads.size() ); + return mThreads[index]; + } + + ModelIndex fromThreadId( int id ) { + Lock l( mResourceLock ); + for ( size_t i = 0; i < mThreads.size(); i++ ) { + const Thread& thread = mThreads[i]; + if ( thread.id == id ) + return index( i ); + } + return {}; + } + protected: std::vector mThreads; i18nFn mi18nFn; @@ -136,6 +149,12 @@ class StackModel : public Model { invalidate(); } + const StackFrame& getStack( size_t index ) const { + Lock l( mResourceLock ); + eeASSERT( index < mStack.stackFrames.size() ); + return mStack.stackFrames[index]; + } + protected: StackTraceInfo mStack; i18nFn mi18nFn; @@ -148,6 +167,10 @@ DebuggerClientListener::DebuggerClientListener( DebuggerClient* client, Debugger DebuggerClientListener::~DebuggerClientListener() { resetState(); + if ( !mPlugin->isShuttingDown() && getStatusDebuggerController() ) { + getStatusDebuggerController()->getUIThreads()->removeEventsOfType( Event::OnModelEvent ); + getStatusDebuggerController()->getUIStack()->removeEventsOfType( Event::OnModelEvent ); + } } void DebuggerClientListener::stateChanged( DebuggerClient::State state ) { @@ -174,8 +197,27 @@ void DebuggerClientListener::stateChanged( DebuggerClient::State state ) { } ); } - getStatusDebuggerController()->getUIThreads()->setModel( mThreadsModel ); - getStatusDebuggerController()->getUIStack()->setModel( mStackModel ); + UITableView* uiThreads = getStatusDebuggerController()->getUIThreads(); + uiThreads->setModel( mThreadsModel ); + + uiThreads->removeEventsOfType( Event::OnModelEvent ); + uiThreads->onModelEvent( [this]( const ModelEvent* modelEvent ) { + if ( modelEvent->getModelEventType() == Abstract::ModelEventType::Open ) { + auto model = static_cast( modelEvent->getModel() ); + mClient->stackTrace( model->getThread( modelEvent->getModelIndex().row() ).id ); + } + } ); + + UITableView* uiStack = getStatusDebuggerController()->getUIStack(); + uiStack->setModel( mStackModel ); + uiStack->removeEventsOfType( Event::OnModelEvent ); + uiStack->onModelEvent( [this]( const ModelEvent* modelEvent ) { + if ( modelEvent->getModelEventType() == Abstract::ModelEventType::Open ) { + auto model = static_cast( modelEvent->getModel() ); + const auto& stack = model->getStack( modelEvent->getModelIndex().row() ); + changeScope( stack ); + } + } ); } ); } } @@ -199,8 +241,11 @@ void DebuggerClientListener::debuggeeTerminated() {} void DebuggerClientListener::capabilitiesReceived( const Capabilities& /*capabilities*/ ) {} void DebuggerClientListener::resetState() { + mStoppedData = {}; + mCurrentScopePos = {}; mThreadsModel->resetThreads(); mStackModel->resetStack(); + mScope.clear(); } void DebuggerClientListener::debuggeeExited( int /*exitCode*/ ) { @@ -212,7 +257,7 @@ void DebuggerClientListener::debuggeeStopped( const StoppedEvent& event ) { Log::debug( "DebuggerClientListener::debuggeeStopped: reason %s", event.reason ); mStoppedData = event; - mCurrentThreadId = mStoppedData->threadId ? *mStoppedData->threadId : 1; + changeThread( mStoppedData->threadId ? *mStoppedData->threadId : 1 ); if ( mPausedToRefreshBreakpoints ) { mPlugin->sendPendingBreakpoints(); @@ -229,12 +274,6 @@ void DebuggerClientListener::debuggeeStopped( const StoppedEvent& event ) { } void DebuggerClientListener::debuggeeContinued( const ContinuedEvent& ) { - mStoppedData = {}; - mCurrentScopePos = {}; - - // Reset models - mScope.clear(); - resetState(); UISceneNode* sceneNode = mPlugin->getUISceneNode(); @@ -261,21 +300,40 @@ void DebuggerClientListener::threads( std::vector&& threads ) { mThreadsModel->setThreads( std::move( threads ) ); } -void DebuggerClientListener::stackTrace( const int /*threadId*/, StackTraceInfo&& stack ) { - if ( !stack.stackFrames.empty() ) { - auto& f = stack.stackFrames[0]; +void DebuggerClientListener::changeScope( const StackFrame& f ) { + mClient->scopes( f.id ); - // mClient->scopes( f.id ); + if ( !f.source ) + return; - if ( f.source ) { - TextRange range{ { f.line - 1, f.column }, { f.line - 1, f.column } }; - std::string path( f.source->path ); + TextRange range{ { f.line - 1, f.column }, { f.line - 1, f.column } }; + std::string path( f.source->path ); - mPlugin->getUISceneNode()->runOnMainThread( [this, path, range] { - mPlugin->getPluginContext()->focusOrLoadFile( path, range ); - } ); + mPlugin->getUISceneNode()->runOnMainThread( + [this, path, range] { mPlugin->getPluginContext()->focusOrLoadFile( path, range ); } ); + + mCurrentScopePos = { f.source->path, f.line }; - mCurrentScopePos = { f.source->path, f.line }; + if ( getStatusDebuggerController() && getStatusDebuggerController()->getUIStack() ) + getStatusDebuggerController()->getUIStack()->setSelection( mStackModel->index( f.id ) ); +} + +void DebuggerClientListener::changeThread( int id ) { + mCurrentThreadId = id; + if ( getStatusDebuggerController() && getStatusDebuggerController()->getUIThreads() ) { + getStatusDebuggerController()->getUIThreads()->setSelection( + mThreadsModel->fromThreadId( id ) ); + } +} + +void DebuggerClientListener::stackTrace( const int threadId, StackTraceInfo&& stack ) { + changeThread( threadId ); + + for ( const auto& f : stack.stackFrames ) { + // Jump to the first stack frame that can be read + if ( f.source ) { + changeScope( f ); + break; } } diff --git a/src/tools/ecode/plugins/debugger/debuggerclientlistener.hpp b/src/tools/ecode/plugins/debugger/debuggerclientlistener.hpp index e3818fda2..a5ae3c321 100644 --- a/src/tools/ecode/plugins/debugger/debuggerclientlistener.hpp +++ b/src/tools/ecode/plugins/debugger/debuggerclientlistener.hpp @@ -79,6 +79,10 @@ class DebuggerClientListener : public DebuggerClient::Listener { StatusDebuggerController* getStatusDebuggerController() const; void resetState(); + + void changeScope( const StackFrame& f ); + + void changeThread( int id ); }; } // namespace ecode diff --git a/src/tools/ecode/plugins/debugger/debuggerplugin.cpp b/src/tools/ecode/plugins/debugger/debuggerplugin.cpp index e0f96025e..744d7e7da 100644 --- a/src/tools/ecode/plugins/debugger/debuggerplugin.cpp +++ b/src/tools/ecode/plugins/debugger/debuggerplugin.cpp @@ -607,7 +607,7 @@ void DebuggerPlugin::drawLineNumbersBefore( UICodeEditor* editor, Float dim = radius * 2; Float gutterSpace = editor->getGutterSpace( this ); - lnPos.x += ( gutterSpace - dim ) * 0.5f; + lnPos.x += editor->getLineNumberPaddingLeft() + ( gutterSpace - dim ) * 0.5f; lnPos.y += ( lineHeight - dim ) * 0.5f; Triangle2f tri; @@ -774,7 +774,6 @@ void DebuggerPlugin::hideStatusBarElement() { StatusDebuggerController* DebuggerPlugin::getStatusDebuggerController() const { auto debuggerElement = getPluginContext()->getStatusBar()->getStatusBarElement( "status_app_debugger" ); - eeASSERT( debuggerElement ); return static_cast( debuggerElement.get() ); } } // namespace ecode diff --git a/src/tools/ecode/plugins/debugger/statusdebuggercontroller.cpp b/src/tools/ecode/plugins/debugger/statusdebuggercontroller.cpp index f33026064..a8e0db9e9 100644 --- a/src/tools/ecode/plugins/debugger/statusdebuggercontroller.cpp +++ b/src/tools/ecode/plugins/debugger/statusdebuggercontroller.cpp @@ -34,12 +34,13 @@ void StatusDebuggerController::createContainer() { if ( mContainer ) return; const auto XML = R"xml( - - - + + + + + - - + )xml"; @@ -53,32 +54,18 @@ void StatusDebuggerController::createContainer() { ->loadLayoutFromString( XML, mMainSplitter ) ->asType(); + mContainer->bind( "debugger_threads_and_stack", mUIThreadsSplitter ); mContainer->bind( "debugger_threads", mUIThreads ); mContainer->bind( "debugger_stack", mUIStack ); mContainer->bind( "debugger_breakpoints", mUIBreakpoints ); - mContainer->on( Event::OnSizeChange, [this]( const Event* event ) { - if ( !mContainer->isVisible() || mContainer->getSize().getWidth() == 0.f ) - return; + mUIThreads->setAutoExpandOnSingleColumn( true ); - const Float width = mContainer->getPixelsSize().getWidth(); + mUIStack->setAutoColumnsWidth( true ); + mUIStack->setMainColumn( 1 ); - mUIThreads->setColumnWidth( 0, width * 0.1 ); - mUIThreads->setColumnWidth( 1, eefloor( width * 0.88 ) ); - - mUIStack->setColumnWidth( 0, width * 0.05 ); - mUIStack->setColumnWidth( 1, width * 0.3 ); - mUIStack->setColumnWidth( 2, width * 0.15 ); - mUIStack->setColumnWidth( 3, eefloor( width * 0.3 ) ); - mUIStack->setColumnWidth( 4, width * 0.08 ); - mUIStack->setColumnWidth( 5, width * 0.08 ); - - mUIBreakpoints->setColumnWidth( 0, width * 0.1 ); - mUIBreakpoints->setColumnWidth( 1, eefloor( width * 0.7 ) ); - mUIBreakpoints->setColumnWidth( 2, eefloor( width * 0.1 ) ); - - mContainer->removeEventListener( event->getCallbackId() ); - } ); + mUIBreakpoints->setAutoColumnsWidth( true ); + mUIBreakpoints->setMainColumn( 1 ); } } // namespace ecode diff --git a/src/tools/ecode/plugins/debugger/statusdebuggercontroller.hpp b/src/tools/ecode/plugins/debugger/statusdebuggercontroller.hpp index 09d434c45..3a4c7bd1a 100644 --- a/src/tools/ecode/plugins/debugger/statusdebuggercontroller.hpp +++ b/src/tools/ecode/plugins/debugger/statusdebuggercontroller.hpp @@ -38,6 +38,7 @@ class StatusDebuggerController : public StatusBarElement { UITableView* mUIThreads{ nullptr }; UITableView* mUIStack{ nullptr }; UITableView* mUIBreakpoints{ nullptr }; + UISplitter* mUIThreadsSplitter{ nullptr }; void createContainer(); };