| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9f45c32 commit f16a248
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -335,6 +335,44 @@ def list_attributes(self, obj): | |||
| 335 | 335 | return dir(obj) | |
| 336 | 336 | ||
| 337 | 337 | ||
| 338 | + class ArrayObjectMembersCompletion(BaseCompletionType): | ||
| 339 | + | ||
| 340 | + def __init__(self, shown_before_tab=True, mode=SIMPLE): | ||
| 341 | + self._shown_before_tab = shown_before_tab | ||
| 342 | + self.completer = AttrCompletion(mode=mode) | ||
| 343 | + | ||
| 344 | + def matches(self, cursor_offset, line, **kwargs): | ||
| 345 | + if 'locals_' not in kwargs: | ||
| 346 | + return None | ||
| 347 | + locals_ = kwargs['locals_'] | ||
| 348 | + | ||
| 349 | + r = self.locate(cursor_offset, line) | ||
| 350 | + if r is None: | ||
| 351 | + return None | ||
| 352 | + member_part = r[2] | ||
| 353 | + _, _, dexpr = lineparts.current_array_with_indexer(cursor_offset, line) | ||
| 354 | + try: | ||
| 355 | + locals_['temp_val_from_array'] = safe_eval(dexpr, locals_) | ||
| 356 | + except (EvaluationError, IndexError): | ||
| 357 | + return set() | ||
| 358 | + | ||
| 359 | + temp_line = line.replace(member_part, 'temp_val_from_array.') | ||
| 360 | + | ||
| 361 | + matches = self.completer.matches(len(temp_line), temp_line, **kwargs) | ||
| 362 | + matches_with_correct_name = \ | ||
| 363 | + set(match.replace('temp_val_from_array.', member_part) for match in matches) | ||
| 364 | + | ||
| 365 | + del locals_['temp_val_from_array'] | ||
| 366 | + | ||
| 367 | + return matches_with_correct_name | ||
| 368 | + | ||
| 369 | + def locate(self, current_offset, line): | ||
| 370 | + return lineparts.current_array_item_member_name(current_offset, line) | ||
| 371 | + | ||
| 372 | + def format(self, match): | ||
| 373 | + return after_last_dot(match) | ||
| 374 | + | ||
| 375 | + | ||
| 338 | 376 | class DictKeyCompletion(BaseCompletionType): | |
| 339 | 377 | ||
| 340 | 378 | def matches(self, cursor_offset, line, **kwargs): | |
@@ -565,6 +603,7 @@ def get_default_completer(mode=SIMPLE): | |||
| 565 | 603 | MagicMethodCompletion(mode=mode), | |
| 566 | 604 | MultilineJediCompletion(mode=mode), | |
| 567 | 605 | GlobalCompletion(mode=mode), | |
| 606 | + ArrayObjectMembersCompletion(mode=mode), | ||
| 568 | 607 | CumulativeCompleter((AttrCompletion(mode=mode), | |
| 569 | 608 | ParameterNameCompletion(mode=mode)), | |
| 570 | 609 | mode=mode) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -226,3 +226,27 @@ def current_string_literal_attr(cursor_offset, line): | |||
| 226 | 226 | if m.start(4) <= cursor_offset and m.end(4) >= cursor_offset: | |
| 227 | 227 | return LinePart(m.start(4), m.end(4), m.group(4)) | |
| 228 | 228 | return None | |
| 229 | + | ||
| 230 | + | ||
| 231 | + current_array_with_indexer_re = LazyReCompile( | ||
| 232 | + r'''([\w_][\w0-9._]*\[[a-zA-Z0-9_"']+\])\.(.*)''') | ||
| 233 | + | ||
| 234 | + | ||
| 235 | + def current_array_with_indexer(cursor_offset, line): | ||
| 236 | + """an array and indexer, e.g. foo[1]""" | ||
| 237 | + matches = current_array_with_indexer_re.finditer(line) | ||
| 238 | + for m in matches: | ||
| 239 | + if m.start(1) <= cursor_offset and m.end(1) <= cursor_offset: | ||
| 240 | + return LinePart(m.start(1), m.end(1), m.group(1)) | ||
| 241 | + | ||
| 242 | + | ||
| 243 | + current_array_item_member_name_re = LazyReCompile( | ||
| 244 | + r'''([\w_][\w0-9._]*\[[a-zA-Z0-9_"']+\]\.)(.*)''') | ||
| 245 | + | ||
| 246 | + | ||
| 247 | + def current_array_item_member_name(cursor_offset, line): | ||
| 248 | + """the member name after an array indexer, e.g. foo[1].bar""" | ||
| 249 | + matches = current_array_item_member_name_re.finditer(line) | ||
| 250 | + for m in matches: | ||
| 251 | + if m.start(2) <= cursor_offset and m.end(2) >= cursor_offset: | ||
| 252 | + return LinePart(m.start(1), m.end(2), m.group(1)) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments