From 48e696bbb4418e3c3c45ded4cc08e28850c06031 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Tue, 27 Jul 2021 18:49:55 +0200 Subject: [PATCH] Update commandline state before completion Fixes #8175. --- src/reader.cpp | 3 +++ tests/pexpects/commandline.py | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/reader.cpp b/src/reader.cpp index 78785d485..afee61526 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -3115,6 +3115,9 @@ void reader_data_t::handle_readline_command(readline_cmd_t c, readline_loop_stat // up to the end of the token we're completing. const wcstring buffcpy = wcstring(cmdsub_begin, token_end); + // Ensure that `commandline` inside the completions gets the current state. + update_commandline_state(); + // std::fwprintf(stderr, L"Complete (%ls)\n", buffcpy.c_str()); completion_request_flags_t complete_flags = {completion_request_t::descriptions, completion_request_t::fuzzy_match}; diff --git a/tests/pexpects/commandline.py b/tests/pexpects/commandline.py index 02941b30f..6d03f0da3 100644 --- a/tests/pexpects/commandline.py +++ b/tests/pexpects/commandline.py @@ -2,7 +2,7 @@ from pexpect_helper import SpawnedProc sp = SpawnedProc() -send, sendline, sleep, expect_prompt = sp.send, sp.sendline, sp.sleep, sp.expect_prompt +send, sendline, sleep, expect_prompt, expect_str = sp.send, sp.sendline, sp.sleep, sp.expect_prompt, sp.expect_str expect_prompt() sendline("bind '~' 'handle_tilde'") @@ -41,3 +41,9 @@ expect_prompt("<>") # TODO: consider removing. sendline("commandline -I foo") expect_prompt("foo") + +# See that the commandline is updated immediately inside completions. +sendline("complete -c foo -xa '(commandline)'") +expect_prompt() +send("foo bar \t") +expect_str("foo bar foo\ bar\ ")