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