We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
COMPLETIONS_MENU_ROWS not working
Hello

My value for `COMPLETIONS_MENU_ROWS` is 5 (default). But it does not seem to work. My terminal grow until the bottom of the window and when it has reached the last line then I don't get completions anymore.

I use gnome-terminal on Ubuntu 14.04

Thank you for your help !

EDIT: I installed HEAD from the git repo. I still have the problem

EDIT2+3: I also have the problem with xtrem and Terminator (It seems Terminal independant)


--- 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             line = document.current_line.lstrip()
27             endidx = document.cursor_position_col
28             begidx = line[:endidx].rfind(' ') + 1 if line[:endidx].rfind(' ') >= 0 else 0
29             prefix = line[begidx:endidx]
30             completions, l = self.completer.complete(prefix,
31                                                      line,
32                                                      begidx,
33                                                      endidx,
34                                                      self.ctx)
35             if len(completions) <= 1:
36                 pass
37             elif len(os.path.commonprefix(completions)) <= len(prefix):
38                 self.reserve_space()
39             for comp in completions:
40                 yield Completion(comp, -l)
41 
42     def reserve_space(self):
43         cli = builtins.__xonsh_shell__.shell.prompter.cli
44         #TODO remove after next prompt_toolkit release
45         try:
46             #old layout to be removed at next ptk release
47             window = cli.application.layout.children[1].children[1].content
48         except AttributeError:
49             #new layout to become default
50             window = cli.application.layout.children[1].content
51         if window and window.render_info:
52             h = window.render_info.content_height
53             r = builtins.__xonsh_env__.get('COMPLETIONS_MENU_ROWS')
54             size = h + r
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()

```

diff --git a/xonsh/ptk/completer.py b/xonsh/ptk/completer.py
--- a/xonsh/ptk/completer.py
+++ b/xonsh/ptk/completer.py
@@ -2,6 +2,7 @@
 """Completer implementation to use with prompt_toolkit."""
 import os
 import builtins
+import xonsh.shell
 
 from prompt_toolkit.layout.dimension import LayoutDimension
 from prompt_toolkit.completion import Completer, Completion
@@ -41,13 +42,18 @@
 
     def reserve_space(self):
         cli = builtins.__xonsh_shell__.shell.prompter.cli
-        #TODO remove after next prompt_toolkit release
-        try:
-            #old layout to be removed at next ptk release
-            window = cli.application.layout.children[1].children[1].content
-        except AttributeError:
-            #new layout to become default
-            window = cli.application.layout.children[1].content
+        if xonsh.shell.prompt_toolkit_version().startswith("1.0"):
+            # This is the layout for ptk 1.0
+            window = cli.application.layout.children[0].content.children[1]
+        else:
+            #TODO remove after next prompt_toolkit release
+            try:
+                #old layout to be removed at next ptk release
+                window = cli.application.layout.children[1].children[1].content
+            except AttributeError:
+                #new layout to become default
+                window = cli.application.layout.children[1].content
+
         if window and window.render_info:
             h = window.render_info.content_height
             r = builtins.__xonsh_env__.get('COMPLETIONS_MENU_ROWS')

{"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@@ -2,6 +2,7 @@\n \"\"\"Completer implementation to use with prompt_toolkit.\"\"\"\n import os\n import builtins\n+import xonsh.shell\n \n from prompt_toolkit.layout.dimension import LayoutDimension\n from prompt_toolkit.completion import Completer, Completion\n@@ -41,13 +42,18 @@\n \n     def reserve_space(self):\n         cli = builtins.__xonsh_shell__.shell.prompter.cli\n-        #TODO remove after next prompt_toolkit release\n-        try:\n-            #old layout to be removed at next ptk release\n-            window = cli.application.layout.children[1].children[1].content\n-        except AttributeError:\n-            #new layout to become default\n-            window = cli.application.layout.children[1].content\n+        if xonsh.shell.prompt_toolkit_version().startswith(\"1.0\"):\n+            # This is the layout for ptk 1.0\n+            window = cli.application.layout.children[0].content.children[1]\n+        else:\n+            #TODO remove after next prompt_toolkit release\n+            try:\n+                #old layout to be removed at next ptk release\n+                window = cli.application.layout.children[1].children[1].content\n+            except AttributeError:\n+                #new layout to become default\n+                window = cli.application.layout.children[1].content\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", "issue": "COMPLETIONS_MENU_ROWS not working\nHello\n\nMy value for `COMPLETIONS_MENU_ROWS` is 5 (default). But it does not seem to work. My terminal grow until the bottom of the window and when it has reached the last line then I don't get completions anymore.\n\nI use gnome-terminal on Ubuntu 14.04\n\nThank you for your help !\n\nEDIT: I installed HEAD from the git repo. I still have the problem\n\nEDIT2+3: I also have the problem with xtrem and Terminator (It seems Terminal independant)\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            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            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        #TODO remove after next prompt_toolkit release\n        try:\n            #old layout to be removed at next ptk release\n            window = cli.application.layout.children[1].children[1].content\n        except AttributeError:\n            #new layout to become default\n            window = cli.application.layout.children[1].content\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            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\nimport xonsh.shell\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            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            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        if xonsh.shell.prompt_toolkit_version().startswith(\"1.0\"):\n            # This is the layout for ptk 1.0\n            window = cli.application.layout.children[0].content.children[1]\n        else:\n            #TODO remove after next prompt_toolkit release\n            try:\n                #old layout to be removed at next ptk release\n                window = cli.application.layout.children[1].children[1].content\n            except AttributeError:\n                #new layout to become default\n                window = cli.application.layout.children[1].content\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            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"}]}