Fixes autocomplete when using sudo#8094
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #8094 +/- ##
==========================================
+ Coverage 54.23% 54.79% +0.56%
==========================================
Files 608 608
Lines 99003 99147 +144
==========================================
+ Hits 53693 54331 +638
+ Misses 45310 44816 -494
|
|
@rgwood I'm not really sure what to look for in the failed CI since everything passes locally. Could this be a temporary issue or something that actually needs a fix? |
|
I think you came across the flakiness of the plugin tests on the Mac CI runners. Restarted them, should typically resolve. |
sholderbach
left a comment
There was a problem hiding this comment.
Thank you very much for tackling this and figuring out some way to get you there.
I am not that up to speed on how the completion parsing and generation works at the moment, so I can not weigh in too much on that. But I have some concerns about the implementation that would make the code harder to maintain in the future.
To convince us to take this change it would probably also be beneficial to have a full test of a completion with sudo prefixed that includes some potential edge cases to make sure we don't break unexpectedly.
|
Thank you for taking your time. I've applied fixes according to your comments, they make sense to me and I see I'll have to check more of what Rust has already implemented to not do double work where applicable. I still have to add the test, which I expect to do shortly. |
|
@sholderbach I believe I've applied all the changes, including the test. Hopefully it captures what you meant. |
|
Thanks for updating the code and adding the additional independent tests! I would hold off on merging for a moment as @kubouch is currently fighting with the completion logic a bit to track down a nasty panic or logic bug (#7779 #8102). We certainly need to reign in a bunch of kludgy special cases that already exist and make everything a bit brittle. If we get this cleared it is probably easier to say how your fix fits in. This maybe also gives us some time to clarify how sudo should behave in regards to internal and external commands (referring to your #8099) Thanks for being responsive and eager to help out with nushell! |
|
I'm OK with it, I was tracking mostly bugs related to aliases, this seems unrelated. I would move Another change I would do is to rename |
|
Excellent suggestions, thank you. I'll take care of them tomorrow I think. |
| } | ||
|
|
||
| pub fn get_file_contents(&self) -> Vec<(Vec<u8>, usize, usize)> { | ||
| self.file_contents.clone() |
There was a problem hiding this comment.
Can we get away here without cloning?
There was a problem hiding this comment.
Agreed, you'd copy the entire source ever read by Nushell just to find sudo, that seems like an overkill. Most likely you can return &[u8].
|
Instead of utils, I would put the two functions into the command_completer.rs because they're used only for the completions. The logic for detecting the sudo is also a bit gnarly. The completer has access to the parsed result so there is no need to iterate bytes, you should be able to check for Expr::ExternalCall and see if it matches sudo and go from there. Or something like that. But I think as long as it works and does not break anything, it should be OK to merge as well. |
|
This will benefit from some squashing before merging. Let me know if it's alright as it is. |
|
We won't merge it at least for the next 1-2 days because we're doing the release, so if you want to keep hacking on it, go ahead. In general, looking up the bytes manually seems a bit unsound to me, I'd rather use the parsed output. One more thing, though. You're using direct array access with |
|
No worries, I'm not in a rush for having this merged, just saying when you feel it's ready, I'll also also squash the changes. I've replaced [..] with .get, thanks for pointing it out to me. I think I'm only using bytes where I don't have the full string available so that can probably stay like that? I'm perfectly fine with adapting the code if you point it out where you think I should do it differently. |
|
This doesn't seem to allow completions to complete local paths (i.e. programs that are not in PATH). Example:You have a script in a folder that requires root privileges to run. It is not in the PATH environment variable. |
# Description Fixes #2047 but for the `doas` command the same way as in #8094 # User-Facing Changes No breaking changes. If people not using `doas`, no difference at all. # Tests I have not added any tests since its using same logic as for "sudo". I guess if something would go wrong in this part, sudo tests will cover it? # Additional context As a nushell user I could not find a way to implement custom completion for a "sudo like command". Since I can see `sudo` being hardcoded in sources, this is what I propose. ~~Also I have almost zero knowledge of rust and this is definitely not the clean way yet~~ --------- Co-authored-by: Stefan Holderbach <[email protected]>
# Description Fixes nushell#2047 but for the `doas` command the same way as in nushell#8094 # User-Facing Changes No breaking changes. If people not using `doas`, no difference at all. # Tests I have not added any tests since its using same logic as for "sudo". I guess if something would go wrong in this part, sudo tests will cover it? # Additional context As a nushell user I could not find a way to implement custom completion for a "sudo like command". Since I can see `sudo` being hardcoded in sources, this is what I propose. ~~Also I have almost zero knowledge of rust and this is definitely not the clean way yet~~ --------- Co-authored-by: Stefan Holderbach <[email protected]>
Description
This PR addresses issue #2047 in order to enable autocomplete functionality when using sudo for executing commands. I'e done a couple of auxiliary checks such as ignoring whitespace and the last pipe in order to determine the last command.
User-Facing Changes
The only user facing change should be the autocomplete working.
Tests + Formatting
All tests and formatting pass.
Screenshots
Suggestions welcome
I still don't know the in's and out's if nushell very well, any suggestions for improvements are welcome.