(
self,
text: str,
include_prefix: bool = True,
context: Optional[CompletionContext] = None,
)
| 1252 | return line |
| 1253 | |
| 1254 | def _attr_matches( |
| 1255 | self, |
| 1256 | text: str, |
| 1257 | include_prefix: bool = True, |
| 1258 | context: Optional[CompletionContext] = None, |
| 1259 | ) -> tuple[Sequence[str], str]: |
| 1260 | m2 = self._ATTR_MATCH_RE.match(text) |
| 1261 | if not m2: |
| 1262 | return [], "" |
| 1263 | expr, attr = m2.group(1, 2) |
| 1264 | try: |
| 1265 | expr = self._strip_code_before_operator(expr) |
| 1266 | except tokenize.TokenError: |
| 1267 | pass |
| 1268 | |
| 1269 | obj = self._evaluate_expr(expr) |
| 1270 | if obj is not_found: |
| 1271 | if context: |
| 1272 | # try to evaluate on full buffer |
| 1273 | previous_lines = "\n".join( |
| 1274 | context.full_text.split("\n")[: context.cursor_line] |
| 1275 | ) |
| 1276 | if previous_lines: |
| 1277 | all_code_lines_before_cursor = ( |
| 1278 | self._extract_code(previous_lines) + "\n" + expr |
| 1279 | ) |
| 1280 | obj = self._evaluate_expr(all_code_lines_before_cursor) |
| 1281 | |
| 1282 | if obj is not_found: |
| 1283 | return [], "" |
| 1284 | |
| 1285 | if self.limit_to__all__ and hasattr(obj, '__all__'): |
| 1286 | words = get__all__entries(obj) |
| 1287 | else: |
| 1288 | words = dir2(obj) |
| 1289 | |
| 1290 | try: |
| 1291 | words = generics.complete_object(obj, words) |
| 1292 | except TryNext: |
| 1293 | pass |
| 1294 | except AssertionError: |
| 1295 | raise |
| 1296 | except Exception: |
| 1297 | # Silence errors from completion function |
| 1298 | pass |
| 1299 | # Build match list to return |
| 1300 | n = len(attr) |
| 1301 | |
| 1302 | # Note: ideally we would just return words here and the prefix |
| 1303 | # reconciliator would know that we intend to append to rather than |
| 1304 | # replace the input text; this requires refactoring to return range |
| 1305 | # which ought to be replaced (as does jedi). |
| 1306 | if include_prefix: |
| 1307 | tokens = _parse_tokens(expr) |
| 1308 | rev_tokens = reversed(tokens) |
| 1309 | skip_over = {tokenize.ENDMARKER, tokenize.NEWLINE} |
| 1310 | name_turn = True |
| 1311 |
no test coverage detected