CodeComprehensionEngine.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Copyright (c) 2021, Itamar S. <itamar8910@gmail.com>
  3. * Copyright (c) 2022, the SerenityOS developers.
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include "CodeComprehensionEngine.h"
  8. namespace CodeComprehension {
  9. CodeComprehensionEngine::CodeComprehensionEngine(FileDB const& filedb, bool should_store_all_declarations)
  10. : m_filedb(filedb)
  11. , m_store_all_declarations(should_store_all_declarations)
  12. {
  13. }
  14. void CodeComprehensionEngine::set_declarations_of_document(String const& filename, Vector<Declaration>&& declarations)
  15. {
  16. // Callback may not be configured if we're running tests
  17. if (!set_declarations_of_document_callback)
  18. return;
  19. // Optimization - Only notify callback if declarations have changed
  20. if (auto previous_declarations = m_all_declarations.find(filename); previous_declarations != m_all_declarations.end()) {
  21. if (previous_declarations->value == declarations)
  22. return;
  23. }
  24. if (m_store_all_declarations)
  25. m_all_declarations.set(filename, declarations);
  26. set_declarations_of_document_callback(filename, move(declarations));
  27. }
  28. void CodeComprehensionEngine::set_todo_entries_of_document(String const& filename, Vector<TodoEntry>&& todo_entries)
  29. {
  30. // Callback may not be configured if we're running tests
  31. if (!set_todo_entries_of_document_callback)
  32. return;
  33. set_todo_entries_of_document_callback(filename, move(todo_entries));
  34. }
  35. }