class_docstr: Adaptor to provide IPython completions to prompt_toolkit
class_docstr_tok: ["Adaptor","to","provide","IPython","completions","to","prompt_toolkit"]
code: def get_completions(self, document, complete_event):
      if not document.current_line.strip():
          return
  
      # Some bits of our completion system may print stuff (e.g. if a module
      # is imported). This context manager ensures that doesn't interfere with
      # the prompt.
      with self.patch_stdout():
          used, matches = self.ipy_completer.complete(
              line_buffer=document.current_line,
              cursor_pos=document.cursor_position_col,
          )
      start_pos = -len(used)
      for m in matches:
          if not m:
              # Guard against completion machinery giving us an empty string.
              continue
  
          m = unicodedata.normalize("NFC", m)
  
          # When the first character of the completion has a zero length,
          # then it's probably a decomposed unicode character. E.g. caused by
          # the "\dot" completion. Try to compose again with the previous
          # character.
          if wcwidth(m[0]) == 0:
              if document.cursor_position + start_pos > 0:
                  char_before = document.text[
                      document.cursor_position + start_pos - 1
                  ]
                  m = unicodedata.normalize("NFC", char_before + m)
  
                  # Yield the modified completion instead, if this worked.
                  if wcwidth(m[0:1]) == 1:
                      yield Completion(m, start_position=start_pos - 1)
                      continue
  
          # TODO: Use Jedi to determine meta_text
          # (Jedi currently has a bug that results in incorrect information.)
          # meta_text = ''
          # yield Completion(m, start_position=start_pos,
          #                  display_meta=meta_text)
          yield Completion(m, start_position=start_pos)
  
file_path: catboost/contrib/python/ipython/py2/IPython/terminal/ptutils.py
imports: import unicodedata
  from wcwidth import wcwidth
  from IPython.utils.py3compat import PY3
  from IPython.core.completer import IPCompleter
  from prompt_toolkit.completion import Completer, Completion
  from prompt_toolkit.layout.lexers import Lexer
  from prompt_toolkit.layout.lexers import PygmentsLexer
  import pygments.lexers
label_desc: Use image node_id 3 for calling the IPythonPTCompleter obj's underlying member method code with example usage: obj.get_completions(document, complete_event) without return types