2021-02-06 11:25:15 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021, Itamar S. <itamar8910@gmail.com>
|
2022-02-15 17:28:01 -03:00
|
|
|
* Copyright (c) 2022, the SerenityOS developers.
|
2021-02-06 11:25:15 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-02-06 11:25:15 -03:00
|
|
|
*/
|
|
|
|
|
|
2021-05-16 11:25:24 -03:00
|
|
|
#include "CodeComprehensionEngine.h"
|
2021-02-06 11:25:15 -03:00
|
|
|
|
2022-05-14 11:09:24 -03:00
|
|
|
namespace CodeComprehension {
|
2021-02-27 04:42:57 -03:00
|
|
|
|
2022-04-01 14:58:27 -03:00
|
|
|
CodeComprehensionEngine::CodeComprehensionEngine(FileDB const& filedb, bool should_store_all_declarations)
|
2021-05-14 04:20:17 -03:00
|
|
|
: m_filedb(filedb)
|
2021-03-02 03:10:10 -03:00
|
|
|
, m_store_all_declarations(should_store_all_declarations)
|
2021-02-06 11:25:15 -03:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-14 11:09:24 -03:00
|
|
|
void CodeComprehensionEngine::set_declarations_of_document(String const& filename, Vector<Declaration>&& declarations)
|
2021-02-27 04:42:57 -03:00
|
|
|
{
|
2021-06-27 15:46:23 -03:00
|
|
|
// Callback may not be configured if we're running tests
|
2021-05-14 03:42:52 -03:00
|
|
|
if (!set_declarations_of_document_callback)
|
|
|
|
|
return;
|
2021-04-10 11:35:55 -03:00
|
|
|
|
2021-04-18 05:30:03 -03:00
|
|
|
// Optimization - Only notify callback if declarations have changed
|
2021-12-05 08:10:17 -03:00
|
|
|
if (auto previous_declarations = m_all_declarations.find(filename); previous_declarations != m_all_declarations.end()) {
|
|
|
|
|
if (previous_declarations->value == declarations)
|
2021-04-10 11:35:55 -03:00
|
|
|
return;
|
|
|
|
|
}
|
2021-03-02 03:10:10 -03:00
|
|
|
if (m_store_all_declarations)
|
|
|
|
|
m_all_declarations.set(filename, declarations);
|
2021-05-14 04:20:17 -03:00
|
|
|
set_declarations_of_document_callback(filename, move(declarations));
|
2021-02-27 04:42:57 -03:00
|
|
|
}
|
2021-05-17 17:19:50 -03:00
|
|
|
|
2022-05-14 11:09:24 -03:00
|
|
|
void CodeComprehensionEngine::set_todo_entries_of_document(String const& filename, Vector<TodoEntry>&& todo_entries)
|
2021-05-17 17:19:50 -03:00
|
|
|
{
|
2021-06-27 15:46:23 -03:00
|
|
|
// Callback may not be configured if we're running tests
|
|
|
|
|
if (!set_todo_entries_of_document_callback)
|
|
|
|
|
return;
|
2021-05-17 17:19:50 -03:00
|
|
|
set_todo_entries_of_document_callback(filename, move(todo_entries));
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-27 04:42:57 -03:00
|
|
|
}
|