mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-09 04:37:52 +03:00
Shell: Complete named function parameters inside the function body
This commit is contained in:
parent
b4da45ab76
commit
2b867ff555
Notes:
sideshowbarker
2024-07-19 02:24:53 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/2b867ff555f Pull-request: https://github.com/SerenityOS/serenity/pull/3473 Reviewed-by: https://github.com/bugaevc
@ -807,7 +807,35 @@ HitTestResult FunctionDeclaration::hit_test_position(size_t offset)
|
||||
if (!position().contains(offset))
|
||||
return {};
|
||||
|
||||
return m_block->hit_test_position(offset);
|
||||
auto result = m_block->hit_test_position(offset);
|
||||
if (result.matching_node && result.matching_node->is_simple_variable())
|
||||
result.closest_node_with_semantic_meaning = this;
|
||||
return result;
|
||||
}
|
||||
|
||||
Vector<Line::CompletionSuggestion> FunctionDeclaration::complete_for_editor(Shell& shell, size_t offset, const HitTestResult& hit_test_result)
|
||||
{
|
||||
auto matching_node = hit_test_result.matching_node;
|
||||
if (!matching_node)
|
||||
return {};
|
||||
|
||||
if (!matching_node->is_simple_variable())
|
||||
return matching_node->complete_for_editor(shell, offset, hit_test_result);
|
||||
|
||||
auto corrected_offset = offset - matching_node->position().start_offset - 1; // Skip the first '$'
|
||||
auto* node = static_cast<SimpleVariable*>(matching_node.ptr());
|
||||
|
||||
auto name = node->name().substring_view(0, corrected_offset);
|
||||
|
||||
Vector<Line::CompletionSuggestion> results;
|
||||
for (auto& arg : m_arguments) {
|
||||
if (arg.name.starts_with(name))
|
||||
results.append(arg.name);
|
||||
}
|
||||
|
||||
results.append(matching_node->complete_for_editor(shell, offset, hit_test_result));
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
FunctionDeclaration::FunctionDeclaration(Position position, NameWithPosition name, Vector<NameWithPosition> arguments, RefPtr<AST::Node> body)
|
||||
|
@ -392,6 +392,7 @@ public:
|
||||
virtual bool is_glob() const { return false; }
|
||||
virtual bool is_tilde() const { return false; }
|
||||
virtual bool is_variable_decls() const { return false; }
|
||||
virtual bool is_simple_variable() const { return false; }
|
||||
virtual bool is_syntax_error() const { return m_is_syntax_error; }
|
||||
|
||||
virtual bool is_list() const { return false; }
|
||||
@ -650,6 +651,7 @@ private:
|
||||
virtual RefPtr<Value> run(RefPtr<Shell>) override;
|
||||
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
|
||||
virtual HitTestResult hit_test_position(size_t) override;
|
||||
virtual Vector<Line::CompletionSuggestion> complete_for_editor(Shell&, size_t, const HitTestResult&) override;
|
||||
virtual String class_name() const override { return "FunctionDeclaration"; }
|
||||
virtual bool would_execute() const override { return true; }
|
||||
|
||||
@ -849,6 +851,8 @@ public:
|
||||
SimpleVariable(Position, String);
|
||||
virtual ~SimpleVariable();
|
||||
|
||||
const String& name() const { return m_name; }
|
||||
|
||||
private:
|
||||
virtual void dump(int level) const override;
|
||||
virtual RefPtr<Value> run(RefPtr<Shell>) override;
|
||||
@ -856,6 +860,7 @@ private:
|
||||
virtual Vector<Line::CompletionSuggestion> complete_for_editor(Shell&, size_t, const HitTestResult&) override;
|
||||
virtual HitTestResult hit_test_position(size_t) override;
|
||||
virtual String class_name() const override { return "SimpleVariable"; }
|
||||
virtual bool is_simple_variable() const override { return true; }
|
||||
|
||||
String m_name;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user