Shell: Convert the remaining fallible AST functions to ErrorOr

This commit is contained in:
Ali Mohammad Pur 2023-02-18 17:27:14 +03:30 committed by Ali Mohammad Pur
parent 5f950df3d4
commit e403dbabfa
Notes: sideshowbarker 2024-07-18 04:46:35 +09:00
5 changed files with 489 additions and 429 deletions

View file

@ -78,7 +78,8 @@ Vector<DeprecatedString> const& ShellComprehensionEngine::DocumentData::sourced_
auto& filename = entries[1];
if (filename->would_execute())
return;
auto name_list = const_cast<::Shell::AST::Node*>(filename.ptr())->run(nullptr)->resolve_as_list(nullptr).release_value_but_fixme_should_propagate_errors();
auto name_list_node = const_cast<::Shell::AST::Node*>(filename.ptr())->run(nullptr).release_value_but_fixme_should_propagate_errors();
auto name_list = name_list_node->resolve_as_list(nullptr).release_value_but_fixme_should_propagate_errors();
StringBuilder builder;
builder.join(' ', name_list);
sourced_files.set(builder.to_deprecated_string());
@ -146,7 +147,7 @@ Vector<CodeComprehension::AutocompleteResultEntry> ShellComprehensionEngine::get
return {};
}
auto completions = const_cast<::Shell::AST::Node*>(document.node.ptr())->complete_for_editor(shell(), offset_in_file, hit_test);
auto completions = const_cast<::Shell::AST::Node*>(document.node.ptr())->complete_for_editor(shell(), offset_in_file, hit_test).release_value_but_fixme_should_propagate_errors();
Vector<CodeComprehension::AutocompleteResultEntry> entries;
for (auto& completion : completions)
entries.append({ completion.text_string, completion.input_offset });

File diff suppressed because it is too large Load diff

View file

@ -421,11 +421,11 @@ class Node : public RefCounted<Node> {
public:
virtual ErrorOr<void> dump(int level) const = 0;
virtual void for_each_entry(RefPtr<Shell> shell, Function<IterationDecision(NonnullRefPtr<Value>)> callback);
virtual RefPtr<Value> run(RefPtr<Shell>) = 0;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) = 0;
virtual Vector<Line::CompletionSuggestion> complete_for_editor(Shell&, size_t, HitTestResult const&) const;
Vector<Line::CompletionSuggestion> complete_for_editor(Shell& shell, size_t offset);
virtual ErrorOr<void> for_each_entry(RefPtr<Shell> shell, Function<ErrorOr<IterationDecision>(NonnullRefPtr<Value>)> callback);
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) = 0;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) = 0;
virtual ErrorOr<Vector<Line::CompletionSuggestion>> complete_for_editor(Shell&, size_t, HitTestResult const&) const;
ErrorOr<Vector<Line::CompletionSuggestion>> complete_for_editor(Shell& shell, size_t offset);
virtual HitTestResult hit_test_position(size_t offset) const
{
if (m_position.contains(offset))
@ -460,7 +460,7 @@ public:
virtual RefPtr<Node const> leftmost_trivial_literal() const { return nullptr; }
Vector<Command> to_lazy_evaluated_commands(RefPtr<Shell> shell);
ErrorOr<Vector<Command>> to_lazy_evaluated_commands(RefPtr<Shell> shell);
virtual void visit(NodeVisitor&) { VERIFY_NOT_REACHED(); }
virtual void visit(NodeVisitor& visitor) const { const_cast<Node*>(this)->visit(visitor); }
@ -533,8 +533,8 @@ class PathRedirectionNode : public Node {
public:
PathRedirectionNode(Position, int, NonnullRefPtr<Node>);
virtual ~PathRedirectionNode();
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual Vector<Line::CompletionSuggestion> complete_for_editor(Shell&, size_t, HitTestResult const&) const override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<Vector<Line::CompletionSuggestion>> complete_for_editor(Shell&, size_t, HitTestResult const&) const override;
virtual HitTestResult hit_test_position(size_t offset) const override;
virtual bool is_command() const override { return true; }
virtual bool is_list() const override { return true; }
@ -561,8 +561,8 @@ public:
private:
NODE(And);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual HitTestResult hit_test_position(size_t) const override;
NonnullRefPtr<Node> m_left;
@ -580,9 +580,9 @@ public:
private:
NODE(ListConcatenate);
virtual ErrorOr<void> dump(int level) const override;
virtual void for_each_entry(RefPtr<Shell> shell, Function<IterationDecision(NonnullRefPtr<Value>)> callback) override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<void> for_each_entry(RefPtr<Shell> shell, Function<ErrorOr<IterationDecision>(NonnullRefPtr<Value>)> callback) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual HitTestResult hit_test_position(size_t) const override;
virtual bool is_list() const override { return true; }
virtual RefPtr<Node const> leftmost_trivial_literal() const override;
@ -601,8 +601,8 @@ public:
private:
NODE(Background);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual HitTestResult hit_test_position(size_t) const override;
NonnullRefPtr<Node> m_command;
@ -619,8 +619,8 @@ public:
private:
NODE(BarewordLiteral);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual bool is_bareword() const override { return true; }
virtual RefPtr<Node const> leftmost_trivial_literal() const override { return this; }
@ -638,8 +638,8 @@ public:
private:
NODE(BraceExpansion);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual HitTestResult hit_test_position(size_t) const override;
NonnullRefPtrVector<Node> m_entries;
@ -656,10 +656,10 @@ public:
private:
NODE(CastToCommand);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual HitTestResult hit_test_position(size_t) const override;
virtual Vector<Line::CompletionSuggestion> complete_for_editor(Shell&, size_t, HitTestResult const&) const override;
virtual ErrorOr<Vector<Line::CompletionSuggestion>> complete_for_editor(Shell&, size_t, HitTestResult const&) const override;
virtual bool is_command() const override { return true; }
virtual bool is_list() const override { return true; }
virtual RefPtr<Node const> leftmost_trivial_literal() const override;
@ -678,9 +678,9 @@ public:
private:
NODE(CastToList);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void for_each_entry(RefPtr<Shell> shell, Function<IterationDecision(NonnullRefPtr<Value>)> callback) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> for_each_entry(RefPtr<Shell> shell, Function<ErrorOr<IterationDecision>(NonnullRefPtr<Value>)> callback) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual HitTestResult hit_test_position(size_t) const override;
virtual bool is_list() const override { return true; }
virtual RefPtr<Node const> leftmost_trivial_literal() const override;
@ -699,8 +699,8 @@ public:
private:
NODE(CloseFdRedirection);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual bool is_command() const override { return true; }
int m_fd { -1 };
@ -717,8 +717,8 @@ public:
private:
NODE(CommandLiteral);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override { VERIFY_NOT_REACHED(); }
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override { VERIFY_NOT_REACHED(); }
virtual bool is_command() const override { return true; }
virtual bool is_list() const override { return true; }
@ -736,8 +736,8 @@ public:
private:
NODE(Comment);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
String m_text;
};
@ -762,8 +762,8 @@ private:
NODE(ContinuationControl);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
ContinuationKind m_kind { ContinuationKind::Break };
};
@ -779,8 +779,8 @@ public:
private:
NODE(DynamicEvaluate);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual HitTestResult hit_test_position(size_t) const override;
virtual bool is_bareword() const override { return m_inner->is_bareword(); }
@ -806,8 +806,8 @@ public:
private:
NODE(DoubleQuotedString);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual HitTestResult hit_test_position(size_t) const override;
RefPtr<Node> m_inner;
@ -825,8 +825,8 @@ public:
private:
NODE(Fd2FdRedirection);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual bool is_command() const override { return true; }
int m_old_fd { -1 };
@ -846,10 +846,10 @@ public:
private:
NODE(FunctionDeclaration);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual HitTestResult hit_test_position(size_t) const override;
virtual Vector<Line::CompletionSuggestion> complete_for_editor(Shell&, size_t, HitTestResult const&) const override;
virtual ErrorOr<Vector<Line::CompletionSuggestion>> complete_for_editor(Shell&, size_t, HitTestResult const&) const override;
virtual bool would_execute() const override { return true; }
virtual bool should_override_execution_in_current_process() const override { return true; }
@ -874,8 +874,8 @@ public:
private:
NODE(ForLoop);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual HitTestResult hit_test_position(size_t) const override;
virtual bool would_execute() const override { return true; }
virtual bool should_override_execution_in_current_process() const override { return true; }
@ -899,8 +899,8 @@ public:
private:
NODE(Glob);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual bool is_glob() const override { return true; }
virtual bool is_list() const override { return true; }
@ -958,8 +958,8 @@ public:
private:
NODE(HistoryEvent);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
HistorySelector m_selector;
};
@ -970,7 +970,7 @@ public:
virtual ~Execute();
void capture_stdout() { m_capture_stdout = true; }
NonnullRefPtr<Node>& command() { return m_command; }
virtual void for_each_entry(RefPtr<Shell> shell, Function<IterationDecision(NonnullRefPtr<Value>)> callback) override;
virtual ErrorOr<void> for_each_entry(RefPtr<Shell> shell, Function<ErrorOr<IterationDecision>(NonnullRefPtr<Value>)> callback) override;
virtual void visit(NodeVisitor& visitor) override { visitor.visit(this); }
NonnullRefPtr<Node> const& command() const { return m_command; }
@ -979,10 +979,10 @@ public:
private:
NODE(Execute);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual HitTestResult hit_test_position(size_t) const override;
virtual Vector<Line::CompletionSuggestion> complete_for_editor(Shell&, size_t, HitTestResult const&) const override;
virtual ErrorOr<Vector<Line::CompletionSuggestion>> complete_for_editor(Shell&, size_t, HitTestResult const&) const override;
virtual bool is_execute() const override { return true; }
virtual bool would_execute() const override { return true; }
@ -1005,8 +1005,8 @@ public:
private:
NODE(IfCond);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual HitTestResult hit_test_position(size_t) const override;
virtual bool should_override_execution_in_current_process() const override { return true; }
@ -1032,9 +1032,9 @@ public:
private:
NODE(ImmediateExpression);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual Vector<Line::CompletionSuggestion> complete_for_editor(Shell&, size_t, HitTestResult const&) const override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
ErrorOr<Vector<Line::CompletionSuggestion>> complete_for_editor(Shell&, size_t, HitTestResult const&) const override;
virtual HitTestResult hit_test_position(size_t) const override;
NonnullRefPtrVector<AST::Node> m_arguments;
@ -1054,8 +1054,8 @@ public:
private:
NODE(Join);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual HitTestResult hit_test_position(size_t) const override;
virtual bool is_command() const override { return true; }
virtual bool is_list() const override { return true; }
@ -1087,8 +1087,8 @@ public:
private:
NODE(MatchExpr);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual HitTestResult hit_test_position(size_t) const override;
virtual bool would_execute() const override { return true; }
virtual bool should_override_execution_in_current_process() const override { return true; }
@ -1112,8 +1112,8 @@ public:
private:
NODE(Or);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual HitTestResult hit_test_position(size_t) const override;
NonnullRefPtr<Node> m_left;
@ -1133,8 +1133,8 @@ public:
private:
NODE(Pipe);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual HitTestResult hit_test_position(size_t) const override;
virtual bool is_command() const override { return true; }
@ -1154,8 +1154,8 @@ public:
private:
NODE(Range);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual HitTestResult hit_test_position(size_t) const override;
NonnullRefPtr<Node> m_start;
@ -1171,7 +1171,7 @@ public:
private:
NODE(ReadRedirection);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
};
class ReadWriteRedirection final : public PathRedirectionNode {
@ -1183,7 +1183,7 @@ public:
private:
NODE(ReadWriteRedirection);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
};
class Sequence final : public Node {
@ -1199,8 +1199,8 @@ public:
private:
NODE(Sequence);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual HitTestResult hit_test_position(size_t) const override;
virtual bool is_list() const override { return true; }
virtual bool should_override_execution_in_current_process() const override { return true; }
@ -1221,8 +1221,8 @@ public:
private:
NODE(Subshell);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual HitTestResult hit_test_position(size_t) const override;
virtual bool would_execute() const override { return false; }
virtual bool should_override_execution_in_current_process() const override { return true; }
@ -1240,9 +1240,9 @@ public:
NonnullRefPtr<AST::Node> selector() const { return m_selector; }
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual Vector<Line::CompletionSuggestion> complete_for_editor(Shell&, size_t, HitTestResult const&) const override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<Vector<Line::CompletionSuggestion>> complete_for_editor(Shell&, size_t, HitTestResult const&) const override;
virtual HitTestResult hit_test_position(size_t) const override;
protected:
@ -1282,9 +1282,9 @@ public:
private:
NODE(SimpleVariable);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual Vector<Line::CompletionSuggestion> complete_for_editor(Shell&, size_t, HitTestResult const&) const override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<Vector<Line::CompletionSuggestion>> complete_for_editor(Shell&, size_t, HitTestResult const&) const override;
virtual HitTestResult hit_test_position(size_t) const override;
virtual bool is_simple_variable() const override { return true; }
@ -1302,9 +1302,9 @@ public:
private:
NODE(SpecialVariable);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual Vector<Line::CompletionSuggestion> complete_for_editor(Shell&, size_t, HitTestResult const&) const override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<Vector<Line::CompletionSuggestion>> complete_for_editor(Shell&, size_t, HitTestResult const&) const override;
virtual HitTestResult hit_test_position(size_t) const override;
char m_name { 0 };
@ -1326,10 +1326,10 @@ public:
private:
NODE(Juxtaposition);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual HitTestResult hit_test_position(size_t) const override;
virtual Vector<Line::CompletionSuggestion> complete_for_editor(Shell&, size_t, HitTestResult const&) const override;
virtual ErrorOr<Vector<Line::CompletionSuggestion>> complete_for_editor(Shell&, size_t, HitTestResult const&) const override;
NonnullRefPtr<Node> m_left;
NonnullRefPtr<Node> m_right;
@ -1360,8 +1360,8 @@ public:
private:
NODE(Heredoc);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual HitTestResult hit_test_position(size_t) const override;
virtual RefPtr<Node const> leftmost_trivial_literal() const override { return this; };
@ -1390,8 +1390,8 @@ public:
private:
NODE(StringLiteral);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual RefPtr<Node const> leftmost_trivial_literal() const override { return this; };
String m_text;
@ -1410,8 +1410,8 @@ public:
private:
NODE(StringPartCompose);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual HitTestResult hit_test_position(size_t) const override;
NonnullRefPtr<Node> m_left;
@ -1444,8 +1444,8 @@ public:
private:
NODE(SyntaxError);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual HitTestResult hit_test_position(size_t) const override { return { nullptr, nullptr, nullptr }; }
virtual SyntaxError& syntax_error_node() override;
@ -1465,8 +1465,8 @@ public:
private:
NODE(SyntheticValue);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
NonnullRefPtr<Value> m_value;
};
@ -1482,9 +1482,9 @@ public:
private:
NODE(Tilde);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual Vector<Line::CompletionSuggestion> complete_for_editor(Shell&, size_t, HitTestResult const&) const override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<Vector<Line::CompletionSuggestion>> complete_for_editor(Shell&, size_t, HitTestResult const&) const override;
virtual HitTestResult hit_test_position(size_t) const override;
virtual bool is_tilde() const override { return true; }
@ -1506,8 +1506,8 @@ public:
private:
NODE(VariableDeclarations);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual HitTestResult hit_test_position(size_t) const override;
virtual bool is_variable_decls() const override { return true; }
@ -1523,7 +1523,7 @@ public:
private:
NODE(WriteAppendRedirection);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
};
class WriteRedirection final : public PathRedirectionNode {
@ -1535,7 +1535,7 @@ public:
private:
NODE(WriteRedirection);
virtual ErrorOr<void> dump(int level) const override;
virtual RefPtr<Value> run(RefPtr<Shell>) override;
virtual ErrorOr<RefPtr<Value>> run(RefPtr<Shell>) override;
};
}

View file

@ -59,7 +59,7 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_length_impl(AST::ImmediateExpression
if (expr_node->is_list())
mode = List;
else if (expr_node->is_simple_variable()) // "Look inside" variables
mode = TRY(const_cast<AST::Node*>(expr_node)->run(this)->resolve_without_cast(this))->is_list_without_resolution() ? List : String;
mode = TRY(TRY(const_cast<AST::Node*>(expr_node)->run(this))->resolve_without_cast(this))->is_list_without_resolution() ? List : String;
else if (is<AST::ImmediateExpression>(expr_node))
mode = List;
else
@ -96,7 +96,7 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_length_impl(AST::ImmediateExpression
case Infer:
VERIFY_NOT_REACHED();
case List: {
auto value = (const_cast<AST::Node*>(expr_node))->run(this);
auto value = TRY(const_cast<AST::Node*>(expr_node)->run(this));
if (!value)
return value_with_number(0);
@ -141,7 +141,7 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_length_impl(AST::ImmediateExpression
}
}
auto value = (const_cast<AST::Node*>(expr_node))->run(this);
auto value = TRY(const_cast<AST::Node*>(expr_node)->run(this));
if (!value)
return value_with_number(0);
@ -206,9 +206,9 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_regex_replace(AST::ImmediateExpressi
return nullptr;
}
auto pattern = const_cast<AST::Node&>(arguments[0]).run(this);
auto replacement = const_cast<AST::Node&>(arguments[1]).run(this);
auto value = TRY(const_cast<AST::Node&>(arguments[2]).run(this)->resolve_without_cast(this));
auto pattern = TRY(const_cast<AST::Node&>(arguments[0]).run(this));
auto replacement = TRY(const_cast<AST::Node&>(arguments[1]).run(this));
auto value = TRY(TRY(const_cast<AST::Node&>(arguments[2]).run(this))->resolve_without_cast(this));
if (!pattern->is_string()) {
raise_error(ShellError::EvaluatedSyntaxError, "Expected the regex_replace pattern to be a string", arguments[0].position());
@ -241,8 +241,8 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_remove_suffix(AST::ImmediateExpressi
return nullptr;
}
auto suffix = const_cast<AST::Node&>(arguments[0]).run(this);
auto value = TRY(const_cast<AST::Node&>(arguments[1]).run(this)->resolve_without_cast(this));
auto suffix = TRY(const_cast<AST::Node&>(arguments[0]).run(this));
auto value = TRY(TRY(const_cast<AST::Node&>(arguments[1]).run(this))->resolve_without_cast(this));
if (!suffix->is_string()) {
raise_error(ShellError::EvaluatedSyntaxError, "Expected the remove_suffix suffix string to be a string", arguments[0].position());
@ -273,8 +273,8 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_remove_prefix(AST::ImmediateExpressi
return nullptr;
}
auto prefix = const_cast<AST::Node&>(arguments[0]).run(this);
auto value = TRY(const_cast<AST::Node&>(arguments[1]).run(this)->resolve_without_cast(this));
auto prefix = TRY(const_cast<AST::Node&>(arguments[0]).run(this));
auto value = TRY(TRY(const_cast<AST::Node&>(arguments[1]).run(this))->resolve_without_cast(this));
if (!prefix->is_string()) {
raise_error(ShellError::EvaluatedSyntaxError, "Expected the remove_prefix prefix string to be a string", arguments[0].position());
@ -304,8 +304,8 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_split(AST::ImmediateExpression& invo
return nullptr;
}
auto delimiter = const_cast<AST::Node&>(arguments[0]).run(this);
auto value = TRY(const_cast<AST::Node&>(arguments[1]).run(this)->resolve_without_cast(this));
auto delimiter = TRY(const_cast<AST::Node&>(arguments[0]).run(this));
auto value = TRY(TRY(const_cast<AST::Node&>(arguments[1]).run(this))->resolve_without_cast(this));
if (!delimiter->is_string()) {
raise_error(ShellError::EvaluatedSyntaxError, "Expected the split delimiter string to be a string", arguments[0].position());
@ -372,7 +372,7 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_concat_lists(AST::ImmediateExpressio
if (auto* list = dynamic_cast<const AST::ListConcatenate*>(&argument)) {
result.extend(list->list());
} else {
auto list_of_values = TRY(const_cast<AST::Node&>(argument).run(this)->resolve_without_cast(this));
auto list_of_values = TRY(TRY(const_cast<AST::Node&>(argument).run(this))->resolve_without_cast(this));
if (auto* list = dynamic_cast<AST::ListValue*>(list_of_values.ptr())) {
for (auto& entry : static_cast<Vector<NonnullRefPtr<AST::Value>>&>(list->values()))
result.append(AST::make_ref_counted<AST::SyntheticNode>(argument.position(), entry));
@ -395,7 +395,7 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_filter_glob(AST::ImmediateExpression
return nullptr;
}
auto glob_list = TRY(const_cast<AST::Node&>(arguments[0]).run(*this)->resolve_as_list(*this));
auto glob_list = TRY(TRY(const_cast<AST::Node&>(arguments[0]).run(*this))->resolve_as_list(*this));
if (glob_list.size() != 1) {
raise_error(ShellError::EvaluatedSyntaxError, "Expected the <glob> argument to filter_glob to be a single string", arguments[0].position());
return nullptr;
@ -405,8 +405,8 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_filter_glob(AST::ImmediateExpression
NonnullRefPtrVector<AST::Node> result;
const_cast<AST::Node&>(list_node).for_each_entry(*this, [&](NonnullRefPtr<AST::Value> entry) {
auto value = entry->resolve_as_list(*this).release_value_but_fixme_should_propagate_errors();
TRY(const_cast<AST::Node&>(list_node).for_each_entry(*this, [&](NonnullRefPtr<AST::Value> entry) -> ErrorOr<IterationDecision> {
auto value = TRY(entry->resolve_as_list(*this));
if (value.size() == 0)
return IterationDecision::Continue;
if (value.size() == 1) {
@ -426,7 +426,7 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_filter_glob(AST::ImmediateExpression
}
}
return IterationDecision::Continue;
});
}));
return AST::make_ref_counted<AST::ListConcatenate>(invoking_node.position(), move(result));
}
@ -438,13 +438,13 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_join(AST::ImmediateExpression& invok
return nullptr;
}
auto delimiter = const_cast<AST::Node&>(arguments[0]).run(this);
auto delimiter = TRY(const_cast<AST::Node&>(arguments[0]).run(this));
if (!delimiter->is_string()) {
raise_error(ShellError::EvaluatedSyntaxError, "Expected the join delimiter string to be a string", arguments[0].position());
return nullptr;
}
auto value = TRY(const_cast<AST::Node&>(arguments[1]).run(this)->resolve_without_cast(this));
auto value = TRY(TRY(const_cast<AST::Node&>(arguments[1]).run(this))->resolve_without_cast(this));
if (!value->is_list()) {
raise_error(ShellError::EvaluatedSyntaxError, "Expected the joined list to be a list", arguments[1].position());
return nullptr;
@ -464,7 +464,7 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_value_or_default(AST::ImmediateExpre
return nullptr;
}
auto name = TRY(const_cast<AST::Node&>(arguments.first()).run(*this)->resolve_as_string(*this));
auto name = TRY(TRY(const_cast<AST::Node&>(arguments.first()).run(*this))->resolve_as_string(*this));
if (!local_variable_or(name, ""sv).is_empty())
return make_ref_counted<AST::SimpleVariable>(invoking_node.position(), name);
@ -478,11 +478,11 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_assign_default(AST::ImmediateExpress
return nullptr;
}
auto name = TRY(const_cast<AST::Node&>(arguments.first()).run(*this)->resolve_as_string(*this));
auto name = TRY(TRY(const_cast<AST::Node&>(arguments.first()).run(*this))->resolve_as_string(*this));
if (!local_variable_or(name, ""sv).is_empty())
return make_ref_counted<AST::SimpleVariable>(invoking_node.position(), name);
auto value = TRY(const_cast<AST::Node&>(arguments.last()).run(*this)->resolve_without_cast(*this));
auto value = TRY(TRY(const_cast<AST::Node&>(arguments.last()).run(*this))->resolve_without_cast(*this));
set_local_variable(name.to_deprecated_string(), value);
return make_ref_counted<AST::SyntheticNode>(invoking_node.position(), value);
@ -495,11 +495,11 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_error_if_empty(AST::ImmediateExpress
return nullptr;
}
auto name = TRY(const_cast<AST::Node&>(arguments.first()).run(*this)->resolve_as_string(*this));
auto name = TRY(TRY(const_cast<AST::Node&>(arguments.first()).run(*this))->resolve_as_string(*this));
if (!local_variable_or(name, ""sv).is_empty())
return make_ref_counted<AST::SimpleVariable>(invoking_node.position(), name);
auto error_value = TRY(const_cast<AST::Node&>(arguments.last()).run(*this)->resolve_as_string(*this));
auto error_value = TRY(TRY(const_cast<AST::Node&>(arguments.last()).run(*this))->resolve_as_string(*this));
if (error_value.is_empty())
error_value = TRY(String::formatted("Expected {} to be non-empty", name));
@ -514,7 +514,7 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_null_or_alternative(AST::ImmediateEx
return nullptr;
}
auto value = TRY(const_cast<AST::Node&>(arguments.first()).run(*this)->resolve_without_cast(*this));
auto value = TRY(TRY(const_cast<AST::Node&>(arguments.first()).run(*this))->resolve_without_cast(*this));
if ((value->is_string() && TRY(value->resolve_as_string(*this)).is_empty()) || (value->is_list() && TRY(value->resolve_as_list(*this)).is_empty()))
return make_ref_counted<AST::SyntheticNode>(invoking_node.position(), value);
@ -528,7 +528,7 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_defined_value_or_default(AST::Immedi
return nullptr;
}
auto name = TRY(const_cast<AST::Node&>(arguments.first()).run(*this)->resolve_as_string(*this));
auto name = TRY(TRY(const_cast<AST::Node&>(arguments.first()).run(*this))->resolve_as_string(*this));
if (!find_frame_containing_local_variable(name))
return arguments.last();
@ -542,11 +542,11 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_assign_defined_default(AST::Immediat
return nullptr;
}
auto name = TRY(const_cast<AST::Node&>(arguments.first()).run(*this)->resolve_as_string(*this));
auto name = TRY(TRY(const_cast<AST::Node&>(arguments.first()).run(*this))->resolve_as_string(*this));
if (find_frame_containing_local_variable(name))
return make_ref_counted<AST::SimpleVariable>(invoking_node.position(), name);
auto value = TRY(const_cast<AST::Node&>(arguments.last()).run(*this)->resolve_without_cast(*this));
auto value = TRY(TRY(const_cast<AST::Node&>(arguments.last()).run(*this))->resolve_without_cast(*this));
set_local_variable(name.to_deprecated_string(), value);
return make_ref_counted<AST::SyntheticNode>(invoking_node.position(), value);
@ -559,11 +559,11 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_error_if_unset(AST::ImmediateExpress
return nullptr;
}
auto name = TRY(const_cast<AST::Node&>(arguments.first()).run(*this)->resolve_as_string(*this));
auto name = TRY(TRY(const_cast<AST::Node&>(arguments.first()).run(*this))->resolve_as_string(*this));
if (find_frame_containing_local_variable(name))
return make_ref_counted<AST::SimpleVariable>(invoking_node.position(), name);
auto error_value = TRY(const_cast<AST::Node&>(arguments.last()).run(*this)->resolve_as_string(*this));
auto error_value = TRY(TRY(const_cast<AST::Node&>(arguments.last()).run(*this))->resolve_as_string(*this));
if (error_value.is_empty())
error_value = TRY(String::formatted("Expected {} to be set", name));
@ -578,7 +578,7 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_null_if_unset_or_alternative(AST::Im
return nullptr;
}
auto name = TRY(const_cast<AST::Node&>(arguments.first()).run(*this)->resolve_as_string(*this));
auto name = TRY(TRY(const_cast<AST::Node&>(arguments.first()).run(*this))->resolve_as_string(*this));
if (!find_frame_containing_local_variable(name))
return arguments.last();
@ -592,7 +592,7 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_reexpand(AST::ImmediateExpression& i
return nullptr;
}
auto value = TRY(const_cast<AST::Node&>(arguments.first()).run(*this)->resolve_as_string(*this));
auto value = TRY(TRY(const_cast<AST::Node&>(arguments.first()).run(*this))->resolve_as_string(*this));
return parse(value, m_is_interactive, false);
}
@ -603,7 +603,7 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_length_of_variable(AST::ImmediateExp
return nullptr;
}
auto name = TRY(const_cast<AST::Node&>(arguments.first()).run(*this)->resolve_as_string(*this));
auto name = TRY(TRY(const_cast<AST::Node&>(arguments.first()).run(*this))->resolve_as_string(*this));
auto variable = make_ref_counted<AST::SimpleVariable>(invoking_node.position(), name);
return immediate_length_impl(

View file

@ -308,7 +308,7 @@ Vector<AST::Command> Shell::expand_aliases(Vector<AST::Command> initial_commands
NonnullRefPtr<AST::Node> substitute = adopt_ref(*new AST::Join(subcommand_nonnull->position(),
subcommand_nonnull,
adopt_ref(*new AST::CommandLiteral(subcommand_nonnull->position(), command))));
auto res = substitute->run(*this);
auto res = substitute->run(*this).release_value_but_fixme_should_propagate_errors();
for (auto& subst_command : res->resolve_as_commands(*this).release_value_but_fixme_should_propagate_errors()) {
if (!subst_command.argv.is_empty() && subst_command.argv.first() == argv0) // Disallow an alias resolving to itself.
commands.append(subst_command);
@ -1434,7 +1434,7 @@ void Shell::highlight(Line::Editor& editor) const
auto ast = parse(line, m_is_interactive);
if (!ast)
return;
ast->highlight_in_editor(editor, const_cast<Shell&>(*this));
ast->highlight_in_editor(editor, const_cast<Shell&>(*this)).release_value_but_fixme_should_propagate_errors();
}
Vector<Line::CompletionSuggestion> Shell::complete()
@ -1450,7 +1450,7 @@ Vector<Line::CompletionSuggestion> Shell::complete(StringView line)
if (!ast)
return {};
return ast->complete_for_editor(*this, line.length());
return ast->complete_for_editor(*this, line.length()).release_value_but_fixme_should_propagate_errors();
}
Vector<Line::CompletionSuggestion> Shell::complete_path(StringView base, StringView part, size_t offset, ExecutableOnly executable_only, AST::Node const* command_node, AST::Node const* node, EscapeMode escape_mode)
@ -1691,7 +1691,7 @@ ErrorOr<Vector<Line::CompletionSuggestion>> Shell::complete_via_program_itself(s
if (!node)
return Error::from_string_literal("Cannot complete");
program_name_storage = const_cast<AST::Node&>(*node).run(*this)->resolve_as_string(*this).release_value_but_fixme_should_propagate_errors();
program_name_storage = TRY(TRY(const_cast<AST::Node&>(*node).run(*this))->resolve_as_string(*this));
known_program_name = program_name_storage;
}
@ -1734,8 +1734,11 @@ ErrorOr<Vector<Line::CompletionSuggestion>> Shell::complete_via_program_itself(s
virtual void visit(AST::BraceExpansion const* node) override
{
if (should_include(node))
list().extend(static_cast<AST::Node*>(const_cast<AST::BraceExpansion*>(node))->run(shell)->resolve_as_list(shell).release_value_but_fixme_should_propagate_errors());
if (should_include(node)) {
auto value = static_cast<AST::Node*>(const_cast<AST::BraceExpansion*>(node))->run(shell).release_value_but_fixme_should_propagate_errors();
auto entries = value->resolve_as_list(shell).release_value_but_fixme_should_propagate_errors();
list().extend(move(entries));
}
}
virtual void visit(AST::CommandLiteral const* node) override
@ -1800,14 +1803,20 @@ ErrorOr<Vector<Line::CompletionSuggestion>> Shell::complete_via_program_itself(s
virtual void visit(AST::SimpleVariable const* node) override
{
if (should_include(node))
list().extend(static_cast<AST::Node*>(const_cast<AST::SimpleVariable*>(node))->run(shell)->resolve_as_list(shell).release_value_but_fixme_should_propagate_errors());
if (should_include(node)) {
auto values = static_cast<AST::Node*>(const_cast<AST::SimpleVariable*>(node))->run(shell).release_value_but_fixme_should_propagate_errors();
auto entries = values->resolve_as_list(shell).release_value_but_fixme_should_propagate_errors();
list().extend(move(entries));
}
}
virtual void visit(AST::SpecialVariable const* node) override
{
if (should_include(node))
list().extend(static_cast<AST::Node*>(const_cast<AST::SpecialVariable*>(node))->run(shell)->resolve_as_list(shell).release_value_but_fixme_should_propagate_errors());
if (should_include(node)) {
auto values = static_cast<AST::Node*>(const_cast<AST::SpecialVariable*>(node))->run(shell).release_value_but_fixme_should_propagate_errors();
auto entries = values->resolve_as_list(shell).release_value_but_fixme_should_propagate_errors();
list().extend(move(entries));
}
}
virtual void visit(AST::Juxtaposition const* node) override
@ -1842,8 +1851,11 @@ ErrorOr<Vector<Line::CompletionSuggestion>> Shell::complete_via_program_itself(s
virtual void visit(AST::Tilde const* node) override
{
if (should_include(node))
list().extend(static_cast<AST::Node*>(const_cast<AST::Tilde*>(node))->run(shell)->resolve_as_list(shell).release_value_but_fixme_should_propagate_errors());
if (should_include(node)) {
auto values = static_cast<AST::Node*>(const_cast<AST::Tilde*>(node))->run(shell).release_value_but_fixme_should_propagate_errors();
auto entries = values->resolve_as_list(shell).release_value_but_fixme_should_propagate_errors();
list().extend(move(entries));
}
}
virtual void visit(AST::PathRedirectionNode const*) override { }
@ -1887,8 +1899,8 @@ ErrorOr<Vector<Line::CompletionSuggestion>> Shell::complete_via_program_itself(s
});
{
TemporaryChange change(m_is_interactive, false);
execute_node->for_each_entry(*this, [&](NonnullRefPtr<AST::Value> entry) -> IterationDecision {
auto result = entry->resolve_as_string(*this).release_value_but_fixme_should_propagate_errors();
TRY(execute_node->for_each_entry(*this, [&](NonnullRefPtr<AST::Value> entry) -> ErrorOr<IterationDecision> {
auto result = TRY(entry->resolve_as_string(*this));
JsonParser parser(result);
auto parsed_result = parser.parse();
if (parsed_result.is_error())
@ -1931,7 +1943,7 @@ ErrorOr<Vector<Line::CompletionSuggestion>> Shell::complete_via_program_itself(s
}
return IterationDecision::Continue;
});
}));
}
auto pgid = getpgrp();