1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:17:36 +00:00

Spreadsheet: Document runtime functions and add a help window

...that can automatically generate documentation pages from the objects.
This commit is contained in:
AnotherTest 2020-08-24 20:05:20 +04:30 committed by Andreas Kling
parent 12cf3e13c0
commit 3a07f6e345
8 changed files with 352 additions and 2 deletions

View file

@ -28,9 +28,11 @@
#include <AK/GenericLexer.h>
#include <AK/JsonArray.h>
#include <AK/JsonObject.h>
#include <AK/JsonParser.h>
#include <LibCore/File.h>
#include <LibJS/Parser.h>
#include <LibJS/Runtime/Error.h>
#include <LibJS/Runtime/Function.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/Object.h>
@ -208,7 +210,6 @@ JS::Value Sheet::evaluate(const StringView& source, Cell* on_behalf_of)
void Cell::update_data()
{
dbg() << "Update cell " << this << ", dirty=" << dirty;
TemporaryChange cell_change { sheet->current_evaluated_cell(), this };
if (!dirty)
return;
@ -325,4 +326,35 @@ JsonObject Sheet::to_json() const
return object;
}
JsonObject Sheet::gather_documentation() const
{
JsonObject object;
const JS::PropertyName doc_name { "__documentation" };
auto& global_object = m_interpreter->global_object();
for (auto& it : global_object.shape().property_table()) {
auto value = global_object.get(it.key);
if (!value.is_function())
continue;
auto& fn = value.as_function();
if (!fn.has_own_property(doc_name))
continue;
auto doc = fn.get(doc_name);
if (!doc.is_string())
continue;
JsonParser parser(doc.to_string_without_side_effects());
auto doc_object = parser.parse();
if (doc_object.has_value())
object.set(it.key.to_display_string(), doc_object.value());
else
dbg() << "Sheet::gather_documentation(): Failed to parse the documentation for '" << it.key.to_display_string() << "'!";
}
return object;
}
}