diff --git a/src/eval.rs b/src/eval.rs index 9b3c132..3c267d6 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -1,16 +1,17 @@ -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use anyhow::anyhow; use pyo3::exceptions::PyRuntimeError; use pyo3::intern; use pyo3::prelude::*; use pyo3::types::{PyDict, PyTuple}; +use starlark::codemap::ResolvedFileSpan; use starlark::environment::{FrozenModule, Module}; use starlark::errors::Frame; use starlark::eval::{CallStack, Evaluator, FileLoader, ProfileMode}; use starlark::PrintHandler; -use crate::codemap::PyFileSpan; +use crate::codemap::{PyFileSpan, PyResolvedFileSpan}; use crate::environment::{PyFrozenModule, PyGlobals, PyModule}; use crate::errors::PyFrame; use crate::syntax::PyAstModule; @@ -134,10 +135,22 @@ impl PyEvaluator { Ok(()) } - // TODO: enable_profile + fn enable_profile(&mut self, py: Python, mode: PyProfileMode) -> PyResult<()> { + self.ensure_module_available(py)?; + self.0.enable_profile(&mode.into())?; + Ok(()) + } + // TODO: write_profile // TODO: gen_profile - // TODO: coverage + + fn coverage(&self, py: Python) -> PyResult> { + self.ensure_module_available(py)?; + Ok(self + .0 + .coverage() + .map(|x| x.into_iter().map(ResolvedFileSpan::into).collect())?) + } fn enable_terminal_breakpoint_console(&mut self, py: Python) -> PyResult<()> { self.ensure_module_available(py)?; diff --git a/xingque.pyi b/xingque.pyi index 76bfe4c..17a200c 100644 --- a/xingque.pyi +++ b/xingque.pyi @@ -236,10 +236,10 @@ class Evaluator: def verbose_gc(self) -> None: ... def enable_static_typechecking(self, enable: bool) -> None: ... def set_loader(self, loader: _FileLoader) -> None: ... - # TODO: enable_profile + def enable_profile(self, mode: ProfileMode) -> None: ... # TODO: write_profile # TODO: gen_profile - # TODO: coverage + def coverage(self) -> set[ResolvedFileSpan]: ... def enable_terminal_breakpoint_console(self) -> None: ... def call_stack(self) -> CallStack: ... def call_stack_top_frame(self) -> Frame | None: ...