Serenity Operating System
at master 42 lines 1.5 kB view raw
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 8#include "CodeComprehensionEngine.h" 9 10namespace CodeComprehension { 11 12CodeComprehensionEngine::CodeComprehensionEngine(FileDB const& filedb, bool should_store_all_declarations) 13 : m_filedb(filedb) 14 , m_store_all_declarations(should_store_all_declarations) 15{ 16} 17 18void CodeComprehensionEngine::set_declarations_of_document(DeprecatedString const& filename, Vector<Declaration>&& declarations) 19{ 20 // Callback may not be configured if we're running tests 21 if (!set_declarations_of_document_callback) 22 return; 23 24 // Optimization - Only notify callback if declarations have changed 25 if (auto previous_declarations = m_all_declarations.find(filename); previous_declarations != m_all_declarations.end()) { 26 if (previous_declarations->value == declarations) 27 return; 28 } 29 if (m_store_all_declarations) 30 m_all_declarations.set(filename, declarations); 31 set_declarations_of_document_callback(filename, move(declarations)); 32} 33 34void CodeComprehensionEngine::set_todo_entries_of_document(DeprecatedString const& filename, Vector<TodoEntry>&& todo_entries) 35{ 36 // Callback may not be configured if we're running tests 37 if (!set_todo_entries_of_document_callback) 38 return; 39 set_todo_entries_of_document_callback(filename, move(todo_entries)); 40} 41 42}