diff --git a/include/xeus-python/xdebugger.hpp b/include/xeus-python/xdebugger.hpp index a7268818..9645c6ea 100644 --- a/include/xeus-python/xdebugger.hpp +++ b/include/xeus-python/xdebugger.hpp @@ -72,6 +72,10 @@ namespace xpyt py::object m_pydebugger; xeus::xthread m_client_runner; bool m_copy_to_globals_available; + + bool m_just_my_code = false; + bool m_filter_internal_frames = false; + std::vector m_internal_modules; }; XEUS_PYTHON_API diff --git a/src/xdebugger.cpp b/src/xdebugger.cpp index 700e4702..c8c04e65 100644 --- a/src/xdebugger.cpp +++ b/src/xdebugger.cpp @@ -59,7 +59,10 @@ namespace xpyt , m_debugpy_host("127.0.0.1") , m_debugpy_port("") , m_debugger_config(debugger_config) + , m_just_my_code(false) + , m_filter_internal_frames(true) { + std::cout << "Debugger Config: " << m_debugger_config << std::endl; m_debugpy_port = xeus::find_free_port(100, 5678, 5900); register_request_handler("inspectVariables", std::bind(&debugger::inspect_variables_request, this, _1), false); register_request_handler("richInspectVariables", std::bind(&debugger::rich_inspect_variables_request, this, _1), false); @@ -67,7 +70,6 @@ namespace xpyt register_request_handler("configurationDone", std::bind(&debugger::configuration_done_request, this, _1), true); register_request_handler("copyToGlobals", std::bind(&debugger::copy_to_globals_request, this, _1), true); register_request_handler("modules", std::bind(&debugger::modules, this, _1), false); - } debugger::~debugger() @@ -176,6 +178,24 @@ namespace xpyt {"port", std::stoi(m_debugpy_port)} }; new_message["arguments"]["logToFile"] = true; + + // Add DebugStdLib when not just-my-code + if (!m_just_my_code) + { + new_message["arguments"]["debugOptions"] = {"DebugStdLib"}; + } + + // Dynamic skip rules + if (m_filter_internal_frames) + { + nl::json rules = nl::json::array(); + for (const auto& path : m_internal_modules) + { + rules.push_back({{"path", path}, {"include", false}}); + } + new_message["arguments"]["rules"] = rules; + } + return forward_message(new_message); } diff --git a/src/xinterpreter.cpp b/src/xinterpreter.cpp index ff210b2d..4fe2d99d 100644 --- a/src/xinterpreter.cpp +++ b/src/xinterpreter.cpp @@ -81,6 +81,21 @@ namespace xpyt instanciate_ipython_shell(); + py::dict modules = sys.attr("modules"); + std::vector internal_mod_paths; + internal_mod_paths.reserve(len(modules)); + + for (auto item : modules) + { + py::object mod = py::reinterpret_borrow(item.second); + if (py::hasattr(mod, "__file__")) + { + std::string path = mod.attr("__file__").cast(); + internal_mod_paths.push_back(path); + } + } + + m_ipython_shell_app.attr("initialize")(use_jedi_for_completion()); m_ipython_shell = m_ipython_shell_app.attr("shell"); diff --git a/src/xinterpreter_raw.cpp b/src/xinterpreter_raw.cpp index 0282f454..6ced62ce 100644 --- a/src/xinterpreter_raw.cpp +++ b/src/xinterpreter_raw.cpp @@ -71,6 +71,20 @@ namespace xpyt py::gil_scoped_acquire acquire; py::module sys = py::module::import("sys"); + + py::dict modules = sys.attr("modules"); + std::vector internal_mod_paths; + internal_mod_paths.reserve(py::len(modules)); + + for (auto item : modules) + { + py::object mod = py::reinterpret_borrow(item.second); + if (py::hasattr(mod, "__file__")) + { + std::string path = mod.attr("__file__").cast(); + internal_mod_paths.push_back(path); + } + } py::module jedi = py::module::import("jedi"); jedi.attr("api").attr("environment").attr("get_default_environment") = py::cpp_function([jedi]() { jedi.attr("api").attr("environment").attr("SameEnvironment")();