prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Autocomplete: don't display full path
  Using  `prompt_kit`, when completing a path such as `/var/log/<TAB>`, the autocompletion menu shows fully prefixed entries. The problem is that when the path is very deep, the autocomplete panel starts to give unreadable results (see attached screenshot).
  
  The proposed solution is to only display the `os.path.basename` of the autocompleted path, suffixed by `/` if it is a directory.
  
  ![screenshot from 2016-05-19 10-33-09](https://cloud.githubusercontent.com/assets/14598/15397392/1170b2b8-1dae-11e6-85b4-ea31504f9346.png)
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `xonsh/ptk/completer.py`
  Content:
  ```
  1 # -*- coding: utf-8 -*-
  2 """Completer implementation to use with prompt_toolkit."""
  3 import os
  4 import builtins
  5 
  6 from prompt_toolkit.layout.dimension import LayoutDimension
  7 from prompt_toolkit.completion import Completer, Completion
  8 
  9 
  10 class PromptToolkitCompleter(Completer):
  11     """Simple prompt_toolkit Completer object.
  12 
  13     It just redirects requests to normal Xonsh completer.
  14     """
  15 
  16     def __init__(self, completer, ctx):
  17         """Takes instance of xonsh.completer.Completer and dict with context."""
  18         self.completer = completer
  19         self.ctx = ctx
  20 
  21     def get_completions(self, document, complete_event):
  22         """Returns a generator for list of completions."""
  23 
  24         #  Only generate completions when the user hits tab.
  25         if complete_event.completion_requested:
  26             if self.completer is None:
  27                 yield from []
  28             else:
  29                 line = document.current_line.lstrip()
  30                 endidx = document.cursor_position_col
  31                 begidx = line[:endidx].rfind(' ') + 1 if line[:endidx].rfind(' ') >= 0 else 0
  32                 prefix = line[begidx:endidx]
  33                 line = builtins.aliases.expand_alias(line)
  34                 completions, l = self.completer.complete(prefix,
  35                                                          line,
  36                                                          begidx,
  37                                                          endidx,
  38                                                          self.ctx)
  39                 if len(completions) <= 1:
  40                     pass
  41                 elif len(os.path.commonprefix(completions)) <= len(prefix):
  42                     self.reserve_space()
  43                 for comp in completions:
  44                     yield Completion(comp, -l)
  45 
  46     def reserve_space(self):
  47         cli = builtins.__xonsh_shell__.shell.prompter.cli
  48         window = cli.application.layout.children[0].content.children[1]
  49 
  50         if window and window.render_info:
  51             h = window.render_info.content_height
  52             r = builtins.__xonsh_env__.get('COMPLETIONS_MENU_ROWS')
  53             size = h + r
  54 
  55             def comp_height(cli):
  56                 # If there is an autocompletion menu to be shown, make sure that o
  57                 # layout has at least a minimal height in order to display it.
  58                 if not cli.is_done:
  59                     return LayoutDimension(min=size)
  60                 else:
  61                     return LayoutDimension()
  62             window._height = comp_height
  63
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/xonsh/ptk/completer.py b/xonsh/ptk/completer.py
  --- a/xonsh/ptk/completer.py
  +++ b/xonsh/ptk/completer.py
  @@ -40,7 +40,11 @@
                       pass
                   elif len(os.path.commonprefix(completions)) <= len(prefix):
                       self.reserve_space()
  +                prefix, _, compprefix = prefix.rpartition('.')
                   for comp in completions:
  +                    if comp.rsplit('.', 1)[0] in prefix:
  +                        comp = comp.rsplit('.', 1)[-1]
  +                    l = len(compprefix) if compprefix in comp else 0
                       yield Completion(comp, -l)
   
       def reserve_space(self):
  
verification_info: {"golden_diff": "diff --git a/xonsh/ptk/completer.py b/xonsh/ptk/completer.py\n--- a/xonsh/ptk/completer.py\n+++ b/xonsh/ptk/completer.py\n@@ -40,7 +40,11 @@\n                     pass\n                 elif len(os.path.commonprefix(completions)) <= len(prefix):\n                     self.reserve_space()\n+                prefix, _, compprefix = prefix.rpartition('.')\n                 for comp in completions:\n+                    if comp.rsplit('.', 1)[0] in prefix:\n+                        comp = comp.rsplit('.', 1)[-1]\n+                    l = len(compprefix) if compprefix in comp else 0\n                     yield Completion(comp, -l)\n \n     def reserve_space(self):\n", "issue": "Autocomplete: don't display full path\nUsing  `prompt_kit`, when completing a path such as `/var/log/<TAB>`, the autocompletion menu shows fully prefixed entries. The problem is that when the path is very deep, the autocomplete panel starts to give unreadable results (see attached screenshot).\n\nThe proposed solution is to only display the `os.path.basename` of the autocompleted path, suffixed by `/` if it is a directory.\n\n![screenshot from 2016-05-19 10-33-09](https://cloud.githubusercontent.com/assets/14598/15397392/1170b2b8-1dae-11e6-85b4-ea31504f9346.png)\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"Completer implementation to use with prompt_toolkit.\"\"\"\nimport os\nimport builtins\n\nfrom prompt_toolkit.layout.dimension import LayoutDimension\nfrom prompt_toolkit.completion import Completer, Completion\n\n\nclass PromptToolkitCompleter(Completer):\n    \"\"\"Simple prompt_toolkit Completer object.\n\n    It just redirects requests to normal Xonsh completer.\n    \"\"\"\n\n    def __init__(self, completer, ctx):\n        \"\"\"Takes instance of xonsh.completer.Completer and dict with context.\"\"\"\n        self.completer = completer\n        self.ctx = ctx\n\n    def get_completions(self, document, complete_event):\n        \"\"\"Returns a generator for list of completions.\"\"\"\n\n        #  Only generate completions when the user hits tab.\n        if complete_event.completion_requested:\n            if self.completer is None:\n                yield from []\n            else:\n                line = document.current_line.lstrip()\n                endidx = document.cursor_position_col\n                begidx = line[:endidx].rfind(' ') + 1 if line[:endidx].rfind(' ') >= 0 else 0\n                prefix = line[begidx:endidx]\n                line = builtins.aliases.expand_alias(line)\n                completions, l = self.completer.complete(prefix,\n                                                         line,\n                                                         begidx,\n                                                         endidx,\n                                                         self.ctx)\n                if len(completions) <= 1:\n                    pass\n                elif len(os.path.commonprefix(completions)) <= len(prefix):\n                    self.reserve_space()\n                for comp in completions:\n                    yield Completion(comp, -l)\n\n    def reserve_space(self):\n        cli = builtins.__xonsh_shell__.shell.prompter.cli\n        window = cli.application.layout.children[0].content.children[1]\n\n        if window and window.render_info:\n            h = window.render_info.content_height\n            r = builtins.__xonsh_env__.get('COMPLETIONS_MENU_ROWS')\n            size = h + r\n\n            def comp_height(cli):\n                # If there is an autocompletion menu to be shown, make sure that o\n                # layout has at least a minimal height in order to display it.\n                if not cli.is_done:\n                    return LayoutDimension(min=size)\n                else:\n                    return LayoutDimension()\n            window._height = comp_height\n", "path": "xonsh/ptk/completer.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"Completer implementation to use with prompt_toolkit.\"\"\"\nimport os\nimport builtins\n\nfrom prompt_toolkit.layout.dimension import LayoutDimension\nfrom prompt_toolkit.completion import Completer, Completion\n\n\nclass PromptToolkitCompleter(Completer):\n    \"\"\"Simple prompt_toolkit Completer object.\n\n    It just redirects requests to normal Xonsh completer.\n    \"\"\"\n\n    def __init__(self, completer, ctx):\n        \"\"\"Takes instance of xonsh.completer.Completer and dict with context.\"\"\"\n        self.completer = completer\n        self.ctx = ctx\n\n    def get_completions(self, document, complete_event):\n        \"\"\"Returns a generator for list of completions.\"\"\"\n\n        #  Only generate completions when the user hits tab.\n        if complete_event.completion_requested:\n            if self.completer is None:\n                yield from []\n            else:\n                line = document.current_line.lstrip()\n                endidx = document.cursor_position_col\n                begidx = line[:endidx].rfind(' ') + 1 if line[:endidx].rfind(' ') >= 0 else 0\n                prefix = line[begidx:endidx]\n                line = builtins.aliases.expand_alias(line)\n                completions, l = self.completer.complete(prefix,\n                                                         line,\n                                                         begidx,\n                                                         endidx,\n                                                         self.ctx)\n                if len(completions) <= 1:\n                    pass\n                elif len(os.path.commonprefix(completions)) <= len(prefix):\n                    self.reserve_space()\n                prefix, _, compprefix = prefix.rpartition('.')\n                for comp in completions:\n                    if comp.rsplit('.', 1)[0] in prefix:\n                        comp = comp.rsplit('.', 1)[-1]\n                    l = len(compprefix) if compprefix in comp else 0\n                    yield Completion(comp, -l)\n\n    def reserve_space(self):\n        cli = builtins.__xonsh_shell__.shell.prompter.cli\n        window = cli.application.layout.children[0].content.children[1]\n\n        if window and window.render_info:\n            h = window.render_info.content_height\n            r = builtins.__xonsh_env__.get('COMPLETIONS_MENU_ROWS')\n            size = h + r\n\n            def comp_height(cli):\n                # If there is an autocompletion menu to be shown, make sure that o\n                # layout has at least a minimal height in order to display it.\n                if not cli.is_done:\n                    return LayoutDimension(min=size)\n                else:\n                    return LayoutDimension()\n            window._height = comp_height\n", "path": "xonsh/ptk/completer.py"}]}