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

HackStudio: Keep the DeclarationsModel around, and use a filtering proxy

Rather than construct a new DeclarationsModel each time the user types
something in the Locator, keep a single one around permanently in the
ProjectDeclarations, and then use a FilteringProxyModel over it for the
suggestions.
This commit is contained in:
Sam Atkins 2024-01-25 14:19:15 +00:00 committed by Sam Atkins
parent e72b14ef1d
commit 85101c6626
6 changed files with 78 additions and 22 deletions

View file

@ -1,24 +1,35 @@
/*
* Copyright (c) 2021, Itamar S. <itamar8910@gmail.com>
* Copyright (c) 2024, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "ProjectDeclarations.h"
#include "HackStudio.h"
HackStudio::ProjectDeclarations& HackStudio::ProjectDeclarations::the()
namespace HackStudio {
ProjectDeclarations::ProjectDeclarations()
: m_declarations_model(adopt_ref(*new DeclarationsModel({})))
{
}
ProjectDeclarations& ProjectDeclarations::the()
{
static ProjectDeclarations s_instance;
return s_instance;
}
void HackStudio::ProjectDeclarations::set_declared_symbols(ByteString const& filename, Vector<CodeComprehension::Declaration> const& declarations)
void ProjectDeclarations::set_declared_symbols(ByteString const& filename, Vector<CodeComprehension::Declaration> const& declarations)
{
m_document_to_declarations.set(filename, declarations);
// FIXME: Partially invalidate the model instead of fully rebuilding it.
update_declarations_model();
if (on_update)
on_update();
}
Optional<GUI::Icon> HackStudio::ProjectDeclarations::get_icon_for(CodeComprehension::DeclarationType type)
Optional<GUI::Icon> ProjectDeclarations::get_icon_for(CodeComprehension::DeclarationType type)
{
static GUI::Icon struct_icon(Gfx::Bitmap::load_from_file("/res/icons/hackstudio/Struct.png"sv).release_value_but_fixme_should_propagate_errors());
static GUI::Icon class_icon(Gfx::Bitmap::load_from_file("/res/icons/hackstudio/Class.png"sv).release_value_but_fixme_should_propagate_errors());
@ -46,3 +57,17 @@ Optional<GUI::Icon> HackStudio::ProjectDeclarations::get_icon_for(CodeComprehens
return {};
}
}
void ProjectDeclarations::update_declarations_model()
{
Vector<Declaration> declarations;
project().for_each_text_file([&](auto& file) {
declarations.append(Declaration::create_filename(file.name()));
});
for_each_declared_symbol([&declarations](auto& decl) {
declarations.append((Declaration::create_symbol_declaration(decl)));
});
m_declarations_model->set_declarations(move(declarations));
}
}