MCPcopy Create free account
hub / github.com/ipython/ipython / _jedi_matches

Method _jedi_matches

IPython/core/completer.py:1333–1406  ·  view source on GitHub ↗

Return a list of :any:`jedi.api.Completions` object from a ``text`` and cursor position. Parameters ---------- cursor_column : int column position of the cursor in ``text``, 0-indexed. cursor_line : int line position of the c

(self, cursor_column:int, cursor_line:int, text:str)

Source from the content-addressed store, hash-verified

1331 return []
1332
1333 def _jedi_matches(self, cursor_column:int, cursor_line:int, text:str):
1334 """
1335
1336 Return a list of :any:`jedi.api.Completions` object from a ``text`` and
1337 cursor position.
1338
1339 Parameters
1340 ----------
1341 cursor_column : int
1342 column position of the cursor in ``text``, 0-indexed.
1343 cursor_line : int
1344 line position of the cursor in ``text``, 0-indexed
1345 text : str
1346 text to complete
1347
1348 Debugging
1349 ---------
1350
1351 If ``IPCompleter.debug`` is ``True`` may return a :any:`_FakeJediCompletion`
1352 object containing a string with the Jedi debug information attached.
1353 """
1354 namespaces = [self.namespace]
1355 if self.global_namespace is not None:
1356 namespaces.append(self.global_namespace)
1357
1358 completion_filter = lambda x:x
1359 offset = cursor_to_position(text, cursor_line, cursor_column)
1360 # filter output if we are completing for object members
1361 if offset:
1362 pre = text[offset-1]
1363 if pre == '.':
1364 if self.omit__names == 2:
1365 completion_filter = lambda c:not c.name.startswith('_')
1366 elif self.omit__names == 1:
1367 completion_filter = lambda c:not (c.name.startswith('__') and c.name.endswith('__'))
1368 elif self.omit__names == 0:
1369 completion_filter = lambda x:x
1370 else:
1371 raise ValueError("Don't understand self.omit__names == {}".format(self.omit__names))
1372
1373 interpreter = jedi.Interpreter(
1374 text[:offset], namespaces, column=cursor_column, line=cursor_line + 1)
1375 try_jedi = True
1376
1377 try:
1378 # find the first token in the current tree -- if it is a ' or " then we are in a string
1379 completing_string = False
1380 try:
1381 first_child = next(c for c in interpreter._get_module().tree_node.children if hasattr(c, 'value'))
1382 except StopIteration:
1383 pass
1384 else:
1385 # note the value may be ', ", or it may also be ''' or """, or
1386 # in some cases, """what/you/typed..., but all of these are
1387 # strings.
1388 completing_string = len(first_child.value) > 0 and first_child.value[0] in {"'", '"'}
1389
1390 # if we are in a string jedi is likely not the right candidate for

Callers 1

_completeMethod · 0.95

Calls 4

cursor_to_positionFunction · 0.85
_FakeJediCompletionClass · 0.85
completionsMethod · 0.80
formatMethod · 0.45

Tested by

no test coverage detected