class_docstr: Adaptor to provide IPython completions to prompt_toolkit
docstr: Private equivalent of get_completions() use only for unit_testing.
docstr_tok: ["Private","equivalent","of","get_completions","(",")","use","only","for","unit_testing","."]
code: def _get_completions(body, offset, cursor_position, ipyc):
      """
      Private equivalent of get_completions() use only for unit_testing.
      """
      debug = getattr(ipyc, "debug", False)
      completions = _deduplicate_completions(
          body, ipyc.completions(body, offset)
      )
      for c in completions:
          if not c.text:
              # Guard against completion machinery giving us an empty string.
              continue
          text = unicodedata.normalize("NFC", c.text)
          # 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(text[0]) == 0:
              if cursor_position + c.start > 0:
                  char_before = body[c.start - 1]
                  fixed_text = unicodedata.normalize(
                      "NFC", char_before + text
                  )
  
                  # Yield the modified completion instead, if this worked.
                  if wcwidth(text[0:1]) == 1:
                      yield Completion(
                          fixed_text,
                          start_position=c.start - offset - 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)
          display_text = c.text
  
          adjusted_text = _adjust_completion_text_based_on_context(
              c.text, body, offset
          )
          if c.type == "function":
              yield Completion(
                  adjusted_text,
                  start_position=c.start - offset,
                  display=_elide(
                      display_text + "()", body[c.start : c.end]
                  ),
                  display_meta=c.type + c.signature,
              )
          else:
              yield Completion(
                  adjusted_text,
                  start_position=c.start - offset,
                  display=_elide(display_text, body[c.start : c.end]),
                  display_meta=c.type,
              )
  
imports: import unicodedata
  from wcwidth import wcwidth
  from IPython.core.completer import provisionalcompleter, cursor_to_position, _deduplicate_completions
  from prompt_toolkit.completion import Completer, Completion
  from prompt_toolkit.lexers import Lexer
  from prompt_toolkit.lexers import PygmentsLexer
  from prompt_toolkit.patch_stdout import patch_stdout
  import pygments.lexers
  import os
  import sys
  import traceback
label_desc: Use image node_id 4 for calling the IPythonPTCompleter obj's underlying member method code with example usage: obj._get_completions(body, offset, cursor_position, ipyc) without return types