[Lldb-commits] [PATCH] D76906: [lldb] Fixing the bug that the "log timer" has no tab completion
gedatsu217 added a comment. [39/575] Linking CXX shared library lib/libc++abi.1.0.dylib FAILED: lib/libc++abi.1.0.dylib : && /Library/Developer/CommandLineTools/usr/bin/c++ -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wstring-conversion -fdiagnostics-color -g -dynamiclib -Wl,-headerpad_max_install_names -nodefaultlibs -compatibility_version 1.0.0 -current_version 1.0.0 -o lib/libc++abi.1.0.dylib -install_name @rpath/libc++abi.1.dylib projects/libcxxabi/src/CMakeFiles/cxxabi_shared.dir/cxa_aux_runtime.cpp.o projects/libcxxabi/src/CMakeFiles/cxxabi_shared.dir/cxa_default_handlers.cpp.o projects/libcxxabi/src/CMakeFiles/cxxabi_shared.dir/cxa_demangle.cpp.o projects/libcxxabi/src/CMakeFiles/cxxabi_shared.dir/cxa_exception_storage.cpp.o projects/libcxxabi/src/CMakeFiles/cxxabi_shared.dir/cxa_guard.cpp.o projects/libcxxabi/src/CMakeFiles/cxxabi_shared.dir/cxa_handlers.cpp.o projects/libcxxabi/src/CMakeFiles/cxxabi_shared.dir/cxa_unexpected.cpp.o projects/libcxxabi/src/CMakeFiles/cxxabi_shared.dir/cxa_vector.cpp.o projects/libcxxabi/src/CMakeFiles/cxxabi_shared.dir/cxa_virtual.cpp.o projects/libcxxabi/src/CMakeFiles/cxxabi_shared.dir/stdlib_exception.cpp.o projects/libcxxabi/src/CMakeFiles/cxxabi_shared.dir/stdlib_stdexcept.cpp.o projects/libcxxabi/src/CMakeFiles/cxxabi_shared.dir/stdlib_typeinfo.cpp.o projects/libcxxabi/src/CMakeFiles/cxxabi_shared.dir/abort_message.cpp.o projects/libcxxabi/src/CMakeFiles/cxxabi_shared.dir/fallback_malloc.cpp.o projects/libcxxabi/src/CMakeFiles/cxxabi_shared.dir/private_typeinfo.cpp.o projects/libcxxabi/src/CMakeFiles/cxxabi_shared.dir/stdlib_new_delete.cpp.o projects/libcxxabi/src/CMakeFiles/cxxabi_shared.dir/cxa_exception.cpp.o projects/libcxxabi/src/CMakeFiles/cxxabi_shared.dir/cxa_personality.cpp.o -Wl,-rpath,@loader_path/../lib -lSystem -Wl,-exported_symbols_list,/Users/shu/Documents/llvm-project/libcxxabi/src/../lib/itanium-base.exp -Wl,-exported_symbols_list,/Users/shu/Documents/llvm-project/libcxxabi/src/../lib/new-delete.exp -Wl,-exported_symbols_list,/Users/shu/Documents/llvm-project/libcxxabi/src/../lib/personality-v0.exp && : Undefined symbols for architecture x86_64: "__ZTIDu", referenced from: -exported_symbol[s_list] command line option "__ZTIPDu", referenced from: -exported_symbol[s_list] command line option "__ZTIPKDu", referenced from: -exported_symbol[s_list] command line option "__ZTSDu", referenced from: -exported_symbol[s_list] command line option "__ZTSPDu", referenced from: -exported_symbol[s_list] command line option "__ZTSPKDu", referenced from: -exported_symbol[s_list] command line option ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) This is an error message. I know it is caused around libc++, but I don't know where parts should I fix. I did below to solve it. - delete build directory and make build directory again (cmake -G Ninja -DLLVM_ENABLE_PROJECTS="clang;lldb;libcxx;libcxxabi" ../llvm) - build each project(ninja lldb, ninja clang, ninja cxx, ninja cxxabi) - but when I executed "ninja cxx" and "ninja cxxabi", the same error occured. I sometimes tried to solve this problem this week, but I could not solve it. (I could not go to my laboratory because of coronavirus, and I was busy dealing with that, so I could not take much time.) Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D76906/new/ https://reviews.llvm.org/D76906 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 updated this revision to Diff 279906. gedatsu217 added a comment. Add the test content. Change return from void to llvm::Optional in several functions to make the code cleaner. Revise the details. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 Files: lldb/include/lldb/Core/Debugger.h lldb/include/lldb/Core/IOHandler.h lldb/include/lldb/Host/Editline.h lldb/include/lldb/Interpreter/CommandInterpreter.h lldb/source/Core/CoreProperties.td lldb/source/Core/Debugger.cpp lldb/source/Core/IOHandler.cpp lldb/source/Host/common/Editline.cpp lldb/source/Interpreter/CommandInterpreter.cpp lldb/test/API/iohandler/autosuggestion/TestAutosuggestion.py Index: lldb/test/API/iohandler/autosuggestion/TestAutosuggestion.py === --- /dev/null +++ lldb/test/API/iohandler/autosuggestion/TestAutosuggestion.py @@ -0,0 +1,83 @@ +""" +Tests autosuggestion using pexpect. +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test.lldbpexpect import PExpectTest + +class TestCase(PExpectTest): + +mydir = TestBase.compute_mydir(__file__) + +# PExpect uses many timeouts internally and doesn't play well +# under ASAN on a loaded machine.. +@skipIfAsan +@skipIfEditlineSupportMissing +def test_autosuggestion(self): +self.launch(extra_args=["-o", "settings set show-autosuggestion true"]) + +# Common input codes and escape sequences. +ctrl_f = "\x06" +faint_color = "\x1b[2m" +reset = "\x1b[0m" +delete = chr(127) + +frame_output_needle = "Syntax: frame " +# Run 'help frame' once to put it into the command history. +self.expect("help frame", substrs=[frame_output_needle]) + +# Check that LLDB shows the autosuggestion in gray behind the text. +self.child.send("hel") +self.child.expect_exact(faint_color + "p frame" + reset + "\x1b[1G") + +# Apply the autosuggestion and press enter. This should print the +# 'help frame' output if everything went correctly. +self.child.send(ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Check that pressing Ctrl+F directly after Ctrl+F again does nothing. +self.child.send("hel" + ctrl_f + ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Try autosuggestion using tab and ^f. +# \t makes "help" and ^f makes "help frame". If everything went +# correct we should see the 'help frame' output again. +self.child.send("hel\t" + ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Check that pressing Ctrl+F in an empty prompt does nothing. +self.child.send(ctrl_f) +self.child.expect_exact("") +self.child.send("\n") + +# Check that autosuggestion works after delete. +self.child.send("a1234" + 5 * delete + "hel" + ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Check that autosuggestion works after delete. +self.child.send("help x" + delete + ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Check that autosuggestion complete to the most recent one. +self.child.send("help frame variable\n") +self.child.send("help fr") +self.child.expect_exact(faint_color + "ame variable" + reset) +self.child.send("\n") + +# Try another command. +apropos_output_needle = "Syntax: apropos " +# Run 'help frame' once to put it into the command history. +self.expect("help apropos", substrs=[apropos_output_needle]) + +# Check that 'hel' should have an autosuggestion for 'help apropos' now. +self.child.send("hel") +self.child.expect_exact(faint_color + "p apropos" + reset + "\x1b[1G") + +# Run the command and expect the 'help apropos' output. +self.child.send(ctrl_f + "\n") +self.child.expect_exact(apropos_output_needle) + +self.quit() + \ No newline at end of file Index: lldb/source/Interpreter/CommandInterpreter.cpp === --- lldb/source/Interpreter/CommandInterpreter.cpp +++ lldb/source/Interpreter/CommandInterpreter.cpp @@ -1866,6 +1866,17 @@ HandleCompletionMatches(request); } +llvm::Optional +CommandInterpreter::GetAutoSuggestionForCommand(llvm::StringRef line) { + const size_t s = m_command_history.GetSize(); + for (int i = s - 1; i >= 0; --i) { +llvm::StringRef entry = m_command_history.GetStringAtIndex(i); +
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 added a comment. I checked what's the sequence that actually gets output, and it was like below. h\x1b[2melp frame\x1b[0m\x1b[1Ghe\x1b[2mlp frame\x1b[0m\x1b[1Gel\x1b[2mp frame\x1b[0m\x1b[1Gl Is it not good to check these characters in `expect_exact`? CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 added a comment. > That said, are you sure this is the right sequence? \x1b[1Gl seems like it > should print the l at column one, which does not sound right... I thought it did not add up too, but pexpect probably actually outputs these characters. > The sequence I got in this test was l\x1b[2mp frame\x1b[0m\x1b[1G\r\x1b[9Cl, > which seems more believable. It did not go well... However, `"l" + faint_color + "p frame" + reset + "\x1b[1G" + "l"` passed the test. This test ensure that the cursor is behind "l", but I do not understand what role "\x1b[1G" plays... What do you think about this test? CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 added a comment. Yes, I'm testing it on Mac. By the way, I checked its output on the error message. When the test failed, the characters, `buffer (last 100 chars) : ~~~`, are displayed as an error message. I thought it was pexpect's output, possibly it is not that output? CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 added a comment. I do not intend for this feature to work with colors disabled. I found that pexpect output the below sequence, and this passed the test. self.child.expect_exact("\x1b[" + str(len("(lldb) he") + 1) + "G" + "l" + "\x1b[2m" + "p frame" + "\x1b[0m\x1b[1G" + "l" + "\x1b[1G\x1b[2m" + "(lldb) " + "\x1b[22m\x1b[" + str(len("(lldb) hel") + 1) + "G") Probably, "(lldb)" is redisplayed every time a character is typed. On the other hand, the character is placed in the designated position. However, there are two strange points. 1. When a character is typed, it is placed in the designated position, but later, it is placed again in column one and overwritten by "(lldb)". 2. About "\x1b[22m". I think this is equal to "\x1b[0m", but the test failed when I replace "\x1b[22m" with "\x1b[0m". Do you think this is a valid test? CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 added a comment. > Could you create a patch to change the definition of ANSI_UNFAINT ? (might be > worth taking a quick look at git history if there is no good reason for why > it uses the color code that it uses) Sure. Should I create another patch? (In short, should I create it separately from the current patch?) CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 updated this revision to Diff 281017. gedatsu217 added a comment. Revise Editline::ApplyAutosuggestCommand. (Change the return value.) Revise IOHandlerEditline::IOHandlerEditline (Disable to use autosuggestion if debugger.GetUseColor() is false.) Fix the test. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 Files: lldb/include/lldb/Core/Debugger.h lldb/include/lldb/Core/IOHandler.h lldb/include/lldb/Host/Editline.h lldb/include/lldb/Interpreter/CommandInterpreter.h lldb/source/Core/CoreProperties.td lldb/source/Core/Debugger.cpp lldb/source/Core/IOHandler.cpp lldb/source/Host/common/Editline.cpp lldb/source/Interpreter/CommandInterpreter.cpp lldb/test/API/iohandler/autosuggestion/TestAutosuggestion.py Index: lldb/test/API/iohandler/autosuggestion/TestAutosuggestion.py === --- /dev/null +++ lldb/test/API/iohandler/autosuggestion/TestAutosuggestion.py @@ -0,0 +1,83 @@ +""" +Tests autosuggestion using pexpect. +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test.lldbpexpect import PExpectTest + +class TestCase(PExpectTest): + +mydir = TestBase.compute_mydir(__file__) + +# PExpect uses many timeouts internally and doesn't play well +# under ASAN on a loaded machine.. +@skipIfAsan +@skipIfEditlineSupportMissing +def test_autosuggestion(self): +self.launch(extra_args=["-o", "settings set show-autosuggestion true", "-o", "settings set use-color true"]) + +# Common input codes and escape sequences. +ctrl_f = "\x06" +faint_color = "\x1b[2m" +reset = "\x1b[0m" +delete = chr(127) + +frame_output_needle = "Syntax: frame " +# Run 'help frame' once to put it into the command history. +self.expect("help frame", substrs=[frame_output_needle]) + +# Check that LLDB shows the autosuggestion in gray behind the text. +self.child.send("hel") +self.child.expect_exact("\x1b["+ str(len("(lldb) he") + 1) + "G" + "l" + faint_color + "p frame" + reset) + +# Apply the autosuggestion and press enter. This should print the +# 'help frame' output if everything went correctly. +self.child.send(ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Check that pressing Ctrl+F directly after Ctrl+F again does nothing. +self.child.send("hel" + ctrl_f + ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Try autosuggestion using tab and ^f. +# \t makes "help" and ^f makes "help frame". If everything went +# correct we should see the 'help frame' output again. +self.child.send("hel\t" + ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Check that autosuggestion works after delete. +self.child.send("a1234" + 5 * delete + "hel" + ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Check that autosuggestion works after delete. +self.child.send("help x" + delete + ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Check that autosuggestion complete to the most recent one. +self.child.send("help frame variable\n") +self.child.send("help fr") +self.child.expect_exact(faint_color + "ame variable" + reset) +self.child.send("\n") + +# Try another command. +apropos_output_needle = "Syntax: apropos " +# Run 'help frame' once to put it into the command history. +self.expect("help apropos", substrs=[apropos_output_needle]) + +# Check that 'hel' should have an autosuggestion for 'help apropos' now. +self.child.send("hel") +self.child.expect_exact("\x1b["+ str(len("(lldb) he") + 1) + "G" + "l" + faint_color + "p apropos" + reset) + +# Run the command and expect the 'help apropos' output. +self.child.send(ctrl_f + "\n") +self.child.expect_exact(apropos_output_needle) + +# Check that pressing Ctrl+F in an empty prompt does nothing. +breakpoint_output_needle = "Syntax: breakpoint " +self.child.send(ctrl_f + "help breakpoint" +"\n") +self.child.expect_exact(breakpoint_output_needle) + +self.quit() + \ No newline at end of file Index: lldb/source/Interpreter/CommandInterpreter.cpp === --- lldb/source/Interpreter/CommandInterpreter.cpp +++ lldb/source/Interpreter/CommandInterpreter.cpp @@ -1866,6 +1866,19 @@ HandleCompletionMatches(request); } +llvm::Optiona
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 updated this revision to Diff 281247. gedatsu217 added a comment. Editline::TypedCharacter is called when delete is pressed. (This probably fix the above bug.) Revise the test. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 Files: lldb/include/lldb/Core/Debugger.h lldb/include/lldb/Core/IOHandler.h lldb/include/lldb/Host/Editline.h lldb/include/lldb/Interpreter/CommandInterpreter.h lldb/source/Core/CoreProperties.td lldb/source/Core/Debugger.cpp lldb/source/Core/IOHandler.cpp lldb/source/Host/common/Editline.cpp lldb/source/Interpreter/CommandInterpreter.cpp Index: lldb/source/Interpreter/CommandInterpreter.cpp === --- lldb/source/Interpreter/CommandInterpreter.cpp +++ lldb/source/Interpreter/CommandInterpreter.cpp @@ -1866,6 +1866,19 @@ HandleCompletionMatches(request); } +llvm::Optional +CommandInterpreter::GetAutoSuggestionForCommand(llvm::StringRef line) { + if (line.empty()) +return llvm::None; + const size_t s = m_command_history.GetSize(); + for (int i = s - 1; i >= 0; --i) { +llvm::StringRef entry = m_command_history.GetStringAtIndex(i); +if (entry.consume_front(line)) + return entry.str(); + } + return llvm::None; +} + CommandInterpreter::~CommandInterpreter() {} void CommandInterpreter::UpdatePrompt(llvm::StringRef new_prompt) { Index: lldb/source/Host/common/Editline.cpp === --- lldb/source/Host/common/Editline.cpp +++ lldb/source/Host/common/Editline.cpp @@ -1007,9 +1007,7 @@ to_add = to_add.substr(request.GetCursorArgumentPrefix().size()); if (request.GetParsedArg().IsQuoted()) to_add.push_back(request.GetParsedArg().GetQuoteChar()); - to_add.push_back(' '); - el_insertstr(m_editline, to_add.c_str()); - break; + return CC_REFRESH; } case CompletionMode::Partial: { std::string to_add = completion.GetCompletion(); @@ -1043,6 +1041,42 @@ return CC_REDISPLAY; } +unsigned char Editline::ApplyAutosuggestCommand(int ch) { + const LineInfo *line_info = el_line(m_editline); + llvm::StringRef line(line_info->buffer, + line_info->lastchar - line_info->buffer); + + if (llvm::Optional to_add = + m_suggestion_callback(line, m_suggestion_callback_baton)) +el_insertstr(m_editline, to_add.getValue().c_str()); + + return CC_REDISPLAY; +} + +unsigned char Editline::TypedCharacter(int ch) { + if(ch == 127) { +el_deletestr(m_editline, 1); +return CC_REDISPLAY; + } + + std::string typed = std::string(1, ch); + el_insertstr(m_editline, typed.c_str()); + const LineInfo *line_info = el_line(m_editline); + llvm::StringRef line(line_info->buffer, + line_info->lastchar - line_info->buffer); + + if (llvm::Optional to_add = + m_suggestion_callback(line, m_suggestion_callback_baton)) { +std::string to_add_color = ANSI_FAINT + to_add.getValue() + ANSI_UNFAINT; +fputs(typed.c_str(), m_output_file); +fputs(to_add_color.c_str(), m_output_file); +MoveCursor(CursorLocation::BlockEnd, CursorLocation::EditingCursor); +return CC_NORM; + } + + return CC_REDISPLAY; +} + void Editline::ConfigureEditor(bool multiline) { if (m_editline && m_multiline_enabled == multiline) return; @@ -1156,9 +1190,43 @@ if (!multiline) { el_set(m_editline, EL_BIND, "^r", "em-inc-search-prev", NULL); // Cycle through backwards search, entering string + +if (m_suggestion_callback) { + el_wset(m_editline, EL_ADDFN, EditLineConstString("lldb-apply-complete"), + EditLineConstString("Adopt autocompletion"), + (EditlineCommandCallbackType)([](EditLine *editline, int ch) { +return Editline::InstanceFor(editline)->ApplyAutosuggestCommand( +ch); + })); + + el_set(m_editline, EL_BIND, "^f", "lldb-apply-complete", + NULL); // Apply a part that is suggested automatically + + el_wset(m_editline, EL_ADDFN, EditLineConstString("lldb-typed-character"), + EditLineConstString("Typed character"), + (EditlineCommandCallbackType)([](EditLine *editline, int ch) { +return Editline::InstanceFor(editline)->TypedCharacter(ch); + })); + + char bind_key[2] = {0, 0}; + llvm::StringRef ascii_chars = + "abcdefghijklmnopqrstuvwxzyABCDEFGHIJKLMNOPQRSTUVWXZY1234567890!\"#$%" + "&'()*+,./:;<=>?@[]_`{|}~ "; + for (char c : ascii_chars) { +bind_key[0] = c; +el_set(m_editline, EL_BIND, bind_key, "lldb-typed-character", NULL); + } + el_set(m_editline, EL_BIND, "\\-", "lldb-typed-character", NULL); + el_set(m_editline, EL_BIND, "\\^", "lldb-typed-character", NULL); + el_set(m_editline, EL_BIND, "", "lldb-typed-character", N
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 added a comment. Sorry, I found the bug. Please do not check this yet. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 added a comment. For example, I execute "help frame variable" and save it as command history. Then, when I type "hel", "helhelp [me variable]" (gray characters are in []) is displayed, probably because of cursor position or CC_NORM. I am trying to solve this problem, but I have not come up with a solution. If you know how to solve this problem, would you help me? CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 updated this revision to Diff 281677. gedatsu217 added a comment. Fix the cursor position. (Editline::TypedCharacter) CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 Files: lldb/include/lldb/Core/Debugger.h lldb/include/lldb/Core/IOHandler.h lldb/include/lldb/Host/Editline.h lldb/include/lldb/Interpreter/CommandInterpreter.h lldb/source/Core/CoreProperties.td lldb/source/Core/Debugger.cpp lldb/source/Core/IOHandler.cpp lldb/source/Host/common/Editline.cpp lldb/source/Interpreter/CommandInterpreter.cpp lldb/test/API/iohandler/autosuggestion/TestAutosuggestion.py Index: lldb/test/API/iohandler/autosuggestion/TestAutosuggestion.py === --- /dev/null +++ lldb/test/API/iohandler/autosuggestion/TestAutosuggestion.py @@ -0,0 +1,86 @@ +""" +Tests autosuggestion using pexpect. +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test.lldbpexpect import PExpectTest + +def cursor_horizontal_abs(s): +return "\x1b[" + str(len(s) + 1) + "G" + +class TestCase(PExpectTest): + +mydir = TestBase.compute_mydir(__file__) + +# PExpect uses many timeouts internally and doesn't play well +# under ASAN on a loaded machine.. +@skipIfAsan +@skipIfEditlineSupportMissing +def test_autosuggestion(self): +self.launch(extra_args=["-o", "settings set show-autosuggestion true", "-o", "settings set use-color true"]) + +# Common input codes and escape sequences. +ctrl_f = "\x06" +faint_color = "\x1b[2m" +reset = "\x1b[0m" +delete = chr(127) + +frame_output_needle = "Syntax: frame " +# Run 'help frame' once to put it into the command history. +self.expect("help frame", substrs=[frame_output_needle]) + +# Check that LLDB shows the autosuggestion in gray behind the text. +self.child.send("hel") +self.child.expect_exact(cursor_horizontal_abs("(lldb) he") + "l" + faint_color + "p frame" + reset) + +# Apply the autosuggestion and press enter. This should print the +# 'help frame' output if everything went correctly. +self.child.send(ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Check that pressing Ctrl+F directly after Ctrl+F again does nothing. +self.child.send("hel" + ctrl_f + ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Try autosuggestion using tab and ^f. +# \t makes "help" and ^f makes "help frame". If everything went +# correct we should see the 'help frame' output again. +self.child.send("hel\t" + ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Check that autosuggestion works after delete. +self.child.send("a1234" + 5 * delete + "hel" + ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Check that autosuggestion works after delete. +self.child.send("help x" + delete + ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Check that autosuggestion complete to the most recent one. +self.child.send("help frame variable\n") +self.child.send("help fr") +self.child.expect_exact(faint_color + "ame variable" + reset) +self.child.send("\n") + +# Try another command. +apropos_output_needle = "Syntax: apropos " +# Run 'help frame' once to put it into the command history. +self.expect("help apropos", substrs=[apropos_output_needle]) + +# Check that 'hel' should have an autosuggestion for 'help apropos' now. +self.child.send("hel") +self.child.expect_exact(cursor_horizontal_abs("(lldb) he") + "l" + faint_color + "p apropos" + reset) + +# Run the command and expect the 'help apropos' output. +self.child.send(ctrl_f + "\n") +self.child.expect_exact(apropos_output_needle) + +# Check that pressing Ctrl+F in an empty prompt does nothing. +breakpoint_output_needle = "Syntax: breakpoint " +self.child.send(ctrl_f + "help breakpoint" +"\n") +self.child.expect_exact(breakpoint_output_needle) + +self.quit() + \ No newline at end of file Index: lldb/source/Interpreter/CommandInterpreter.cpp === --- lldb/source/Interpreter/CommandInterpreter.cpp +++ lldb/source/Interpreter/CommandInterpreter.cpp @@ -1866,6 +1866,19 @@ HandleCompletionMatches(request); } +llvm::Optional +CommandInterpreter::GetAutoSuggestionForCommand(llvm::StringRef line) { + if
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 updated this revision to Diff 281686. gedatsu217 added a comment. Sorry, I mistakenly uploaded a different file. This is the correct file. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 Files: lldb/include/lldb/Core/Debugger.h lldb/include/lldb/Core/IOHandler.h lldb/include/lldb/Host/Editline.h lldb/include/lldb/Interpreter/CommandInterpreter.h lldb/source/Core/CoreProperties.td lldb/source/Core/Debugger.cpp lldb/source/Core/IOHandler.cpp lldb/source/Host/common/Editline.cpp lldb/source/Interpreter/CommandInterpreter.cpp lldb/test/API/iohandler/autosuggestion/TestAutosuggestion.py Index: lldb/test/API/iohandler/autosuggestion/TestAutosuggestion.py === --- /dev/null +++ lldb/test/API/iohandler/autosuggestion/TestAutosuggestion.py @@ -0,0 +1,86 @@ +""" +Tests autosuggestion using pexpect. +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test.lldbpexpect import PExpectTest + +def cursor_horizontal_abs(s): +return "\x1b[" + str(len(s) + 1) + "G" + +class TestCase(PExpectTest): + +mydir = TestBase.compute_mydir(__file__) + +# PExpect uses many timeouts internally and doesn't play well +# under ASAN on a loaded machine.. +@skipIfAsan +@skipIfEditlineSupportMissing +def test_autosuggestion(self): +self.launch(extra_args=["-o", "settings set show-autosuggestion true", "-o", "settings set use-color true"]) + +# Common input codes and escape sequences. +ctrl_f = "\x06" +faint_color = "\x1b[2m" +reset = "\x1b[0m" +delete = chr(127) + +frame_output_needle = "Syntax: frame " +# Run 'help frame' once to put it into the command history. +self.expect("help frame", substrs=[frame_output_needle]) + +# Check that LLDB shows the autosuggestion in gray behind the text. +self.child.send("hel") +self.child.expect_exact(cursor_horizontal_abs("(lldb) he") + "l" + faint_color + "p frame" + reset) + +# Apply the autosuggestion and press enter. This should print the +# 'help frame' output if everything went correctly. +self.child.send(ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Check that pressing Ctrl+F directly after Ctrl+F again does nothing. +self.child.send("hel" + ctrl_f + ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Try autosuggestion using tab and ^f. +# \t makes "help" and ^f makes "help frame". If everything went +# correct we should see the 'help frame' output again. +self.child.send("hel\t" + ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Check that autosuggestion works after delete. +self.child.send("a1234" + 5 * delete + "hel" + ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Check that autosuggestion works after delete. +self.child.send("help x" + delete + ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Check that autosuggestion complete to the most recent one. +self.child.send("help frame variable\n") +self.child.send("help fr") +self.child.expect_exact(faint_color + "ame variable" + reset) +self.child.send("\n") + +# Try another command. +apropos_output_needle = "Syntax: apropos " +# Run 'help frame' once to put it into the command history. +self.expect("help apropos", substrs=[apropos_output_needle]) + +# Check that 'hel' should have an autosuggestion for 'help apropos' now. +self.child.send("hel") +self.child.expect_exact(cursor_horizontal_abs("(lldb) he") + "l" + faint_color + "p apropos" + reset) + +# Run the command and expect the 'help apropos' output. +self.child.send(ctrl_f + "\n") +self.child.expect_exact(apropos_output_needle) + +# Check that pressing Ctrl+F in an empty prompt does nothing. +breakpoint_output_needle = "Syntax: breakpoint " +self.child.send(ctrl_f + "help breakpoint" +"\n") +self.child.expect_exact(breakpoint_output_needle) + +self.quit() + \ No newline at end of file Index: lldb/source/Interpreter/CommandInterpreter.cpp === --- lldb/source/Interpreter/CommandInterpreter.cpp +++ lldb/source/Interpreter/CommandInterpreter.cpp @@ -1866,6 +1866,19 @@ HandleCompletionMatches(request); } +llvm::Optional +CommandInterpreter::GetAutoSuggestionForCommand(llvm::Str
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 added a comment. Although I thought of how to clear all the following characters, I did not come up with it. So, I will try to fill the space. Should I add how many spaces? If I add too many spaces, sequences will be two lines, but if I add a few spaces, I can't handle some of the cases. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 added a comment. > Also could you rebase the diff here when you have time (e.g., regenerate the > diff from you changes on top of the latest master commit)? It no longer > applies at the moment without having to manually resolve a conflict. Does this mean that I should generate diff from the current latest master commit of [https://github.com/llvm/llvm-project]? or from my latest commit (local)? Sorry, I am not used to using git:( CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 updated this revision to Diff 282430. gedatsu217 added a comment. Add spaces when a character is typed. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 Files: lldb/include/lldb/Core/Debugger.h lldb/include/lldb/Core/IOHandler.h lldb/include/lldb/Host/Editline.h lldb/include/lldb/Interpreter/CommandInterpreter.h lldb/source/Core/CoreProperties.td lldb/source/Core/Debugger.cpp lldb/source/Core/IOHandler.cpp lldb/source/Host/common/Editline.cpp lldb/source/Interpreter/CommandInterpreter.cpp lldb/test/API/iohandler/autosuggestion/TestAutosuggestion.py Index: lldb/test/API/iohandler/autosuggestion/TestAutosuggestion.py === --- /dev/null +++ lldb/test/API/iohandler/autosuggestion/TestAutosuggestion.py @@ -0,0 +1,86 @@ +""" +Tests autosuggestion using pexpect. +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test.lldbpexpect import PExpectTest + +def cursor_horizontal_abs(s): +return "\x1b[" + str(len(s) + 1) + "G" + +class TestCase(PExpectTest): + +mydir = TestBase.compute_mydir(__file__) + +# PExpect uses many timeouts internally and doesn't play well +# under ASAN on a loaded machine.. +@skipIfAsan +@skipIfEditlineSupportMissing +def test_autosuggestion(self): +self.launch(extra_args=["-o", "settings set show-autosuggestion true", "-o", "settings set use-color true"]) + +# Common input codes and escape sequences. +ctrl_f = "\x06" +faint_color = "\x1b[2m" +reset = "\x1b[0m" +delete = chr(127) + +frame_output_needle = "Syntax: frame " +# Run 'help frame' once to put it into the command history. +self.expect("help frame", substrs=[frame_output_needle]) + +# Check that LLDB shows the autosuggestion in gray behind the text. +self.child.send("hel") +self.child.expect_exact(cursor_horizontal_abs("(lldb) he") + "l" + faint_color + "p frame" + reset) + +# Apply the autosuggestion and press enter. This should print the +# 'help frame' output if everything went correctly. +self.child.send(ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Check that pressing Ctrl+F directly after Ctrl+F again does nothing. +self.child.send("hel" + ctrl_f + ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Try autosuggestion using tab and ^f. +# \t makes "help" and ^f makes "help frame". If everything went +# correct we should see the 'help frame' output again. +self.child.send("hel\t" + ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Check that autosuggestion works after delete. +self.child.send("a1234" + 5 * delete + "hel" + ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Check that autosuggestion works after delete. +self.child.send("help x" + delete + ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Check that autosuggestion complete to the most recent one. +self.child.send("help frame variable\n") +self.child.send("help fr") +self.child.expect_exact(faint_color + "ame variable" + reset) +self.child.send("\n") + +# Try another command. +apropos_output_needle = "Syntax: apropos " +# Run 'help frame' once to put it into the command history. +self.expect("help apropos", substrs=[apropos_output_needle]) + +# Check that 'hel' should have an autosuggestion for 'help apropos' now. +self.child.send("hel") +self.child.expect_exact(cursor_horizontal_abs("(lldb) he") + "l" + faint_color + "p apropos" + reset) + +# Run the command and expect the 'help apropos' output. +self.child.send(ctrl_f + "\n") +self.child.expect_exact(apropos_output_needle) + +# Check that pressing Ctrl+F in an empty prompt does nothing. +breakpoint_output_needle = "Syntax: breakpoint " +self.child.send(ctrl_f + "help breakpoint" +"\n") +self.child.expect_exact(breakpoint_output_needle) + +self.quit() + \ No newline at end of file Index: lldb/source/Interpreter/CommandInterpreter.cpp === --- lldb/source/Interpreter/CommandInterpreter.cpp +++ lldb/source/Interpreter/CommandInterpreter.cpp @@ -1878,6 +1878,19 @@ HandleCompletionMatches(request); } +llvm::Optional +CommandInterpreter::GetAutoSuggestionForCommand(llvm::StringRef line) { + if (line.empty())
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 added a comment. @skipIfAsan @skipIfEditlineSupportMissing def test_hidden_autosuggestion(self): @skipIfAsan @skipIfEditlineSupportMissing def test_autosuggestion(self): self.launch(extra_args=["-o", "settings set show-autosuggestion true", "-o", "settings set use-color true"]) self.expect("help frame v") self.expect("help frame info") [type 'help frame v' and check for the three space after the grey part to cover up the "nfo" text] Sorry, would you tell me about this code in more detail? Does this mean that I should make test_hidden_autosuggestion and test if there are spaces there? What is the difference between test_hidden_autosuggestion and test_autosuggestion? > I don't think the value of m_previous_autosuggestion_size should only grow > (which is what this if is doing), as this way we just keep printing a longer > and longer space buffer over time. Just printing enough to clear the buffer > of the previous completion is enough. If I keep the number of characters of the only previous command, I think there is a problem. For example, If I type "help frame var" → "help frame info" → "help frame v", the remains are hidden. However, If I type "help frame var" → "help frame info" → "help" → "help frame v", the number of characters of "help frame var" is more than that of "help", so "help frame v[aro]" is displayed. What do you think? > Also you can just do this calculation directly after you calculated int > spaces_to_print above. This way this code is closer together which hopefully > makes this easier to understand. For example, if the user executes a command directly after using tab-completion, Editline::TypedCharacter is not called, so spaces_to_print is not calculated. That is because I can calculate this here. By the way, I found a bug again. The gray characters remain when only one character is completed by tab-completion. For instance, when I type "b" and press tab-key after I execute "breakpoint", b [eakpoint] is displayed. [eakpoint] should not be displayed. This problem will be probably solved by my previous diff (https://reviews.llvm.org/D81001?id=276468). But this diff changes Editline::TabCommand significantly. Would you tell me a good way if any? CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 added a comment. >>> I don't think the value of m_previous_autosuggestion_size should only grow >>> (which is what this if is doing), as this way we just keep printing a >>> longer and longer space buffer over time. Just printing enough to clear the >>> buffer of the previous completion is enough. >> >> If I keep the number of characters of the only previous command, I think >> there is a problem. For example, If I type "help frame var" → "help frame >> info" → "help frame v", the remains are hidden. However, If I type "help >> frame var" → "help frame info" → "help" → "help frame v", the number of >> characters of "help frame var" is more than that of "help", so "help frame >> v[aro]" is displayed. What do you think? > > Not sure if I understand your example correctly, but as soon as you type > "help frame ", you should have an autosuggestion of "help frame info" and > then typing the "v" should clear the "nfo" part. The "help" autosuggestion > should not be involved at all in any logic after you typed "help "? What I mean is that if I should keep the length of characters of the only previous command, following thing occurs. 1. execution "help frame var" and m_previous_autosuggestion_size = len("help frame var") = 14 2. execution "help frame info" and m_previous_autosuggestion_size = len("help frame info") = 15 3. execution "help" and m_previous_autosuggestion_size = len("help") = 4 4. Typing "help frame v". Then, spaces_to_print = m_previous_autosuggestion_size - line.size() - to_add.getValue().length() = 4 - 12 - 2 < 0. So, spaces are not added. (In short, "help frame v[aro]" is displayed.) (Maybe, I do not understand what you say. ) >>> Also you can just do this calculation directly after you calculated int >>> spaces_to_print above. This way this code is closer together which >>> hopefully makes this easier to understand. >> >> For example, if the user executes a command directly after using >> tab-completion, Editline::TypedCharacter is not called, so spaces_to_print >> is not calculated. That is because I can calculate this here. > > Can you give me an example input where this breaks? I'm not sure how the tab > completion would influence until what column we would need to overwrite the > line buffer (that should still be the same). If m_previous_autosuggestion_size is calculated in Editline::TypedCharacter, 1. Execution "help frame info", m_previous_autosuggestion_size = len("help frame info") = 15 2. Typing "help frame va" and pressing tab-key. "help frame variable" is executed. m_previous_autosuggestion_size = len("help frame va") = 13. (because m_previous_autosuggestion_size is not calculated in Editline::TabCommand.) 3. Typing "help frame i". Then, spaces_to_print = m_previous_autosuggestion_size - line.size() - to_add.getValue().length() = 13 - 12 - 3 < 0. So, spaces are not added. "help frame i[nfoable] is displayed. > Did you try if your previous code fixes this issue? Not yet. I will try it. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 added a comment. @teemperor I understand what you say just now. Indeed, your method is more efficient than mine. I'm fixing the code now. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 updated this revision to Diff 282961. gedatsu217 added a comment. Add test. Delete gray character if autosuggestion has the only one character. (e.g. "b") (Editline::TabCommand) Simplify the code. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 Files: lldb/include/lldb/Core/Debugger.h lldb/include/lldb/Core/IOHandler.h lldb/include/lldb/Host/Editline.h lldb/include/lldb/Interpreter/CommandInterpreter.h lldb/source/Core/CoreProperties.td lldb/source/Core/Debugger.cpp lldb/source/Core/IOHandler.cpp lldb/source/Host/common/Editline.cpp lldb/source/Interpreter/CommandInterpreter.cpp lldb/test/API/iohandler/autosuggestion/TestAutosuggestion.py Index: lldb/test/API/iohandler/autosuggestion/TestAutosuggestion.py === --- /dev/null +++ lldb/test/API/iohandler/autosuggestion/TestAutosuggestion.py @@ -0,0 +1,104 @@ +""" +Tests autosuggestion using pexpect. +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test.lldbpexpect import PExpectTest + +def cursor_horizontal_abs(s): +return "\x1b[" + str(len(s) + 1) + "G" + + + +class TestCase(PExpectTest): + +mydir = TestBase.compute_mydir(__file__) + +# PExpect uses many timeouts internally and doesn't play well +# under ASAN on a loaded machine.. +@skipIfAsan +@skipIfEditlineSupportMissing +def test_autosuggestion_add_spaces(self): +self.launch(extra_args=["-o", "settings set show-autosuggestion true", "-o", "settings set use-color true"]) + +# Common input codes and escape sequences. +faint_color = "\x1b[2m" +reset = "\x1b[0m" + +# Check if spaces are added to hide the previous gray characters. +self.expect("help frame var") +self.expect("help frame info") +self.child.send("help frame v") +self.child.expect_exact(cursor_horizontal_abs("(lldb) help frame ") + "v" + faint_color + "ar" + reset + " ") + +@skipIfAsan +@skipIfEditlineSupportMissing +def test_autosuggestion(self): +self.launch(extra_args=["-o", "settings set show-autosuggestion true", "-o", "settings set use-color true"]) + +# Common input codes and escape sequences. +ctrl_f = "\x06" +faint_color = "\x1b[2m" +reset = "\x1b[0m" +delete = chr(127) + +frame_output_needle = "Syntax: frame " +# Run 'help frame' once to put it into the command history. +self.expect("help frame", substrs=[frame_output_needle]) + +# Check that LLDB shows the autosuggestion in gray behind the text. +self.child.send("hel") +self.child.expect_exact(cursor_horizontal_abs("(lldb) he") + "l" + faint_color + "p frame" + reset) + +# Apply the autosuggestion and press enter. This should print the +# 'help frame' output if everything went correctly. +self.child.send(ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Check that pressing Ctrl+F directly after Ctrl+F again does nothing. +self.child.send("hel" + ctrl_f + ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Try autosuggestion using tab and ^f. +# \t makes "help" and ^f makes "help frame". If everything went +# correct we should see the 'help frame' output again. +self.child.send("hel\t" + ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Check that autosuggestion works after delete. +self.child.send("a1234" + 5 * delete + "hel" + ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Check that autosuggestion works after delete. +self.child.send("help x" + delete + ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Check that autosuggestion complete to the most recent one. +self.child.send("help frame variable\n") +self.child.send("help fr") +self.child.expect_exact(faint_color + "ame variable" + reset) +self.child.send("\n") + +# Try another command. +apropos_output_needle = "Syntax: apropos " +# Run 'help frame' once to put it into the command history. +self.expect("help apropos", substrs=[apropos_output_needle]) + +# Check that 'hel' should have an autosuggestion for 'help apropos' now. +self.child.send("hel") +self.child.expect_exact(cursor_horizontal_abs("(lldb) he") + "l" + faint_color + "p apropos" + reset) + +# Run the command and expect the 'help apropos' output. +self.child.send(ctrl_f + "\n") +self.chil
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 added a comment. > So the way the issue with the single space is now solved is by doing > CC_REDISPLAY when we're only adding the single space? Isn't that also > deleting the whole autosuggestion? Yes. CC_REDISPLAY can delete all the gray characters left. Comment at: lldb/source/Host/common/Editline.cpp:1081 +if (spaces_to_print > 0) { + std::string spaces = std::string((int)spaces_to_print, ' '); + fputs(spaces.c_str(), m_output_file); teemperor wrote: > The `(int)` cast isn't necessary. I found that lldb crashed. Sorry, I should have checked more when I uploaded this. I use spaces_to_print as size_t, but this sometimes becomes less than zero. So, I have to use this as int. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 added a comment. > So, if I would type "b" and then press tab, the autosuggestion would briefly > disappear until I type the next character? Yes. Indeed, it may not be good. I'll think of other ways. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 added a comment. > Are there any other problems with the current state of the patch that haven't > been resolved? (I went over the comments, but it's hard to say what has and > hasn't been fixed until now). Yes, I have solved all the problems. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 updated this revision to Diff 283590. gedatsu217 added a comment. Simplify the code. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 Files: lldb/include/lldb/Core/Debugger.h lldb/include/lldb/Core/IOHandler.h lldb/include/lldb/Host/Editline.h lldb/include/lldb/Interpreter/CommandInterpreter.h lldb/source/Core/CoreProperties.td lldb/source/Core/Debugger.cpp lldb/source/Core/IOHandler.cpp lldb/source/Host/common/Editline.cpp lldb/source/Interpreter/CommandInterpreter.cpp lldb/test/API/iohandler/autosuggestion/TestAutosuggestion.py Index: lldb/test/API/iohandler/autosuggestion/TestAutosuggestion.py === --- /dev/null +++ lldb/test/API/iohandler/autosuggestion/TestAutosuggestion.py @@ -0,0 +1,104 @@ +""" +Tests autosuggestion using pexpect. +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test.lldbpexpect import PExpectTest + +def cursor_horizontal_abs(s): +return "\x1b[" + str(len(s) + 1) + "G" + + + +class TestCase(PExpectTest): + +mydir = TestBase.compute_mydir(__file__) + +# PExpect uses many timeouts internally and doesn't play well +# under ASAN on a loaded machine.. +@skipIfAsan +@skipIfEditlineSupportMissing +def test_autosuggestion_add_spaces(self): +self.launch(extra_args=["-o", "settings set show-autosuggestion true", "-o", "settings set use-color true"]) + +# Common input codes and escape sequences. +faint_color = "\x1b[2m" +reset = "\x1b[0m" + +# Check if spaces are added to hide the previous gray characters. +self.expect("help frame var") +self.expect("help frame info") +self.child.send("help frame v") +self.child.expect_exact(cursor_horizontal_abs("(lldb) help frame ") + "v" + faint_color + "ar" + reset + " ") + +@skipIfAsan +@skipIfEditlineSupportMissing +def test_autosuggestion(self): +self.launch(extra_args=["-o", "settings set show-autosuggestion true", "-o", "settings set use-color true"]) + +# Common input codes and escape sequences. +ctrl_f = "\x06" +faint_color = "\x1b[2m" +reset = "\x1b[0m" +delete = chr(127) + +frame_output_needle = "Syntax: frame " +# Run 'help frame' once to put it into the command history. +self.expect("help frame", substrs=[frame_output_needle]) + +# Check that LLDB shows the autosuggestion in gray behind the text. +self.child.send("hel") +self.child.expect_exact(cursor_horizontal_abs("(lldb) he") + "l" + faint_color + "p frame" + reset) + +# Apply the autosuggestion and press enter. This should print the +# 'help frame' output if everything went correctly. +self.child.send(ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Check that pressing Ctrl+F directly after Ctrl+F again does nothing. +self.child.send("hel" + ctrl_f + ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Try autosuggestion using tab and ^f. +# \t makes "help" and ^f makes "help frame". If everything went +# correct we should see the 'help frame' output again. +self.child.send("hel\t" + ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Check that autosuggestion works after delete. +self.child.send("a1234" + 5 * delete + "hel" + ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Check that autosuggestion works after delete. +self.child.send("help x" + delete + ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Check that autosuggestion complete to the most recent one. +self.child.send("help frame variable\n") +self.child.send("help fr") +self.child.expect_exact(faint_color + "ame variable" + reset) +self.child.send("\n") + +# Try another command. +apropos_output_needle = "Syntax: apropos " +# Run 'help frame' once to put it into the command history. +self.expect("help apropos", substrs=[apropos_output_needle]) + +# Check that 'hel' should have an autosuggestion for 'help apropos' now. +self.child.send("hel") +self.child.expect_exact(cursor_horizontal_abs("(lldb) he") + "l" + faint_color + "p apropos" + reset) + +# Run the command and expect the 'help apropos' output. +self.child.send(ctrl_f + "\n") +self.child.expect_exact(apropos_output_needle) + +# Check that pressing Ctrl+F in an empty prompt does nothing. +
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 updated this revision to Diff 283686. gedatsu217 added a comment. add comments. revise a test(add self.quit()). CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 Files: lldb/include/lldb/Core/Debugger.h lldb/include/lldb/Core/IOHandler.h lldb/include/lldb/Host/Editline.h lldb/include/lldb/Interpreter/CommandInterpreter.h lldb/source/Core/CoreProperties.td lldb/source/Core/Debugger.cpp lldb/source/Core/IOHandler.cpp lldb/source/Host/common/Editline.cpp lldb/source/Interpreter/CommandInterpreter.cpp lldb/test/API/iohandler/autosuggestion/TestAutosuggestion.py Index: lldb/test/API/iohandler/autosuggestion/TestAutosuggestion.py === --- /dev/null +++ lldb/test/API/iohandler/autosuggestion/TestAutosuggestion.py @@ -0,0 +1,106 @@ +""" +Tests autosuggestion using pexpect. +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test.lldbpexpect import PExpectTest + +def cursor_horizontal_abs(s): +return "\x1b[" + str(len(s) + 1) + "G" + + + +class TestCase(PExpectTest): + +mydir = TestBase.compute_mydir(__file__) + +# PExpect uses many timeouts internally and doesn't play well +# under ASAN on a loaded machine.. +@skipIfAsan +@skipIfEditlineSupportMissing +def test_autosuggestion_add_spaces(self): +self.launch(extra_args=["-o", "settings set show-autosuggestion true", "-o", "settings set use-color true"]) + +# Common input codes and escape sequences. +faint_color = "\x1b[2m" +reset = "\x1b[0m" + +# Check if spaces are added to hide the previous gray characters. +self.expect("help frame var") +self.expect("help frame info") +self.child.send("help frame v") +self.child.expect_exact(cursor_horizontal_abs("(lldb) help frame ") + "v" + faint_color + "ar" + reset + " ") + +self.quit() + +@skipIfAsan +@skipIfEditlineSupportMissing +def test_autosuggestion(self): +self.launch(extra_args=["-o", "settings set show-autosuggestion true", "-o", "settings set use-color true"]) + +# Common input codes and escape sequences. +ctrl_f = "\x06" +faint_color = "\x1b[2m" +reset = "\x1b[0m" +delete = chr(127) + +frame_output_needle = "Syntax: frame " +# Run 'help frame' once to put it into the command history. +self.expect("help frame", substrs=[frame_output_needle]) + +# Check that LLDB shows the autosuggestion in gray behind the text. +self.child.send("hel") +self.child.expect_exact(cursor_horizontal_abs("(lldb) he") + "l" + faint_color + "p frame" + reset) + +# Apply the autosuggestion and press enter. This should print the +# 'help frame' output if everything went correctly. +self.child.send(ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Check that pressing Ctrl+F directly after Ctrl+F again does nothing. +self.child.send("hel" + ctrl_f + ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Try autosuggestion using tab and ^f. +# \t makes "help" and ^f makes "help frame". If everything went +# correct we should see the 'help frame' output again. +self.child.send("hel\t" + ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Check that autosuggestion works after delete. +self.child.send("a1234" + 5 * delete + "hel" + ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Check that autosuggestion works after delete. +self.child.send("help x" + delete + ctrl_f + "\n") +self.child.expect_exact(frame_output_needle) + +# Check that autosuggestion complete to the most recent one. +self.child.send("help frame variable\n") +self.child.send("help fr") +self.child.expect_exact(faint_color + "ame variable" + reset) +self.child.send("\n") + +# Try another command. +apropos_output_needle = "Syntax: apropos " +# Run 'help frame' once to put it into the command history. +self.expect("help apropos", substrs=[apropos_output_needle]) + +# Check that 'hel' should have an autosuggestion for 'help apropos' now. +self.child.send("hel") +self.child.expect_exact(cursor_horizontal_abs("(lldb) he") + "l" + faint_color + "p apropos" + reset) + +# Run the command and expect the 'help apropos' output. +self.child.send(ctrl_f + "\n") +self.child.expect_exact(apropos_output_needle) + +# Check that pr
[Lldb-commits] [PATCH] D76906: [lldb] Fixing the bug that the "log timer" has no tab completion
gedatsu217 added a comment. I performed a factory reset for OS upgrade and rebuild LLDB, and solved this problem. Thanks. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D76906/new/ https://reviews.llvm.org/D76906 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 created this revision. gedatsu217 added reviewers: teemperor, JDevlieghere. gedatsu217 added a project: LLDB. Herald added a subscriber: lldb-commits. I implemented autosuggestion if there is one possible suggestion. I set the keybinds for every character. When a character is typed, Editline::TypedCharacter is called. Then, autosuggestion part is displayed in gray, and you can actually input by typing C-k. Editline::Autosuggest is a function for finding completion, and it is like Editline::TabCommand now, but I will add more features to it. Testing does not work well in my environment, so I can't confirm that it goes well, sorry. I am dealing with it now. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D81001 Files: lldb/include/lldb/Host/Editline.h lldb/source/Host/common/Editline.cpp Index: lldb/source/Host/common/Editline.cpp === --- lldb/source/Host/common/Editline.cpp +++ lldb/source/Host/common/Editline.cpp @@ -14,6 +14,7 @@ #include "lldb/Host/Editline.h" #include "lldb/Host/FileSystem.h" #include "lldb/Host/Host.h" +#include "lldb/Utility/AnsiTerminal.h" #include "lldb/Utility/CompletionRequest.h" #include "lldb/Utility/FileSpec.h" #include "lldb/Utility/LLDBAssert.h" @@ -114,22 +115,21 @@ // - The H_FIRST returns the most recent entry in the history. // // The naming of the enum entries match the semantic meaning. - switch(op) { -case HistoryOperation::Oldest: - return H_LAST; -case HistoryOperation::Older: - return H_NEXT; -case HistoryOperation::Current: - return H_CURR; -case HistoryOperation::Newer: - return H_PREV; -case HistoryOperation::Newest: - return H_FIRST; + switch (op) { + case HistoryOperation::Oldest: +return H_LAST; + case HistoryOperation::Older: +return H_NEXT; + case HistoryOperation::Current: +return H_CURR; + case HistoryOperation::Newer: +return H_PREV; + case HistoryOperation::Newest: +return H_FIRST; } llvm_unreachable("Fully covered switch!"); } - EditLineStringType CombineLines(const std::vector &lines) { EditLineStringStreamType combined_stream; for (EditLineStringType line : lines) { @@ -296,8 +296,8 @@ // to use when loading/saving history std::string m_path; // Path to the history file }; -} -} +} // namespace line_editor +} // namespace lldb_private // Editline private methods @@ -415,9 +415,10 @@ const char *unfaint = m_color_prompts ? ANSI_UNFAINT : ""; for (int index = firstIndex; index < line_count; index++) { -fprintf(m_output_file, "%s" - "%s" - "%s" EditLineStringFormatSpec " ", +fprintf(m_output_file, +"%s" +"%s" +"%s" EditLineStringFormatSpec " ", faint, PromptForIndex(index).c_str(), unfaint, m_input_lines[index].c_str()); if (index < line_count - 1) @@ -532,9 +533,10 @@ // (will only be requested if colors are supported) if (m_needs_prompt_repaint) { MoveCursor(CursorLocation::EditingCursor, CursorLocation::EditingPrompt); -fprintf(m_output_file, "%s" - "%s" - "%s", +fprintf(m_output_file, +"%s" +"%s" +"%s", ANSI_FAINT, Prompt(), ANSI_UNFAINT); MoveCursor(CursorLocation::EditingPrompt, CursorLocation::EditingCursor); m_needs_prompt_repaint = false; @@ -1040,6 +1042,77 @@ return CC_REDISPLAY; } +std::string Editline::AutoSuggest(std::string typed) { + const LineInfo *line_info = el_line(m_editline); + + llvm::StringRef line(line_info->buffer, + line_info->lastchar - line_info->buffer); + unsigned cursor_index = line_info->cursor - line_info->buffer; + CompletionResult result; + CompletionRequest request(line, cursor_index, result); + + m_completion_callback(request, m_completion_callback_baton); + + llvm::ArrayRef results = result.GetResults(); + + StringList completions; + result.GetMatches(completions); + + std::string to_add = ""; + + if (results.size() == 1) { +CompletionResult::Completion completion = results.front(); +switch (completion.GetMode()) { +case CompletionMode::Normal: { + to_add = completion.GetCompletion(); + to_add = to_add.substr(request.GetCursorArgumentPrefix().size()); + if (request.GetParsedArg().IsQuoted()) +to_add.push_back(request.GetParsedArg().GetQuoteChar()); + to_add.push_back(' '); + break; +} +case CompletionMode::Partial: { + std::string to_add = completion.GetCompletion(); + to_add = to_add.substr(request.GetCursorArgumentPrefix().size()); + break; +} +case CompletionMode::RewriteLine: { + el_deletestr(m_editline, line_info->cursor - line_info->buffer); + el_insertstr(m_editline, completion.GetComp
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 added inline comments. Comment at: lldb/source/Core/Debugger.cpp:349 +bool Debugger::GetUseAutosuggestion() const { + const uint32_t idx = ePropertyShowAutosuggestion; teemperor wrote: > You declared the function, but you don't use it anywhere. You should move all > the code you added behind `if (GetShowAutosuggestion())` so that it is only > active if the user activated the setting (by doing `settings set > show-autosuggestion true`). Sorry, would you tell me more about it? I understood that I did not use this function, but I do not know how to validate it. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 added inline comments. Comment at: lldb/source/Host/common/Editline.cpp:1244 +llvm::StringRef indent_chars = +"abcdefghijklmnopqrstuvwxzyABCDEFGHIJKLMNOPQRSTUVWXZY1234567890 "; +for (char c : indent_chars) { teemperor wrote: > `.-/()[]{};\"'\\!@#$%^&*_` are missing here. Maybe we should just iterate > over all ASCII characters and add all printables except newline or something > like that to the alphabet. If I add -, \, and ^, an error occurs because these characters are probably used in other forms like -a (ll. 1283), \n (ll.1253), and ^p (ll.1257). Do you know good ways to avoid it? CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 updated this revision to Diff 270454. gedatsu217 added a comment. I updated my codes according to your advice: Add if(GetUseAutosuggestion()) in IOHandlerSuggestion in IOHandler.cpp. (Is this not enough?) Add more keybinds for TypedCharacter. Return llvm::Optional in HandleSuggestion in CommandInterpreter.cpp. and several minor change... CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 Files: lldb/include/lldb/Core/Debugger.h lldb/include/lldb/Core/IOHandler.h lldb/include/lldb/Host/Editline.h lldb/include/lldb/Interpreter/CommandInterpreter.h lldb/source/Core/CoreProperties.td lldb/source/Core/Debugger.cpp lldb/source/Core/IOHandler.cpp lldb/source/Host/common/Editline.cpp lldb/source/Interpreter/CommandInterpreter.cpp Index: lldb/source/Interpreter/CommandInterpreter.cpp === --- lldb/source/Interpreter/CommandInterpreter.cpp +++ lldb/source/Interpreter/CommandInterpreter.cpp @@ -1866,6 +1866,21 @@ HandleCompletionMatches(request); } +llvm::Optional +CommandInterpreter::GetAutoSuggestionForCommand(llvm::StringRef line, +std::string &result) { + const size_t s = m_command_history.GetSize(); + for (size_t i = 0; i < s; ++i) { +llvm::StringRef entry = m_command_history.GetStringAtIndex(i); +if (entry.startswith(line)) { + llvm::StringRef res = entry.substr(line.size()); + result = res.str(); + return result; +} + } + return llvm::None; +} + CommandInterpreter::~CommandInterpreter() {} void CommandInterpreter::UpdatePrompt(llvm::StringRef new_prompt) { Index: lldb/source/Host/common/Editline.cpp === --- lldb/source/Host/common/Editline.cpp +++ lldb/source/Host/common/Editline.cpp @@ -14,6 +14,7 @@ #include "lldb/Host/Editline.h" #include "lldb/Host/FileSystem.h" #include "lldb/Host/Host.h" +#include "lldb/Utility/AnsiTerminal.h" #include "lldb/Utility/CompletionRequest.h" #include "lldb/Utility/FileSpec.h" #include "lldb/Utility/LLDBAssert.h" @@ -1040,6 +1041,36 @@ return CC_REDISPLAY; } +unsigned char Editline::ApplyCompleteCommand(int ch) { + el_insertstr(m_editline, m_current_autosuggestion.c_str()); + m_current_autosuggestion = ""; + return CC_REDISPLAY; +} + +unsigned char Editline::TypedCharacter(int ch) { + std::string typed = std::string(1, ch); + el_insertstr(m_editline, typed.c_str()); + const LineInfo *line_info = el_line(m_editline); + llvm::StringRef line(line_info->buffer, + line_info->lastchar - line_info->buffer); + + std::string to_add; + m_suggestion_callback(line, to_add, m_suggestion_callback_baton); + m_current_autosuggestion = to_add; + + if (to_add.empty()) +return CC_REDISPLAY; + + std::string to_add_color = ansi::FormatAnsiTerminalCodes("${ansi.faint}") + + to_add + + ansi::FormatAnsiTerminalCodes("${ansi.normal}"); + fputs(typed.c_str(), m_output_file); + fputs(to_add_color.c_str(), m_output_file); + MoveCursor(CursorLocation::BlockEnd, CursorLocation::EditingPrompt); + + return CC_REFRESH; +} + void Editline::ConfigureEditor(bool multiline) { if (m_editline && m_multiline_enabled == multiline) return; @@ -1159,6 +1190,21 @@ el_set(m_editline, EL_BIND, "\t", "lldb-complete", NULL); // Bind TAB to auto complete + el_wset(m_editline, EL_ADDFN, EditLineConstString("lldb-apply-complete"), + EditLineConstString("Adopt autocompletion"), + (EditlineCommandCallbackType)([](EditLine *editline, int ch) { +return Editline::InstanceFor(editline)->ApplyCompleteCommand(ch); + })); + + el_set(m_editline, EL_BIND, "^f", "lldb-apply-complete", + NULL); // Apply a part that is suggested automatically + + el_wset(m_editline, EL_ADDFN, EditLineConstString("lldb-typed-character"), + EditLineConstString("Typed character"), + (EditlineCommandCallbackType)([](EditLine *editline, int ch) { +return Editline::InstanceFor(editline)->TypedCharacter(ch); + })); + // Allow ctrl-left-arrow and ctrl-right-arrow for navigation, behave like // bash in emacs mode. el_set(m_editline, EL_BIND, ESCAPE "[1;5C", "em-next-word", NULL); @@ -1190,6 +1236,17 @@ } } + if (true) { +char bind_key[2] = {0, 0}; +llvm::StringRef indent_chars = +"abcdefghijklmnopqrstuvwxzyABCDEFGHIJKLMNOPQRSTUVWXZY1234567890!\"#$%&'" +"()*+,./:;<=>?@[]_`{|}~ "; +for (char c : indent_chars) { + bind_key[0] = c; + el_set(m_editline, EL_BIND, bind_key, "lldb-typed-character", NULL); +} + } + // Multi-line editor bindings if (multiline) { el_set(m_editline, EL_BIND, "\n", "lldb-end-or-add-line", NULL); @@ -1364,6 +1421,12 @@ return result; } +void Editline::Se
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 updated this revision to Diff 271146. gedatsu217 added a comment. Implementation all ascii characters for TypedCharacter. Making m_use_autosuggestion in Editline.cpp. (I did not know a way to pass the bool value of IOHandlerEditline to Editline constructor, so I made a function, Editline::UseAutosuggestion, in Editline class. If the autosuggestion is valid, this function is called from IOHandlerEditline constructor. Is this implementation good?) > You can test it by just doing settings set show-autosuggestion true (which > should activate this) and settings set show-autosuggestion true (which should > deactivate this). It's fine if LLDB requires a restart to do activate this > setting (that's to my knowledge a limitation of the current way the > IOHandlers work). "restart" means that excuting "quit" in LLDB and executing "bin/lldb" again in Terminal? I made m_use_autosuggestion in Editline.cpp and it goes well when show-autosuggestion is DefaultTrue. However, when show-autosuggestion is DefaultFalse and executing "settings set show-autosuggestion true", autosuggestion does not work well. Do you know what causes it? In addition, > There's no way to confirm the autosuggestion. In fish you can use right-arrow > or a key to move to the end of the line (END, CTRL-E). If you press CTRL-F, you probably confirm the autosuggestion. > The interaction between the autocompletion and autosuggestion is rather > confusing. Fish solves this by showing the autocompletion under the current > line. I don't we need to take it that far, but at least the the situation > described below should work. I added some codes in TabCommand in Editline.cpp so that autosuggestion still show up after the completion when there is a possible completion. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 Files: lldb/include/lldb/Core/Debugger.h lldb/include/lldb/Core/IOHandler.h lldb/include/lldb/Host/Editline.h lldb/include/lldb/Interpreter/CommandInterpreter.h lldb/source/Core/CoreProperties.td lldb/source/Core/Debugger.cpp lldb/source/Core/IOHandler.cpp lldb/source/Host/common/Editline.cpp lldb/source/Interpreter/CommandInterpreter.cpp Index: lldb/source/Interpreter/CommandInterpreter.cpp === --- lldb/source/Interpreter/CommandInterpreter.cpp +++ lldb/source/Interpreter/CommandInterpreter.cpp @@ -1866,6 +1866,21 @@ HandleCompletionMatches(request); } +llvm::Optional +CommandInterpreter::GetAutoSuggestionForCommand(llvm::StringRef line, +std::string &result) { + const size_t s = m_command_history.GetSize(); + for (size_t i = 0; i < s; ++i) { +llvm::StringRef entry = m_command_history.GetStringAtIndex(i); +if (entry.startswith(line)) { + llvm::StringRef res = entry.substr(line.size()); + result = res.str(); + return result; +} + } + return llvm::None; +} + CommandInterpreter::~CommandInterpreter() {} void CommandInterpreter::UpdatePrompt(llvm::StringRef new_prompt) { Index: lldb/source/Host/common/Editline.cpp === --- lldb/source/Host/common/Editline.cpp +++ lldb/source/Host/common/Editline.cpp @@ -14,6 +14,7 @@ #include "lldb/Host/Editline.h" #include "lldb/Host/FileSystem.h" #include "lldb/Host/Host.h" +#include "lldb/Utility/AnsiTerminal.h" #include "lldb/Utility/CompletionRequest.h" #include "lldb/Utility/FileSpec.h" #include "lldb/Utility/LLDBAssert.h" @@ -1004,6 +1005,17 @@ to_add = to_add.substr(request.GetCursorArgumentPrefix().size()); if (request.GetParsedArg().IsQuoted()) to_add.push_back(request.GetParsedArg().GetQuoteChar()); + if (m_use_autosuggestion) { +int length = (int)(to_add.length()); +if ((int)(m_current_autosuggestion.length()) > length && +to_add == m_current_autosuggestion.substr(0, length)) { + to_add.push_back(' '); + el_insertstr(m_editline, to_add.c_str()); + m_current_autosuggestion = + m_current_autosuggestion.substr(length + 1); + return CC_REFRESH; +} + } to_add.push_back(' '); el_insertstr(m_editline, to_add.c_str()); break; @@ -1020,6 +1032,7 @@ break; } } +m_current_autosuggestion = ""; return CC_REDISPLAY; } @@ -1040,6 +1053,36 @@ return CC_REDISPLAY; } +unsigned char Editline::ApplyCompleteCommand(int ch) { + el_insertstr(m_editline, m_current_autosuggestion.c_str()); + m_current_autosuggestion = ""; + return CC_REDISPLAY; +} + +unsigned char Editline::TypedCharacter(int ch) { + std::string typed = std::string(1, ch); + el_insertstr(m_editline, typed.c_str()); + const LineInfo *line_info = el_line(m_editline); + llvm::StringRef line(line_info->buffer, + line_info->lastchar - line_
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 updated this revision to Diff 272479. gedatsu217 added a comment. Change the name and return of the function( bool UseAutosuggestion() -> void SetShowAutosuggestion (bool) ) (ll. 1447 in Editline.cpp and ll.194 in Editline.h). int -> size_t (ll. 1009 in Editline.cpp). Fix for normal setter (ll. 269 in IOHandler.cpp). > The Editline instance isn't recreated when you change the settings, so you > need to restart LLDB for this to work. However, settings aren't automatically > saved, so I think the right way to do this by putting the settings set > show-autosuggestion true into the ~/.lldbinit file (which will be > automatically executed before LLDB's command line frontend starts). It > probably requires a bunch of work to get that working without a restart, so I > think this can be fixed as a follow-up. There is no ~/.lldbinit in my environment (I do not why). Instead, there is ~/.lldb directory (but there are just command history file there.). > On a more general note: I'm not sure why we need m_current_autosuggestion. > There is a bunch of code that tries to keep that variable up-to-date with > what is typed, but unless I'm missing something this is just the text the > user has entered so far? If yes, then you can also just get the current user > input from Editline (see the first few lines of the Editline::TabCommand > function for how to do that). I think "m_current_autosuggestion" is needed. That is because it keeps the characters for the suggestion, not just user input. For example, when "b" is typed, "reakpoint" is saved in m_current_autosuggestion (when "breakpoint" is typed before). When a character is typed, Editline::TypedCharacter is called and m_current_autosuggestion is renewed every time. On the other hand, Editline::ApplyCompleteCommand, which execute suggestion actually, is not called unless C^f is typed. Therefore I think the suggestion parts should be saved until it is called. Indeed, I can get current user input by the first few lines of the Editline::TabCommand function, but it cannot save the suggestion parts probably. However, I noticed that "to_add" in Editline::TypedCharacter is unnecessary, so removeed it. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 Files: lldb/include/lldb/Core/Debugger.h lldb/include/lldb/Core/IOHandler.h lldb/include/lldb/Host/Editline.h lldb/include/lldb/Interpreter/CommandInterpreter.h lldb/source/Core/CoreProperties.td lldb/source/Core/Debugger.cpp lldb/source/Core/IOHandler.cpp lldb/source/Host/common/Editline.cpp lldb/source/Interpreter/CommandInterpreter.cpp Index: lldb/source/Interpreter/CommandInterpreter.cpp === --- lldb/source/Interpreter/CommandInterpreter.cpp +++ lldb/source/Interpreter/CommandInterpreter.cpp @@ -1866,6 +1866,21 @@ HandleCompletionMatches(request); } +llvm::Optional +CommandInterpreter::GetAutoSuggestionForCommand(llvm::StringRef line, +std::string &result) { + const size_t s = m_command_history.GetSize(); + for (size_t i = 0; i < s; ++i) { +llvm::StringRef entry = m_command_history.GetStringAtIndex(i); +if (entry.startswith(line)) { + llvm::StringRef res = entry.substr(line.size()); + result = res.str(); + return result; +} + } + return llvm::None; +} + CommandInterpreter::~CommandInterpreter() {} void CommandInterpreter::UpdatePrompt(llvm::StringRef new_prompt) { Index: lldb/source/Host/common/Editline.cpp === --- lldb/source/Host/common/Editline.cpp +++ lldb/source/Host/common/Editline.cpp @@ -14,6 +14,7 @@ #include "lldb/Host/Editline.h" #include "lldb/Host/FileSystem.h" #include "lldb/Host/Host.h" +#include "lldb/Utility/AnsiTerminal.h" #include "lldb/Utility/CompletionRequest.h" #include "lldb/Utility/FileSpec.h" #include "lldb/Utility/LLDBAssert.h" @@ -1004,6 +1005,17 @@ to_add = to_add.substr(request.GetCursorArgumentPrefix().size()); if (request.GetParsedArg().IsQuoted()) to_add.push_back(request.GetParsedArg().GetQuoteChar()); + if (m_use_autosuggestion && !to_add.empty()) { +size_t length = to_add.length(); +if (m_current_autosuggestion.length() > length && +to_add == m_current_autosuggestion.substr(0, length)) { + to_add.push_back(' '); + el_insertstr(m_editline, to_add.c_str()); + m_current_autosuggestion = + m_current_autosuggestion.substr(length + 1); + return CC_REFRESH; +} + } to_add.push_back(' '); el_insertstr(m_editline, to_add.c_str()); break; @@ -1020,6 +1032,7 @@ break; } } +m_current_autosuggestion = ""; return CC_REDISPLAY; } @@ -1040,6 +1053,36 @@ return CC_REDISPLAY; } +unsigned char Editline::ApplyCom
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 added inline comments. Comment at: lldb/source/Interpreter/CommandInterpreter.cpp:1875-1878 +if (entry.startswith(line)) { + llvm::StringRef res = entry.substr(line.size()); + result = res.str(); + return result; labath wrote: > ``` > if (entry.consume_front(line)) { > result = entry.str(); > return result; // Why is this returning the result both as a proper return > value and a by-ref argument? > } > ``` That is because using the llvm::Optional as a return value instead of void would make it more obvious what the function returns in case there is no suggestion. We've discussed this issue before, so please see the comments above. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 added a comment. I understood what you said. Sorry, I misunderstood it. Indeed, m_current_autosuggestion is not good for the future. I will get the current user input every time calling ApplyCompleteCommand instead of using m_current_autosuggestion. By the way, when I use llvm::Optional as a return, how do I receive it? I want to receive the result in IOHandlerDelegate::IOHandlerSuggestion. If I write "result = ...GetAutoSuggestionForCommand(line)", an error, "no viable overloaded '='", occurs. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 updated this revision to Diff 273349. gedatsu217 added a comment. I revised the code according to your advice. In addition, llvm::Optional was originally returned in CommandInterpreter::GetAutoSuggestionForCommand, but it seems to useless that converting llvm::Optional to std::string in the function, so I changed return value. > By the way, when I use llvm::Optional as a return, how do I > receive it? I want to receive the result in > IOHandlerDelegate::IOHandlerSuggestion. If I write "result = > ...GetAutoSuggestionForCommand(line)", an error, "no viable overloaded '='", > occurs. This problem was solved. (I forgot about llvm::None, sorry.) CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 Files: lldb/include/lldb/Core/Debugger.h lldb/include/lldb/Core/IOHandler.h lldb/include/lldb/Host/Editline.h lldb/include/lldb/Interpreter/CommandInterpreter.h lldb/source/Core/CoreProperties.td lldb/source/Core/Debugger.cpp lldb/source/Core/IOHandler.cpp lldb/source/Host/common/Editline.cpp lldb/source/Interpreter/CommandInterpreter.cpp Index: lldb/source/Interpreter/CommandInterpreter.cpp === --- lldb/source/Interpreter/CommandInterpreter.cpp +++ lldb/source/Interpreter/CommandInterpreter.cpp @@ -1866,6 +1866,17 @@ HandleCompletionMatches(request); } +llvm::Optional +CommandInterpreter::GetAutoSuggestionForCommand(llvm::StringRef line) { + const size_t s = m_command_history.GetSize(); + for (size_t i = 0; i < s; ++i) { +llvm::StringRef entry = m_command_history.GetStringAtIndex(i); +if (entry.consume_front(line)) + return entry; + } + return llvm::None; +} + CommandInterpreter::~CommandInterpreter() {} void CommandInterpreter::UpdatePrompt(llvm::StringRef new_prompt) { Index: lldb/source/Host/common/Editline.cpp === --- lldb/source/Host/common/Editline.cpp +++ lldb/source/Host/common/Editline.cpp @@ -14,6 +14,7 @@ #include "lldb/Host/Editline.h" #include "lldb/Host/FileSystem.h" #include "lldb/Host/Host.h" +#include "lldb/Utility/AnsiTerminal.h" #include "lldb/Utility/CompletionRequest.h" #include "lldb/Utility/FileSpec.h" #include "lldb/Utility/LLDBAssert.h" @@ -1002,8 +1003,20 @@ case CompletionMode::Normal: { std::string to_add = completion.GetCompletion(); to_add = to_add.substr(request.GetCursorArgumentPrefix().size()); + std::string to_add_autosuggestion = ""; + m_suggestion_callback(line, to_add_autosuggestion, +m_suggestion_callback_baton); if (request.GetParsedArg().IsQuoted()) to_add.push_back(request.GetParsedArg().GetQuoteChar()); + if (!to_add_autosuggestion.empty() && !to_add.empty()) { +size_t length = to_add.length(); +if (to_add_autosuggestion.length() > length && +to_add == to_add_autosuggestion.substr(0, length)) { + to_add.push_back(' '); + el_insertstr(m_editline, to_add.c_str()); + return CC_REFRESH; +} + } to_add.push_back(' '); el_insertstr(m_editline, to_add.c_str()); break; @@ -1040,6 +1053,43 @@ return CC_REDISPLAY; } +unsigned char Editline::ApplyCompleteCommand(int ch) { + const LineInfo *line_info = el_line(m_editline); + llvm::StringRef line(line_info->buffer, + line_info->lastchar - line_info->buffer); + std::string to_add = ""; + m_suggestion_callback(line, to_add, m_suggestion_callback_baton); + + if (to_add.empty()) +return CC_REFRESH; + + el_insertstr(m_editline, to_add.c_str()); + return CC_REDISPLAY; +} + +unsigned char Editline::TypedCharacter(int ch) { + std::string typed = std::string(1, ch); + el_insertstr(m_editline, typed.c_str()); + const LineInfo *line_info = el_line(m_editline); + llvm::StringRef line(line_info->buffer, + line_info->lastchar - line_info->buffer); + + std::string to_add = ""; + m_suggestion_callback(line, to_add, m_suggestion_callback_baton); + + if (to_add.empty()) +return CC_REDISPLAY; + + std::string to_add_color = ansi::FormatAnsiTerminalCodes("${ansi.faint}") + + to_add + + ansi::FormatAnsiTerminalCodes("${ansi.normal}"); + fputs(typed.c_str(), m_output_file); + fputs(to_add_color.c_str(), m_output_file); + MoveCursor(CursorLocation::BlockEnd, CursorLocation::EditingPrompt); + + return CC_REFRESH; +} + void Editline::ConfigureEditor(bool multiline) { if (m_editline && m_multiline_enabled == multiline) return; @@ -1153,7 +1203,38 @@ if (!multiline) { el_set(m_editline, EL_BIND, "^r", "em-inc-search-prev", NULL); // Cycle through backwards search, entering string + +if (m_use_autosuggestion) { + el_wset(m_editline, EL_ADDFN, EditLineConstString("lldb-apply-complete"), +
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 marked an inline comment as done. gedatsu217 added inline comments. Comment at: lldb/source/Host/common/Editline.cpp:1017 + el_insertstr(m_editline, to_add.c_str()); + return CC_REFRESH; +} teemperor wrote: > If I understand the only effect this whole code has is to return CC_REFRESH > instead of CC_REDISPLAY? If yes, then I think you can just replace the > `break` below with `return CC_REFRESH;` which will be much simpler. > If yes, then I think you can just replace the break below with return > CC_REFRESH; which will be much simpler. Isn't it "return CC_REDISPLAY", not "CC_REFRESH"? I want to return CC_REFRESH only when "to_add" is in "to_add_autosuggestion" (e.g. to_add = b, to_add_autosuggestion = "breakpoint"). That is because CC_REDISPLAY deletes the gray-colored autosuggested part, while CC_REFRESH leaves it. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 updated this revision to Diff 276468. gedatsu217 added a comment. I fixed the code according to your advice. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 Files: lldb/include/lldb/Core/Debugger.h lldb/include/lldb/Core/IOHandler.h lldb/include/lldb/Host/Editline.h lldb/include/lldb/Interpreter/CommandInterpreter.h lldb/source/Core/CoreProperties.td lldb/source/Core/Debugger.cpp lldb/source/Core/IOHandler.cpp lldb/source/Host/common/Editline.cpp lldb/source/Interpreter/CommandInterpreter.cpp Index: lldb/source/Interpreter/CommandInterpreter.cpp === --- lldb/source/Interpreter/CommandInterpreter.cpp +++ lldb/source/Interpreter/CommandInterpreter.cpp @@ -1866,6 +1866,17 @@ HandleCompletionMatches(request); } +llvm::Optional +CommandInterpreter::GetAutoSuggestionForCommand(llvm::StringRef line) { + const size_t s = m_command_history.GetSize(); + for (size_t i = 0; i < s; ++i) { +llvm::StringRef entry = m_command_history.GetStringAtIndex(i); +if (entry.consume_front(line)) + return entry.str(); + } + return llvm::None; +} + CommandInterpreter::~CommandInterpreter() {} void CommandInterpreter::UpdatePrompt(llvm::StringRef new_prompt) { Index: lldb/source/Host/common/Editline.cpp === --- lldb/source/Host/common/Editline.cpp +++ lldb/source/Host/common/Editline.cpp @@ -14,6 +14,7 @@ #include "lldb/Host/Editline.h" #include "lldb/Host/FileSystem.h" #include "lldb/Host/Host.h" +#include "lldb/Utility/AnsiTerminal.h" #include "lldb/Utility/CompletionRequest.h" #include "lldb/Utility/FileSpec.h" #include "lldb/Utility/LLDBAssert.h" @@ -1002,8 +1003,20 @@ case CompletionMode::Normal: { std::string to_add = completion.GetCompletion(); to_add = to_add.substr(request.GetCursorArgumentPrefix().size()); + std::string to_add_autosuggestion = ""; + m_suggestion_callback(line, to_add_autosuggestion, +m_suggestion_callback_baton); if (request.GetParsedArg().IsQuoted()) to_add.push_back(request.GetParsedArg().GetQuoteChar()); + if (!to_add_autosuggestion.empty() && !to_add.empty()) { +size_t length = to_add.length(); +if (to_add_autosuggestion.length() > length && +to_add == to_add_autosuggestion.substr(0, length)) { + to_add.push_back(' '); + el_insertstr(m_editline, to_add.c_str()); + return CC_REFRESH; +} + } to_add.push_back(' '); el_insertstr(m_editline, to_add.c_str()); break; @@ -1040,6 +1053,43 @@ return CC_REDISPLAY; } +unsigned char Editline::ApplyAutosuggestCommand(int ch) { + const LineInfo *line_info = el_line(m_editline); + llvm::StringRef line(line_info->buffer, + line_info->lastchar - line_info->buffer); + std::string to_add = ""; + m_suggestion_callback(line, to_add, m_suggestion_callback_baton); + + if (to_add.empty()) +return CC_REFRESH; + + el_insertstr(m_editline, to_add.c_str()); + return CC_REDISPLAY; +} + +unsigned char Editline::TypedCharacter(int ch) { + std::string typed = std::string(1, ch); + el_insertstr(m_editline, typed.c_str()); + const LineInfo *line_info = el_line(m_editline); + llvm::StringRef line(line_info->buffer, + line_info->lastchar - line_info->buffer); + + std::string to_add = ""; + m_suggestion_callback(line, to_add, m_suggestion_callback_baton); + + if (to_add.empty()) +return CC_REDISPLAY; + + std::string to_add_color = ansi::FormatAnsiTerminalCodes("${ansi.faint}") + + to_add + + ansi::FormatAnsiTerminalCodes("${ansi.normal}"); + fputs(typed.c_str(), m_output_file); + fputs(to_add_color.c_str(), m_output_file); + MoveCursor(CursorLocation::BlockEnd, CursorLocation::EditingPrompt); + + return CC_REFRESH; +} + void Editline::ConfigureEditor(bool multiline) { if (m_editline && m_multiline_enabled == multiline) return; @@ -1153,7 +1203,38 @@ if (!multiline) { el_set(m_editline, EL_BIND, "^r", "em-inc-search-prev", NULL); // Cycle through backwards search, entering string + +if (m_suggestion_callback) { + el_wset(m_editline, EL_ADDFN, EditLineConstString("lldb-apply-complete"), + EditLineConstString("Adopt autocompletion"), + (EditlineCommandCallbackType)([](EditLine *editline, int ch) { +return Editline::InstanceFor(editline)->ApplyAutosuggestCommand( +ch); + })); + + el_set(m_editline, EL_BIND, "^f", "lldb-apply-complete", + NULL); // Apply a part that is suggested automatically + + el_wset(m_editline, EL_ADDFN, EditLineConstString("lldb-typed-character"), + EditLineConstString("Typed character"), +
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 marked an inline comment as done. gedatsu217 added inline comments. Comment at: lldb/source/Host/common/Editline.cpp:1017 + el_insertstr(m_editline, to_add.c_str()); + return CC_REFRESH; +} teemperor wrote: > gedatsu217 wrote: > > teemperor wrote: > > > If I understand the only effect this whole code has is to return > > > CC_REFRESH instead of CC_REDISPLAY? If yes, then I think you can just > > > replace the `break` below with `return CC_REFRESH;` which will be much > > > simpler. > > > If yes, then I think you can just replace the break below with return > > > CC_REFRESH; which will be much simpler. > > > > Isn't it "return CC_REDISPLAY", not "CC_REFRESH"? I want to return > > CC_REFRESH only when "to_add" is in "to_add_autosuggestion" (e.g. to_add = > > b, to_add_autosuggestion = "breakpoint"). > > > > That is because CC_REDISPLAY deletes the gray-colored autosuggested part, > > while CC_REFRESH leaves it. > > > > > I see. What about just retuning always `CC_REFRESH` here? That should work as > we only add text to the end with a normal completion (which is IIRC that's > what `CC_REFRESH` is for, but > > ``` > lang=c++ > case CompletionMode::Normal: { > std::string to_add = completion.GetCompletion(); > to_add = to_add.substr(request.GetCursorArgumentPrefix().size()); > std::string to_add_autosuggestion = ""; > to_add.push_back(' '); > el_insertstr(m_editline, to_add.c_str()); > return CC_REFRESH; > } > ``` > > That seems to work for me (and it avoids the crash I pointed out above). > > Also my main point here is that this is quite a large change just to change > the return value (and the other tab completions below aren't covered and > would need similar changes if we do this change). Where is "to_add_autosuggestion" used in the above example? CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 marked an inline comment as done. gedatsu217 added inline comments. Comment at: lldb/source/Host/common/Editline.cpp:1017 + el_insertstr(m_editline, to_add.c_str()); + return CC_REFRESH; +} teemperor wrote: > gedatsu217 wrote: > > teemperor wrote: > > > gedatsu217 wrote: > > > > teemperor wrote: > > > > > If I understand the only effect this whole code has is to return > > > > > CC_REFRESH instead of CC_REDISPLAY? If yes, then I think you can just > > > > > replace the `break` below with `return CC_REFRESH;` which will be > > > > > much simpler. > > > > > If yes, then I think you can just replace the break below with return > > > > > CC_REFRESH; which will be much simpler. > > > > > > > > Isn't it "return CC_REDISPLAY", not "CC_REFRESH"? I want to return > > > > CC_REFRESH only when "to_add" is in "to_add_autosuggestion" (e.g. > > > > to_add = b, to_add_autosuggestion = "breakpoint"). > > > > > > > > That is because CC_REDISPLAY deletes the gray-colored autosuggested > > > > part, while CC_REFRESH leaves it. > > > > > > > > > > > I see. What about just retuning always `CC_REFRESH` here? That should > > > work as we only add text to the end with a normal completion (which is > > > IIRC that's what `CC_REFRESH` is for, but > > > > > > ``` > > > lang=c++ > > > case CompletionMode::Normal: { > > > std::string to_add = completion.GetCompletion(); > > > to_add = to_add.substr(request.GetCursorArgumentPrefix().size()); > > > std::string to_add_autosuggestion = ""; > > > to_add.push_back(' '); > > > el_insertstr(m_editline, to_add.c_str()); > > > return CC_REFRESH; > > > } > > > ``` > > > > > > That seems to work for me (and it avoids the crash I pointed out above). > > > > > > Also my main point here is that this is quite a large change just to > > > change the return value (and the other tab completions below aren't > > > covered and would need similar changes if we do this change). > > Where is "to_add_autosuggestion" used in the above example? > Yeah, you could also remove that: > > ``` > lang=c++ > case CompletionMode::Normal: { > std::string to_add = completion.GetCompletion(); > to_add = to_add.substr(request.GetCursorArgumentPrefix().size()); > to_add.push_back(' '); > el_insertstr(m_editline, to_add.c_str()); > return CC_REFRESH; > } > ``` > > (So, changing `break;` -> `return CC_REFRESH;` seems to be enough in this > situation). CC_REFRESH should be fine for both normal completion and when we > add the autosuggestion string afterwards if I understand the meaning of it > correctly. Now I get it. Thanks. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 updated this revision to Diff 278580. gedatsu217 added a comment. Remove extra parts in Editline::TabCommand in Editline.cpp. Add a test for the autosuggestion. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 Files: lldb/include/lldb/Core/Debugger.h lldb/include/lldb/Core/IOHandler.h lldb/include/lldb/Host/Editline.h lldb/include/lldb/Interpreter/CommandInterpreter.h lldb/source/Core/CoreProperties.td lldb/source/Core/Debugger.cpp lldb/source/Core/IOHandler.cpp lldb/source/Host/common/Editline.cpp lldb/source/Interpreter/CommandInterpreter.cpp lldb/test/API/iohandler/autosuggestion/TestAutosuggestion.py Index: lldb/test/API/iohandler/autosuggestion/TestAutosuggestion.py === --- /dev/null +++ lldb/test/API/iohandler/autosuggestion/TestAutosuggestion.py @@ -0,0 +1,35 @@ +""" +Tests autosuggestion using pexpect. +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test.lldbpexpect import PExpectTest + +class TestCase(PExpectTest): + +mydir = TestBase.compute_mydir(__file__) + +# PExpect uses many timeouts internally and doesn't play well +# under ASAN on a loaded machine.. +@skipIfAsan +@skipIfEditlineSupportMissing +def test_autosuggestion(self): +self.launch() + +# Execute "help frame" and register it as a history. +self.child.send("help frame") +self.child.expect_exact("help frame") + +# Try autosuggestion using ^f. +self.child.send("hel\x06") +self.child.expect_exact("help frame") + +# Try autosuggestion using tab and ^f. +# \t makes "help" and ^f makes "help frame". +self.child.send("hel\t\x06") +self.child.expect_exact("help frame") + +self.quit() + \ No newline at end of file Index: lldb/source/Interpreter/CommandInterpreter.cpp === --- lldb/source/Interpreter/CommandInterpreter.cpp +++ lldb/source/Interpreter/CommandInterpreter.cpp @@ -1866,6 +1866,17 @@ HandleCompletionMatches(request); } +llvm::Optional +CommandInterpreter::GetAutoSuggestionForCommand(llvm::StringRef line) { + const size_t s = m_command_history.GetSize(); + for (size_t i = 0; i < s; ++i) { +llvm::StringRef entry = m_command_history.GetStringAtIndex(i); +if (entry.consume_front(line)) + return entry.str(); + } + return llvm::None; +} + CommandInterpreter::~CommandInterpreter() {} void CommandInterpreter::UpdatePrompt(llvm::StringRef new_prompt) { Index: lldb/source/Host/common/Editline.cpp === --- lldb/source/Host/common/Editline.cpp +++ lldb/source/Host/common/Editline.cpp @@ -14,6 +14,7 @@ #include "lldb/Host/Editline.h" #include "lldb/Host/FileSystem.h" #include "lldb/Host/Host.h" +#include "lldb/Utility/AnsiTerminal.h" #include "lldb/Utility/CompletionRequest.h" #include "lldb/Utility/FileSpec.h" #include "lldb/Utility/LLDBAssert.h" @@ -1006,7 +1007,7 @@ to_add.push_back(request.GetParsedArg().GetQuoteChar()); to_add.push_back(' '); el_insertstr(m_editline, to_add.c_str()); - break; + return CC_REFRESH; } case CompletionMode::Partial: { std::string to_add = completion.GetCompletion(); @@ -1040,6 +1041,43 @@ return CC_REDISPLAY; } +unsigned char Editline::ApplyAutosuggestCommand(int ch) { + const LineInfo *line_info = el_line(m_editline); + llvm::StringRef line(line_info->buffer, + line_info->lastchar - line_info->buffer); + std::string to_add = ""; + m_suggestion_callback(line, to_add, m_suggestion_callback_baton); + + if (to_add.empty()) +return CC_REFRESH; + + el_insertstr(m_editline, to_add.c_str()); + return CC_REDISPLAY; +} + +unsigned char Editline::TypedCharacter(int ch) { + std::string typed = std::string(1, ch); + el_insertstr(m_editline, typed.c_str()); + const LineInfo *line_info = el_line(m_editline); + llvm::StringRef line(line_info->buffer, + line_info->lastchar - line_info->buffer); + + std::string to_add = ""; + m_suggestion_callback(line, to_add, m_suggestion_callback_baton); + + if (to_add.empty()) +return CC_REDISPLAY; + + std::string to_add_color = ansi::FormatAnsiTerminalCodes("${ansi.faint}") + + to_add + + ansi::FormatAnsiTerminalCodes("${ansi.normal}"); + fputs(typed.c_str(), m_output_file); + fputs(to_add_color.c_str(), m_output_file); + MoveCursor(CursorLocation::BlockEnd, CursorLocation::EditingPrompt); + + return CC_REFRESH; +} + void Editline::ConfigureEditor(bool multiline) { if (m_editline && m_multiline_enabled == multiline) return; @@ -1153,9 +1191,41 @@ if (!multiline) { el_set(m_editline, EL_BIND, "^r", "em-in
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 marked an inline comment as done. gedatsu217 added a comment. > help help frame should not have an autosuggestion to help frame. You can just > try to get the autosuggestion for help help frame and check for the error for > an invalid command. Sorry, I do not know what this means. Now, if I execute "help help frame" once, it is suggested. Is this wrong? Comment at: lldb/source/Core/IOHandler.cpp:204 + .GetAutoSuggestionForCommand(line)) +result = res.getValue(); +} labath wrote: > Why does this switch Optional result to a by-ref string argument. We > have both code which uses an empty string to signify failure, and code which > does that with `None`. Both have their advantages and disadvantages, and I > don't have any strong objections to either one, but I certainly don't see an > advantage in using both in the same patch. Sorry, I do not what you mean. Would you explain it more in detail? (If None is returned, it is not assigned to "result". So, only is string assigned to "result". Does this answer your question?) CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 marked an inline comment as done. gedatsu217 added inline comments. Comment at: lldb/source/Core/IOHandler.cpp:204 + .GetAutoSuggestionForCommand(line)) +result = res.getValue(); +} labath wrote: > gedatsu217 wrote: > > labath wrote: > > > Why does this switch Optional result to a by-ref string argument. > > > We have both code which uses an empty string to signify failure, and code > > > which does that with `None`. Both have their advantages and > > > disadvantages, and I don't have any strong objections to either one, but > > > I certainly don't see an advantage in using both in the same patch. > > Sorry, I do not what you mean. Would you explain it more in detail? > > > > (If None is returned, it is not assigned to "result". So, only is string > > assigned to "result". Does this answer your question?) > Ok, let me try to phrase that differently: > - if `GetAutoSuggestionForCommand` fails, it returns `None` > - if `IOHandlerDelegate::IOHandlerSuggestion` fails, it sets a by-ref string > argument to `""` (or rather, leaves it as empty). > > The two behaviors are different, and it's not clear to me what justifies that > difference. It would be much cleaner and clearer if both were using the same > convention. Changing conventions part way like this is confusing and forces > one to add conversion code. If `IOHandlerSuggestion` was using the same > convention, then it's implementation would just be `return > io_handler.GetDebugger().GetCommandInterpreter().GetAutoSuggestionForCommand(line))`. I understood it. Even if I change return of IOHandlerSuggestion from void to llvm::Optional, I think I have to convert None to empty string in another function eventually, because the final perpose of these function is to make string for autosuggestion. Therefore, if I change return of CommandInterperter::GetAutoSuggestionForCommand from llvm::Optional to just std::string, I think above problem will be solved. What do you think? CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion
gedatsu217 added a comment. In addition to it, I tried the below code, but it did not go well. ("\x1b[nD" moves the cursor n steps to the left.) self.child.send("hel") self.child.expect_exact(faint_color + "p frame" + reset + "\x1b[" + str(len("p frame")) + "D") In the first place, the below code does not go well. self.child.send("help frame") self.child.expect_exact("help frame" + "\x1b[0D") "\x1b[0D" means that the cursor does not move. So, I suspect "\x1b[nD" does not function in pexpect. What do you think? CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81001/new/ https://reviews.llvm.org/D81001 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits