| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2933,6 +2933,7 @@ def __init__(self, pid, sockfile, interrupt_script): | |||
| 2933 | 2933 | self.completion_matches = [] | |
| 2934 | 2934 | self.state = "dumb" | |
| 2935 | 2935 | self.write_failed = False | |
| 2936 | + self.multiline_block = False | ||
| 2936 | 2937 | ||
| 2937 | 2938 | def _ensure_valid_message(self, msg): | |
| 2938 | 2939 | # Ensure the message conforms to our protocol. | |
@@ -2979,6 +2980,7 @@ def _send(self, **kwargs): | |||
| 2979 | 2980 | self.write_failed = True | |
| 2980 | 2981 | ||
| 2981 | 2982 | def read_command(self, prompt): | |
| 2983 | + self.multiline_block = False | ||
| 2982 | 2984 | reply = input(prompt) | |
| 2983 | 2985 | ||
| 2984 | 2986 | if self.state == "dumb": | |
@@ -3003,6 +3005,7 @@ def read_command(self, prompt): | |||
| 3003 | 3005 | return prefix + reply | |
| 3004 | 3006 | ||
| 3005 | 3007 | # Otherwise, valid first line of a multi-line statement | |
| 3008 | + self.multiline_block = True | ||
| 3006 | 3009 | continue_prompt = "...".ljust(len(prompt)) | |
| 3007 | 3010 | while codeop.compile_command(reply, "<stdin>", "single") is None: | |
| 3008 | 3011 | reply += "\n" + input(continue_prompt) | |
@@ -3105,9 +3108,13 @@ def complete(self, text, state): | |||
| 3105 | 3108 | ||
| 3106 | 3109 | origline = readline.get_line_buffer() | |
| 3107 | 3110 | line = origline.lstrip() | |
| 3108 | - stripped = len(origline) - len(line) | ||
| 3109 | - begidx = readline.get_begidx() - stripped | ||
| 3110 | - endidx = readline.get_endidx() - stripped | ||
| 3111 | + if self.multiline_block: | ||
| 3112 | + # We're completing a line contained in a multi-line block. | ||
| 3113 | + # Force the remote to treat it as a Python expression. | ||
| 3114 | + line = "! " + line | ||
| 3115 | + offset = len(origline) - len(line) | ||
| 3116 | + begidx = readline.get_begidx() - offset | ||
| 3117 | + endidx = readline.get_endidx() - offset | ||
| 3111 | 3118 | ||
| 3112 | 3119 | msg = { | |
| 3113 | 3120 | "complete": { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -531,6 +531,44 @@ def test_completion_in_pdb_state(self): | |||
| 531 | 531 | expected_state={"state": "pdb"}, | |
| 532 | 532 | ) | |
| 533 | 533 | ||
| 534 | + def test_multiline_completion_in_pdb_state(self): | ||
| 535 | + """Test requesting tab completions at a (Pdb) continuation prompt.""" | ||
| 536 | + # GIVEN | ||
| 537 | + incoming = [ | ||
| 538 | + ("server", {"prompt": "(Pdb) ", "state": "pdb"}), | ||
| 539 | + ("user", {"prompt": "(Pdb) ", "input": "if True:"}), | ||
| 540 | + ( | ||
| 541 | + "user", | ||
| 542 | + { | ||
| 543 | + "prompt": "... ", | ||
| 544 | + "completion_request": { | ||
| 545 | + "line": " b", | ||
| 546 | + "begidx": 4, | ||
| 547 | + "endidx": 5, | ||
| 548 | + }, | ||
| 549 | + "input": " bool()", | ||
| 550 | + }, | ||
| 551 | + ), | ||
| 552 | + ("server", {"completions": ["bin", "bool", "bytes"]}), | ||
| 553 | + ("user", {"prompt": "... ", "input": ""}), | ||
| 554 | + ] | ||
| 555 | + self.do_test( | ||
| 556 | + incoming=incoming, | ||
| 557 | + expected_outgoing=[ | ||
| 558 | + { | ||
| 559 | + "complete": { | ||
| 560 | + "text": "b", | ||
| 561 | + "line": "! b", | ||
| 562 | + "begidx": 2, | ||
| 563 | + "endidx": 3, | ||
| 564 | + } | ||
| 565 | + }, | ||
| 566 | + {"reply": "if True:\n bool()\n"}, | ||
| 567 | + ], | ||
| 568 | + expected_completions=["bin", "bool", "bytes"], | ||
| 569 | + expected_state={"state": "pdb"}, | ||
| 570 | + ) | ||
| 571 | + | ||
| 534 | 572 | def test_completion_in_interact_state(self): | |
| 535 | 573 | """Test requesting tab completions at a >>> prompt.""" | |
| 536 | 574 | incoming = [ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + Fix remote PDB to correctly request tab completions for Python expressions | ||
| 2 | + from the server when completing a continuation line of a multi-line Python | ||
| 3 | + block. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments