Files
whetstone_DSL/editor/src/DAPBreakpointHitDispatcher.h

48 lines
1.6 KiB
C
Raw Normal View History

#pragma once
#include "ASTNodeBreakpointMapper.h"
#include "DebugAdapterRouter.h"
#include <string>
#include <vector>
namespace whetstone {
struct HitResult {
std::string language;
std::string astNodeId;
int line = 0;
bool dispatched = false;
};
class DAPBreakpointHitDispatcher {
public:
// Find the first active breakpoint at source:line, set router to its language.
HitResult dispatch(const std::string& source, int line,
const ASTNodeBreakpointMapper& mapper,
DebugAdapterRouter& router) const {
for (const auto& bp : mapper.allBreakpoints()) {
if (bp.active && bp.source == source && bp.line == line) {
router.setActiveLanguage(bp.language);
return {bp.language, bp.astNodeId, bp.line, true};
}
}
return {"", "", line, false};
}
// Return a HitResult for every active breakpoint at source:line.
// Router ends at the language of the last match.
std::vector<HitResult> dispatchAll(const std::string& source, int line,
const ASTNodeBreakpointMapper& mapper,
DebugAdapterRouter& router) const {
std::vector<HitResult> results;
for (const auto& bp : mapper.allBreakpoints()) {
if (bp.active && bp.source == source && bp.line == line) {
router.setActiveLanguage(bp.language);
results.push_back({bp.language, bp.astNodeId, bp.line, true});
}
}
return results;
}
};
} // namespace whetstone