MCPcopy Create free account
hub / github.com/astral-sh/ruff / add_start

Method add_start

crates/ruff_python_formatter/src/string/docstring.rs:757–775  ·  view source on GitHub ↗

Looks for the start of a code example. If one was found, then the given line is kept and added as part of the code example. Otherwise, the line is pushed onto the queue unchanged to be printed as-is. # Panics This panics when the existing code-example is any non-None value. That is, this routine assumes that there is no ongoing code example being collected and looks for the beginning of another

(
        &mut self,
        original: InputDocstringLine<'src>,
        queue: &mut VecDeque<CodeExampleAddAction<'src>>,
    )

Source from the content-addressed store, hash-verified

755 /// is, this routine assumes that there is no ongoing code example being
756 /// collected and looks for the beginning of another code example.
757 fn add_start(
758 &mut self,
759 original: InputDocstringLine<'src>,
760 queue: &mut VecDeque<CodeExampleAddAction<'src>>,
761 ) {
762 assert!(self.kind.is_none(), "expected no existing code example");
763 if let Some(doctest) = CodeExampleDoctest::new(original) {
764 self.kind = Some(CodeExampleKind::Doctest(doctest));
765 queue.push_back(CodeExampleAddAction::Kept);
766 } else if let Some(litblock) = CodeExampleRst::new(original) {
767 self.kind = Some(CodeExampleKind::Rst(litblock));
768 queue.push_back(CodeExampleAddAction::Print { original });
769 } else if let Some(fenced) = CodeExampleMarkdown::new(original) {
770 self.kind = Some(CodeExampleKind::Markdown(fenced));
771 queue.push_back(CodeExampleAddAction::Print { original });
772 } else {
773 queue.push_back(CodeExampleAddAction::Print { original });
774 }
775 }
776}
777
778/// The kind of code example observed in a docstring.

Callers 4

formatFunction · 0.45
print_oneMethod · 0.45
addMethod · 0.45
parse_string_annotationFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected