summaryrefslogtreecommitdiff
path: root/Userland/Shell
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2022-01-21 17:31:48 +0330
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2022-01-21 18:58:28 +0330
commit78d1093dabe73de2010fa6e47fd8b5d8389572fd (patch)
tree1569bc4cfec3aedbed27cd3322194fc8b7e679fc /Userland/Shell
parent2e333b3571c08e80fe26c309bea60a2b28592633 (diff)
downloadserenity-78d1093dabe73de2010fa6e47fd8b5d8389572fd.zip
Shell: Make Juxtaposition autocompletion smarter
Now something like `"$HOME"/` autocompletes correctly. Note that only the first element of lists is used to autocomplete things.
Diffstat (limited to 'Userland/Shell')
-rw-r--r--Userland/Shell/AST.cpp31
1 files changed, 22 insertions, 9 deletions
diff --git a/Userland/Shell/AST.cpp b/Userland/Shell/AST.cpp
index a59c6b328e..4b1499028e 100644
--- a/Userland/Shell/AST.cpp
+++ b/Userland/Shell/AST.cpp
@@ -3013,23 +3013,36 @@ void Juxtaposition::highlight_in_editor(Line::Editor& editor, Shell& shell, High
Vector<Line::CompletionSuggestion> Juxtaposition::complete_for_editor(Shell& shell, size_t offset, const HitTestResult& hit_test_result)
{
auto matching_node = hit_test_result.matching_node;
+ if (m_left->would_execute() || m_right->would_execute()) {
+ return {};
+ }
+
// '~/foo/bar' is special, we have to actually resolve the tilde
// then complete the bareword with that path prefix.
- if (m_right->is_bareword() && m_left->is_tilde()) {
- auto tilde_value = m_left->run(shell)->resolve_as_list(shell)[0];
+ auto left_values = m_left->run(shell)->resolve_as_list(shell);
- auto corrected_offset = offset - matching_node->position().start_offset;
- auto* node = static_cast<BarewordLiteral*>(matching_node.ptr());
+ if (left_values.is_empty())
+ return m_right->complete_for_editor(shell, offset, hit_test_result);
- if (corrected_offset > node->text().length())
- return {};
+ auto& left_value = left_values.first();
- auto text = node->text().substring(1, node->text().length() - 1);
+ auto right_values = m_right->run(shell)->resolve_as_list(shell);
+ StringView right_value {};
- return shell.complete_path(tilde_value, text, corrected_offset - 1, Shell::ExecutableOnly::No);
+ auto corrected_offset = offset - matching_node->position().start_offset;
+
+ if (!right_values.is_empty())
+ right_value = right_values.first();
+
+ if (m_left->is_tilde() && !right_value.is_empty()) {
+ right_value = right_value.substring_view(1);
+ corrected_offset--;
}
- return Node::complete_for_editor(shell, offset, hit_test_result);
+ if (corrected_offset > right_value.length())
+ return {};
+
+ return shell.complete_path(left_value, right_value, corrected_offset, Shell::ExecutableOnly::No);
}
HitTestResult Juxtaposition::hit_test_position(size_t offset) const