diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2022-04-16 03:18:56 +0430 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2022-04-18 19:53:10 +0430 |
commit | ae27d7e4427b6186f720afebb63914e0cf644ec8 (patch) | |
tree | 1761123edfac33339f9a6be1fe10b871f6cace24 /Userland/Shell | |
parent | 302a0c54f05b31586c8ea8c66d98cb4d39f53517 (diff) | |
download | serenity-ae27d7e4427b6186f720afebb63914e0cf644ec8.zip |
Shell: Make program-based completion with no actual token possible
31ca48e made this default to paths, but now that we have a few sensible
ways to complete things, let's make those work too.
For instance, prior to this `kill <tab>` would've suggested paths, but
now it will suggest processes.
Diffstat (limited to 'Userland/Shell')
-rw-r--r-- | Userland/Shell/AST.cpp | 3 | ||||
-rw-r--r-- | Userland/Shell/Shell.cpp | 6 |
2 files changed, 6 insertions, 3 deletions
diff --git a/Userland/Shell/AST.cpp b/Userland/Shell/AST.cpp index f941f88409..126b136273 100644 --- a/Userland/Shell/AST.cpp +++ b/Userland/Shell/AST.cpp @@ -393,6 +393,7 @@ Vector<Line::CompletionSuggestion> Node::complete_for_editor(Shell& shell, size_ auto result = hit_test_position(offset); if (!result.matching_node) return shell.complete_path("", "", 0, Shell::ExecutableOnly::No, result.closest_command_node.ptr(), nullptr, Shell::EscapeMode::Bareword); + auto node = result.matching_node; if (node->is_bareword() || node != result.closest_node_with_semantic_meaning) node = result.closest_node_with_semantic_meaning; @@ -744,6 +745,8 @@ HitTestResult CastToCommand::hit_test_position(size_t offset) const auto result = m_inner->hit_test_position(offset); if (!result.closest_node_with_semantic_meaning) result.closest_node_with_semantic_meaning = this; + if (!result.closest_command_node && position().contains(offset)) + result.closest_command_node = this; return result; } diff --git a/Userland/Shell/Shell.cpp b/Userland/Shell/Shell.cpp index d6405cc7dc..532db8ed9c 100644 --- a/Userland/Shell/Shell.cpp +++ b/Userland/Shell/Shell.cpp @@ -1678,9 +1678,9 @@ ErrorOr<Vector<Line::CompletionSuggestion>> Shell::complete_via_program_itself(s completion_command.argv.extend({ "--complete", "--" }); struct Visitor : public AST::NodeVisitor { - Visitor(Shell& shell, AST::Node const& node) + Visitor(Shell& shell, AST::Position position) : shell(shell) - , completion_position(node.position()) + , completion_position(position) { lists.empend(); } @@ -1824,7 +1824,7 @@ ErrorOr<Vector<Line::CompletionSuggestion>> Shell::complete_via_program_itself(s virtual void visit(AST::ReadWriteRedirection const*) override { } virtual void visit(AST::WriteAppendRedirection const*) override { } virtual void visit(AST::WriteRedirection const*) override { } - } visitor { *this, *node }; + } visitor { *this, node ? node->position() : AST::Position() }; command_node->visit(visitor); if (visitor.fail) |