MCPcopy Create free account
hub / github.com/LaBatata101/sith-language-server / get_python_doc

Function get_python_doc

crates/sith_python_utils/src/lib.rs:42–70  ·  view source on GitHub ↗
(
    interpreter_path: impl AsRef<Path>,
    search_term: &str,
)

Source from the content-addressed store, hash-verified

40}
41
42pub fn get_python_doc(
43 interpreter_path: impl AsRef<Path>,
44 search_term: &str,
45) -> anyhow::Result<Option<String>> {
46 let output = Command::new(interpreter_path.as_ref())
47 .args([
48 "-c",
49 [
50 "import pydoc",
51 "pydoc.pager=pydoc.plainpager",
52 &format!("pydoc.help('{search_term}')"),
53 ]
54 .join(";")
55 .as_str(),
56 ])
57 .stdout(Stdio::piped())
58 .output()
59 .map_err(|e| anyhow::anyhow!("Failed to get python documentation! {e}"))?;
60
61 let output_str = String::from_utf8_lossy(&output.stdout);
62 if output_str.starts_with("No Python documentation found for") {
63 Ok(None)
64 } else {
65 Ok(Some(
66 // Skip the line with "Help on ..."
67 output_str.lines().skip(1).collect::<Vec<&str>>().join("\n"),
68 ))
69 }
70}
71
72pub fn get_python_version(interpreter_path: impl AsRef<Path>) -> anyhow::Result<PythonVersion> {
73 let output = Command::new(interpreter_path.as_ref())

Callers 3

hoverFunction · 0.85
get_doc_strFunction · 0.85

Calls 5

joinMethod · 0.80
starts_withMethod · 0.80
linesMethod · 0.80
as_refMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected