Match named parameters (kwargs) of the last open function
(self,text)
| 1488 | return list(set(ret)) |
| 1489 | |
| 1490 | def python_func_kw_matches(self,text): |
| 1491 | """Match named parameters (kwargs) of the last open function""" |
| 1492 | |
| 1493 | if "." in text: # a parameter cannot be dotted |
| 1494 | return [] |
| 1495 | try: regexp = self.__funcParamsRegex |
| 1496 | except AttributeError: |
| 1497 | regexp = self.__funcParamsRegex = re.compile(r''' |
| 1498 | '.*?(?<!\\)' | # single quoted strings or |
| 1499 | ".*?(?<!\\)" | # double quoted strings or |
| 1500 | \w+ | # identifier |
| 1501 | \S # other characters |
| 1502 | ''', re.VERBOSE | re.DOTALL) |
| 1503 | # 1. find the nearest identifier that comes before an unclosed |
| 1504 | # parenthesis before the cursor |
| 1505 | # e.g. for "foo (1+bar(x), pa<cursor>,a=1)", the candidate is "foo" |
| 1506 | tokens = regexp.findall(self.text_until_cursor) |
| 1507 | iterTokens = reversed(tokens); openPar = 0 |
| 1508 | |
| 1509 | for token in iterTokens: |
| 1510 | if token == ')': |
| 1511 | openPar -= 1 |
| 1512 | elif token == '(': |
| 1513 | openPar += 1 |
| 1514 | if openPar > 0: |
| 1515 | # found the last unclosed parenthesis |
| 1516 | break |
| 1517 | else: |
| 1518 | return [] |
| 1519 | # 2. Concatenate dotted names ("foo.bar" for "foo.bar(x, pa" ) |
| 1520 | ids = [] |
| 1521 | isId = re.compile(r'\w+$').match |
| 1522 | |
| 1523 | while True: |
| 1524 | try: |
| 1525 | ids.append(next(iterTokens)) |
| 1526 | if not isId(ids[-1]): |
| 1527 | ids.pop(); break |
| 1528 | if not next(iterTokens) == '.': |
| 1529 | break |
| 1530 | except StopIteration: |
| 1531 | break |
| 1532 | |
| 1533 | # Find all named arguments already assigned to, as to avoid suggesting |
| 1534 | # them again |
| 1535 | usedNamedArgs = set() |
| 1536 | par_level = -1 |
| 1537 | for token, next_token in zip(tokens, tokens[1:]): |
| 1538 | if token == '(': |
| 1539 | par_level += 1 |
| 1540 | elif token == ')': |
| 1541 | par_level -= 1 |
| 1542 | |
| 1543 | if par_level != 0: |
| 1544 | continue |
| 1545 | |
| 1546 | if next_token != '=': |
| 1547 | continue |
nothing calls this directly
no test coverage detected