Skip to content

Commit

Permalink
More improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
SpartanJ committed Jan 5, 2025
1 parent df65ec7 commit 0330f38
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 58 deletions.
3 changes: 2 additions & 1 deletion src/eepp/ui/abstract/uiabstracttableview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}
Expand Down
2 changes: 0 additions & 2 deletions src/tools/ecode/ecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand Down
114 changes: 86 additions & 28 deletions src/tools/ecode/plugins/debugger/debuggerclientlistener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
}
Expand All @@ -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<Thread> mThreads;
i18nFn mi18nFn;
Expand Down Expand Up @@ -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;
Expand All @@ -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 ) {
Expand All @@ -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<const ThreadsModel*>( 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<const StackModel*>( modelEvent->getModel() );
const auto& stack = model->getStack( modelEvent->getModelIndex().row() );
changeScope( stack );
}
} );
} );
}
}
Expand All @@ -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*/ ) {
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -261,21 +300,40 @@ void DebuggerClientListener::threads( std::vector<Thread>&& 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;
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/tools/ecode/plugins/debugger/debuggerclientlistener.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions src/tools/ecode/plugins/debugger/debuggerplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -774,7 +774,6 @@ void DebuggerPlugin::hideStatusBarElement() {
StatusDebuggerController* DebuggerPlugin::getStatusDebuggerController() const {
auto debuggerElement =
getPluginContext()->getStatusBar()->getStatusBarElement( "status_app_debugger" );
eeASSERT( debuggerElement );
return static_cast<StatusDebuggerController*>( debuggerElement.get() );
}
} // namespace ecode
37 changes: 12 additions & 25 deletions src/tools/ecode/plugins/debugger/statusdebuggercontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ void StatusDebuggerController::createContainer() {
if ( mContainer )
return;
const auto XML = R"xml(
<TabWidget id="app_debugger" layout_width="match_parent" layout_height="0dp" layout_weight="1">
<TableView id="debugger_stack" layout_width="mp" layout_height="mp" />
<TableView id="debugger_threads" layout_width="mp" layout_height="mp" />
<TabWidget id="app_debugger" layout_width="mp" layout_height="mp">
<Splitter id="debugger_threads_and_stack" layout_width="mp" lh="mp" splitter-partition="15%">
<TableView id="debugger_threads" layout_width="mp" layout_height="mp" />
<TableView id="debugger_stack" layout_width="mp" layout_height="mp" />
</Splitter>
<TableView id="debugger_breakpoints" layout_width="mp" layout_height="mp" />
<Tab text="@string(stack, Stack)" owns="debugger_stack" />
<Tab text="@string(threads, Threads)" owns="debugger_threads" />
<Tab text="@string(threads_and_stack, Threads & Stack)" owns="debugger_threads_and_stack" />
<Tab text="@string(breakpoints, Breakpoints)" owns="debugger_breakpoints" />
</TabWidget>
)xml";
Expand All @@ -53,32 +54,18 @@ void StatusDebuggerController::createContainer() {
->loadLayoutFromString( XML, mMainSplitter )
->asType<UILinearLayout>();

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
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class StatusDebuggerController : public StatusBarElement {
UITableView* mUIThreads{ nullptr };
UITableView* mUIStack{ nullptr };
UITableView* mUIBreakpoints{ nullptr };
UISplitter* mUIThreadsSplitter{ nullptr };

void createContainer();
};
Expand Down

0 comments on commit 0330f38

Please sign in to comment.