Skip to content

Commit

Permalink
Several fixes related to breakpoints.
Browse files Browse the repository at this point in the history
  • Loading branch information
SpartanJ committed Jan 25, 2025
1 parent 4315808 commit 3cdfc84
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 15 deletions.
2 changes: 2 additions & 0 deletions src/eepp/ui/abstract/uiabstracttableview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,8 @@ void UIAbstractTableView::recalculateColumnsWidth() {
}

UITableCell* UIAbstractTableView::getCellFromIndex( const ModelIndex& index ) const {
if ( !index.isValid() )
return nullptr;
for ( const auto& row : mWidgets ) {
for ( const auto& widget : row ) {
if ( widget.second->isType( UI_TYPE_TABLECELL ) &&
Expand Down
4 changes: 2 additions & 2 deletions src/tools/ecode/plugins/debugger/dap/protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ template <> struct std::hash<ecode::dap::SourceBreakpointStateful> {
size_t h4 =
breakpoint.hitCondition ? std::hash<std::string>()( *breakpoint.hitCondition ) : 0;
size_t h5 = breakpoint.logMessage ? std::hash<std::string>()( *breakpoint.logMessage ) : 0;
size_t h6 = std::hash<bool>()( breakpoint.enabled );
return hashCombine( h1, h2, h3, h4, h5, h6 );
// size_t h6 = std::hash<bool>()( breakpoint.enabled );
return hashCombine( h1, h2, h3, h4, h5/*, h6*/ );
}
};
4 changes: 2 additions & 2 deletions src/tools/ecode/plugins/debugger/debuggerclientlistener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace ecode {

std::vector<SourceBreakpoint>
DebuggerClientListener::fromSet( const EE::UnorderedSet<SourceBreakpointStateful>& set ) {
DebuggerClientListener::fromSet( const UnorderedSet<SourceBreakpointStateful>& set ) {
std::vector<SourceBreakpoint> bps;
bps.reserve( set.size() );
for ( const auto& bp : set )
Expand Down Expand Up @@ -326,7 +326,7 @@ void DebuggerClientListener::changeScope( const StackFrame& f ) {
if ( !f.source )
return;

TextRange range{ { f.line - 1, f.column }, { f.line - 1, f.column } };
TextRange range{ { f.line - 1, f.column - 1 }, { f.line - 1, f.column - 1 } };
std::string path( f.source->path );

mPlugin->getUISceneNode()->runOnMainThread(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct ModelVariableNode;
class DebuggerClientListener : public DebuggerClient::Listener {
public:
static std::vector<SourceBreakpoint>
fromSet( const EE::UnorderedSet<SourceBreakpointStateful>& set );
fromSet( const UnorderedSet<SourceBreakpointStateful>& set );

DebuggerClientListener( DebuggerClient* client, DebuggerPlugin* plugin );

Expand Down
31 changes: 23 additions & 8 deletions src/tools/ecode/plugins/debugger/debuggerplugin.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "debuggerplugin.hpp"
#include "../../notificationcenter.hpp"
#include "../../projectbuild.hpp"
#include "../../terminalmanager.hpp"
Expand All @@ -7,7 +8,6 @@
#include "bussocket.hpp"
#include "bussocketprocess.hpp"
#include "dap/debuggerclientdap.hpp"
#include "debuggerplugin.hpp"
#include "models/breakpointsmodel.hpp"
#include "models/processesmodel.hpp"
#include "models/variablesmodel.hpp"
Expand Down Expand Up @@ -1460,12 +1460,15 @@ bool DebuggerPlugin::breakpointSetEnabled( const std::string& doc, Uint32 lineNu
bool enabled ) {
Lock l( mBreakpointsMutex );
auto& breakpoints = mBreakpoints[doc];
auto breakpointIt = breakpoints.find( SourceBreakpointStateful( lineNumber ) );
SourceBreakpointStateful sb( lineNumber );
auto breakpointIt = breakpoints.find( sb );
if ( breakpointIt != breakpoints.end() ) {
breakpointIt->enabled = enabled;
mBreakpointsModel->enable( doc, lineNumber, breakpointIt->enabled );
mThreadPool->run( [this, doc] { sendFileBreakpoints( doc ); } );
getUISceneNode()->getRoot()->invalidateDraw();
if ( enabled != breakpointIt->enabled ) {
breakpointIt->enabled = enabled;
mBreakpointsModel->enable( doc, lineNumber, enabled );
mThreadPool->run( [this, doc] { sendFileBreakpoints( doc ); } );
getUISceneNode()->getRoot()->invalidateDraw();
}
return true;
}
return false;
Expand All @@ -1488,9 +1491,16 @@ bool DebuggerPlugin::breakpointToggleEnabled( TextDocument* doc, Uint32 lineNumb
return breakpointToggleEnabled( doc->getFilePath(), lineNumber );
}

bool DebuggerPlugin::hasBreakpoint( const std::string& doc, Uint32 lineNumber ) {
Lock l( mBreakpointsMutex );
auto& breakpoints = mBreakpoints[doc];
auto breakpointIt = breakpoints.find( SourceBreakpointStateful( lineNumber ) );
return breakpointIt != breakpoints.end();
}

bool DebuggerPlugin::onMouseDown( UICodeEditor* editor, const Vector2i& position,
const Uint32& flags ) {
if ( !( flags & EE_BUTTON_LMASK ) )
if ( !( flags & ( EE_BUTTON_LMASK | EE_BUTTON_RMASK ) ) )
return false;
Float offset = editor->getGutterLocalStartOffset( this );
Vector2f localPos( editor->convertToNodeSpace( position.asFloat() ) );
Expand All @@ -1500,7 +1510,12 @@ bool DebuggerPlugin::onMouseDown( UICodeEditor* editor, const Vector2i& position
localPos.y > editor->getPluginsTopSpace() ) {
if ( editor->getUISceneNode()->getEventDispatcher()->isFirstPress() ) {
auto cursorPos( editor->resolveScreenPosition( position.asFloat() ) );
setBreakpoint( editor, cursorPos.line() + 1 );
if ( ( flags & EE_BUTTON_RMASK ) &&
hasBreakpoint( editor->getDocument().getFilePath(), cursorPos.line() + 1 ) ) {
breakpointToggleEnabled( &editor->getDocument(), cursorPos.line() + 1 );
} else {
setBreakpoint( editor, cursorPos.line() + 1 );
}
}
return true;
}
Expand Down
2 changes: 2 additions & 0 deletions src/tools/ecode/plugins/debugger/debuggerplugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ class DebuggerPlugin : public PluginBase {

bool breakpointSetEnabled( const std::string& doc, Uint32 lineNumber, bool enabled );

bool hasBreakpoint( const std::string& doc, Uint32 lineNumber );

bool onMouseDown( UICodeEditor*, const Vector2i&, const Uint32& flags ) override;

bool isSupportedByAnyDebugger( const std::string& language );
Expand Down
7 changes: 7 additions & 0 deletions src/tools/ecode/plugins/debugger/models/breakpointsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,11 @@ void BreakpointsModel::enable( const std::string& filePath,
}
}

const std::pair<std::string, SourceBreakpointStateful>& BreakpointsModel::get( ModelIndex index ) {
static std::pair<std::string, SourceBreakpointStateful> EMPTY = {};
if ( !index.isValid() || index.row() >= static_cast<Int64>( mBreakpoints.size() ) )
return EMPTY;
return mBreakpoints[index.row()];
}

} // namespace ecode
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class BreakpointsModel : public Model {
void enable( const std::string& filePath, const SourceBreakpointStateful& breakpoint,
bool enable );

const std::pair<std::string, SourceBreakpointStateful>& get( ModelIndex index );
protected:
std::vector<std::pair<std::string, SourceBreakpointStateful>> mBreakpoints;
UISceneNode* mSceneNode{ nullptr };
Expand Down
27 changes: 25 additions & 2 deletions src/tools/ecode/plugins/debugger/statusdebuggercontroller.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "statusdebuggercontroller.hpp"
#include "../plugincontextprovider.hpp"
#include "eepp/ui/uiwidgetcreator.hpp"
#include "statusdebuggercontroller.hpp"
#include <eepp/ui/uicheckbox.hpp>

namespace ecode {
Expand Down Expand Up @@ -33,9 +33,32 @@ UIBreakpointsTableView::getCheckBoxFn( const ModelIndex& index, const Breakpoint
};
}

class UIBreakpointsTableCell : public UITableCell {
public:
static UIBreakpointsTableCell*
New( const std::string& tag,
const std::function<UITextView*( UIPushButton* )>& newTextViewCb ) {
return eeNew( UIBreakpointsTableCell, ( tag, newTextViewCb ) );
}

UIBreakpointsTableCell( const std::string& tag,
const std::function<UITextView*( UIPushButton* )>& newTextViewCb ) :
UITableCell( tag, newTextViewCb ) {}

virtual void updateCell( Model* model ) {
if ( !mTextBox->isType( UI_TYPE_CHECKBOX ) )
return;
auto bpModel = static_cast<BreakpointsModel*>( model );
auto cur = bpModel->get( getCurIndex() );
if ( cur.first.empty() )
return;
mTextBox->asType<UICheckBox>()->setChecked( cur.second.enabled );
}
};

UIWidget* UIBreakpointsTableView::createCell( UIWidget* rowWidget, const ModelIndex& index ) {
if ( index.column() == BreakpointsModel::Enabled ) {
UITableCell* widget = UITableCell::NewWithOpt(
UIBreakpointsTableCell* widget = UIBreakpointsTableCell::New(
mTag + "::cell", getCheckBoxFn( index, (const BreakpointsModel*)getModel() ) );
widget->getTextBox()->setEnabled( true );
widget->setDontAutoHideEmptyTextBox( true );
Expand Down

0 comments on commit 3cdfc84

Please sign in to comment.