mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
gh-133351: Fix remote PDB's multi-line block tab completion (#133387)
This commit is contained in:
parent
61b50a98b4
commit
d8c118f50d
3 changed files with 51 additions and 3 deletions
13
Lib/pdb.py
13
Lib/pdb.py
|
@ -2933,6 +2933,7 @@ class _PdbClient:
|
||||||
self.completion_matches = []
|
self.completion_matches = []
|
||||||
self.state = "dumb"
|
self.state = "dumb"
|
||||||
self.write_failed = False
|
self.write_failed = False
|
||||||
|
self.multiline_block = False
|
||||||
|
|
||||||
def _ensure_valid_message(self, msg):
|
def _ensure_valid_message(self, msg):
|
||||||
# Ensure the message conforms to our protocol.
|
# Ensure the message conforms to our protocol.
|
||||||
|
@ -2979,6 +2980,7 @@ class _PdbClient:
|
||||||
self.write_failed = True
|
self.write_failed = True
|
||||||
|
|
||||||
def read_command(self, prompt):
|
def read_command(self, prompt):
|
||||||
|
self.multiline_block = False
|
||||||
reply = input(prompt)
|
reply = input(prompt)
|
||||||
|
|
||||||
if self.state == "dumb":
|
if self.state == "dumb":
|
||||||
|
@ -3003,6 +3005,7 @@ class _PdbClient:
|
||||||
return prefix + reply
|
return prefix + reply
|
||||||
|
|
||||||
# Otherwise, valid first line of a multi-line statement
|
# Otherwise, valid first line of a multi-line statement
|
||||||
|
self.multiline_block = True
|
||||||
continue_prompt = "...".ljust(len(prompt))
|
continue_prompt = "...".ljust(len(prompt))
|
||||||
while codeop.compile_command(reply, "<stdin>", "single") is None:
|
while codeop.compile_command(reply, "<stdin>", "single") is None:
|
||||||
reply += "\n" + input(continue_prompt)
|
reply += "\n" + input(continue_prompt)
|
||||||
|
@ -3105,9 +3108,13 @@ class _PdbClient:
|
||||||
|
|
||||||
origline = readline.get_line_buffer()
|
origline = readline.get_line_buffer()
|
||||||
line = origline.lstrip()
|
line = origline.lstrip()
|
||||||
stripped = len(origline) - len(line)
|
if self.multiline_block:
|
||||||
begidx = readline.get_begidx() - stripped
|
# We're completing a line contained in a multi-line block.
|
||||||
endidx = readline.get_endidx() - stripped
|
# Force the remote to treat it as a Python expression.
|
||||||
|
line = "! " + line
|
||||||
|
offset = len(origline) - len(line)
|
||||||
|
begidx = readline.get_begidx() - offset
|
||||||
|
endidx = readline.get_endidx() - offset
|
||||||
|
|
||||||
msg = {
|
msg = {
|
||||||
"complete": {
|
"complete": {
|
||||||
|
|
|
@ -531,6 +531,44 @@ class PdbClientTestCase(unittest.TestCase):
|
||||||
expected_state={"state": "pdb"},
|
expected_state={"state": "pdb"},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_multiline_completion_in_pdb_state(self):
|
||||||
|
"""Test requesting tab completions at a (Pdb) continuation prompt."""
|
||||||
|
# GIVEN
|
||||||
|
incoming = [
|
||||||
|
("server", {"prompt": "(Pdb) ", "state": "pdb"}),
|
||||||
|
("user", {"prompt": "(Pdb) ", "input": "if True:"}),
|
||||||
|
(
|
||||||
|
"user",
|
||||||
|
{
|
||||||
|
"prompt": "... ",
|
||||||
|
"completion_request": {
|
||||||
|
"line": " b",
|
||||||
|
"begidx": 4,
|
||||||
|
"endidx": 5,
|
||||||
|
},
|
||||||
|
"input": " bool()",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
("server", {"completions": ["bin", "bool", "bytes"]}),
|
||||||
|
("user", {"prompt": "... ", "input": ""}),
|
||||||
|
]
|
||||||
|
self.do_test(
|
||||||
|
incoming=incoming,
|
||||||
|
expected_outgoing=[
|
||||||
|
{
|
||||||
|
"complete": {
|
||||||
|
"text": "b",
|
||||||
|
"line": "! b",
|
||||||
|
"begidx": 2,
|
||||||
|
"endidx": 3,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{"reply": "if True:\n bool()\n"},
|
||||||
|
],
|
||||||
|
expected_completions=["bin", "bool", "bytes"],
|
||||||
|
expected_state={"state": "pdb"},
|
||||||
|
)
|
||||||
|
|
||||||
def test_completion_in_interact_state(self):
|
def test_completion_in_interact_state(self):
|
||||||
"""Test requesting tab completions at a >>> prompt."""
|
"""Test requesting tab completions at a >>> prompt."""
|
||||||
incoming = [
|
incoming = [
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
Fix remote PDB to correctly request tab completions for Python expressions
|
||||||
|
from the server when completing a continuation line of a multi-line Python
|
||||||
|
block.
|
Loading…
Add table
Add a link
Reference in a new issue