Skip to content
3 changes: 3 additions & 0 deletions scip_indexer/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ cc_library(
cc_library(
name = "scip_indexer",
srcs = [
"Debug.cc",
"Debug.h",
"SCIPIndexer.cc",
"SCIPSymbolRef.cc",
"SCIPSymbolRef.h",
],
linkstatic = select({
"@com_stripe_ruby_typer//tools/config:linkshared": 0,
Expand Down
24 changes: 24 additions & 0 deletions scip_indexer/Debug.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

#include <string>

#include "core/GlobalState.h"
#include "core/Loc.h"

#include "scip_indexer/Debug.h"

namespace sorbet::scip_indexer {

void _log_debug(const sorbet::core::GlobalState &gs, sorbet::core::Loc loc, std::string s) {
if (auto e = gs.beginError(loc, SCIPRubyDebug)) {
auto lines = absl::StrSplit(s, '\n');
for (auto line = lines.begin(); line != lines.end(); line++) {
auto text = std::string(line->begin(), line->length());
if (line == lines.begin()) {
e.setHeader("[scip-ruby] {}", text);
} else {
e.addErrorNote("{}", text);
}
}
}
}
} // namespace sorbet::scip_indexer
25 changes: 23 additions & 2 deletions scip_indexer/Debug.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
#include <ostream>
#ifndef SORBET_SCIP_DEBUG
#define SORBET_SCIP_DEBUG

#include <sstream>
#include <string>
#include <vector>

#include "absl/strings/str_split.h"

#include "common/common.h"
#include "core/Error.h"

template <typename K, typename V, typename Fn> std::string map_to_string(const sorbet::UnorderedMap<K, V> m, Fn f) {
std::ostringstream out;
Expand Down Expand Up @@ -45,4 +51,19 @@ template <typename T, typename Fn> std::string vec_to_string(const std::vector<T
}
out << "]";
return out.str();
}
}

namespace sorbet::scip_indexer {

constexpr sorbet::core::ErrorClass SCIPRubyDebug{400, sorbet::core::StrictLevel::False};

void _log_debug(const sorbet::core::GlobalState &gs, sorbet::core::Loc loc, std::string s);
} // namespace sorbet::scip_indexer

#ifndef NDEBUG
#define LOG_DEBUG(__gs, __loc, __s) sorbet::scip_indexer::_log_debug(__gs, __loc, __s)
#else
#define LOG_DEBUG(__gs, __s)
#endif

#endif // SORBET_SCIP_DEBUG
Loading