[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion

Raphael Isemann via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Jul 17 09:24:15 PDT 2020


teemperor requested changes to this revision.
teemperor added a comment.
This revision now requires changes to proceed.

> The test looks wrong to me. If the feature is supposed to be off by default, then how can it test anything without first turning the feature on? Either the feature isn't really off, or the test is broken. I would expect it to be the latter, because the test sequence seems incorrect to me. I would expect to see some newlines in the strings being sent, otherwise all of this will just get concatenated into a single command.
>  Also, this only seems to test the ^F functionality. It does not check that the command is printed in gray _before_ the user hits ^F.

Yeah, and the test obviously doesn't pass.

Alright, let's try to fix this.

@gedatsu217 Not sure if you uploaded the wrong diff, but that test doesn't pass. It would be a nice test if if worked though. But as we anyway need another iteration, let's also extend the test while we're at it.

First, you need to get the test to actually enable autosuggestions, so you need to launch via `self.launch(extra_args=["-o", "settings set show-autosuggestion true"])` (the `extra_args` are just passed to LLDB's command line).

Also as Pavel said, we should also test that we display the autosuggestion in faint colour. Not sure if there is a good way to test that the text is directly behind the cursor, but we can test that it's there. And I guess we should test that we actually pick the most recent command for the autosuggestion (this is currently wrong and we pick the least recent command).

I extend your test a bit to something like this (which is currently failing as it always completes `help frame` but not the `help apropos`).

  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"                                                       
                                                                          
  frame_output_needle = "Syntax: frame <subcommand>"                      
  # 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)                
                                                                          
  # Apply the autosuggestion and press enter. This should print the       
  # the 'help frame' output if everything went correctly.                 
  self.child.send(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)                            
                                                                          
  # Try another command.                                                  
  apropos_output_needle = "Syntax: apropos <search-word>"                 
  # Run 'help frame' once to put it into the command history.             
  self.expect("help apropos", substrs=[apropos_output_needle])            
                                                                          
  # 'hel' should have an autosuggestion for 'help apropos' now.           
  self.child.send("hel")                                                  
  # FIXME: This is showing 'frame' instead.                               
  self.child.expect_exact(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)

A few more test cases that come to my mind and you should add:

- `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.
- Pressing Ctrl+F in an empty prompt should do nothing (you can just check for the `(lldb) ` prompt I would say).
- Pressing Ctrl+F directly after Ctrl+F again should do nothing.
- Having `help frame` and `help frame var` in the command history, `help fr` should still complete to the most recent one.
- Entering `a1234`, then 5 backspaces, then `hel` and then Ctrl+F should bring up the autosuggestion for `help frame`.
- Entering `help x`, then 1 backspace, then Ctrl+F should bring up the autosuggestion for `help frame`.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81001/new/

https://reviews.llvm.org/D81001





More information about the lldb-commits mailing list