mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
js: Allow for completion of lexically declared variables
This does require us to have a method which lists all the bindings in a declarative environment which is not in the spec.
This commit is contained in:
parent
0be0e7ea6e
commit
f4f1397735
Notes:
sideshowbarker
2024-07-18 03:08:32 +09:00
Author: https://github.com/davidot Commit: https://github.com/SerenityOS/serenity/commit/f4f13977355 Pull-request: https://github.com/SerenityOS/serenity/pull/10333 Reviewed-by: https://github.com/linusg ✅
3 changed files with 18 additions and 0 deletions
|
@ -142,4 +142,13 @@ void DeclarativeEnvironment::initialize_or_set_mutable_binding(Badge<ScopeNode>,
|
|||
set_mutable_binding(global_object, name, value, false);
|
||||
}
|
||||
|
||||
Vector<String> DeclarativeEnvironment::bindings() const
|
||||
{
|
||||
Vector<String> names;
|
||||
for (auto& binding : m_bindings) {
|
||||
names.empend(binding.key);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,6 +31,9 @@ public:
|
|||
|
||||
void initialize_or_set_mutable_binding(Badge<ScopeNode>, GlobalObject& global_object, FlyString const& name, Value value);
|
||||
|
||||
// This is not a method defined in the spec! Do not use this in any LibJS (or other spec related) code.
|
||||
[[nodiscard]] Vector<String> bindings() const;
|
||||
|
||||
protected:
|
||||
virtual void visit_edges(Visitor&) override;
|
||||
|
||||
|
|
|
@ -1361,6 +1361,12 @@ int main(int argc, char** argv)
|
|||
case CompleteVariable: {
|
||||
auto const& variable = interpreter->global_object();
|
||||
list_all_properties(variable.shape(), variable_name);
|
||||
|
||||
for (String& name : global_environment.declarative_record().bindings()) {
|
||||
if (name.starts_with(variable_name))
|
||||
results.empend(name);
|
||||
}
|
||||
|
||||
if (results.size())
|
||||
editor.suggest(variable_name.length());
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue