Extract a docstring from this definition, if applicable. This method returns a docstring for function, class, and attribute definitions. The docstring is extracted from the first statement in the body if it's a string literal.
(self, db: &'db dyn Db)
| 141 | /// This method returns a docstring for function, class, and attribute definitions. |
| 142 | /// The docstring is extracted from the first statement in the body if it's a string literal. |
| 143 | pub fn docstring(self, db: &'db dyn Db) -> Option<String> { |
| 144 | let file = self.file(db); |
| 145 | let module = parsed_module(db, file).load(db); |
| 146 | let kind = self.kind(db); |
| 147 | |
| 148 | match kind { |
| 149 | DefinitionKind::Assignment(assign_def) => { |
| 150 | let assign_node = assign_def.target(&module); |
| 151 | attribute_docstring(&module, assign_node) |
| 152 | .map(|docstring_expr| docstring_expr.value.to_str().to_owned()) |
| 153 | } |
| 154 | DefinitionKind::AnnotatedAssignment(assign_def) => { |
| 155 | let assign_node = assign_def.target(&module); |
| 156 | attribute_docstring(&module, assign_node) |
| 157 | .map(|docstring_expr| docstring_expr.value.to_str().to_owned()) |
| 158 | } |
| 159 | DefinitionKind::Function(function_def) => { |
| 160 | let function_node = function_def.node(&module); |
| 161 | docstring_from_body(&function_node.body) |
| 162 | .map(|docstring_expr| docstring_expr.value.to_str().to_owned()) |
| 163 | } |
| 164 | DefinitionKind::Class(class_def) => { |
| 165 | let class_node = class_def.node(&module); |
| 166 | docstring_from_body(&class_node.body) |
| 167 | .map(|docstring_expr| docstring_expr.value.to_str().to_owned()) |
| 168 | } |
| 169 | _ => None, |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | /// The identity of the place defined by a [`Definition`] and whether it is re-exported. |
nothing calls this directly
no test coverage detected