2021-02-06 16:25:15 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021, Itamar S. <itamar8910@gmail.com>
|
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-02-06 16:25:15 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "AutoCompleteEngine.h"
|
|
|
|
|
|
2021-03-02 09:40:10 +03:30
|
|
|
namespace LanguageServers {
|
2021-02-27 09:42:57 +02:00
|
|
|
|
2021-03-02 09:40:10 +03:30
|
|
|
AutoCompleteEngine::AutoCompleteEngine(ClientConnection& connection, const FileDB& filedb, bool should_store_all_declarations)
|
2021-02-27 09:42:57 +02:00
|
|
|
: m_connection(connection)
|
|
|
|
|
, 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
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AutoCompleteEngine::~AutoCompleteEngine()
|
|
|
|
|
{
|
|
|
|
|
}
|
2021-02-27 09:42:57 +02:00
|
|
|
void AutoCompleteEngine::set_declarations_of_document(const String& filename, Vector<GUI::AutocompleteProvider::Declaration>&& declarations)
|
|
|
|
|
{
|
|
|
|
|
VERIFY(set_declarations_of_document_callback);
|
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-04-10 17:35:55 +03:00
|
|
|
if (auto previous_declarations = m_all_declarations.get(filename); previous_declarations.has_value()) {
|
|
|
|
|
if (previous_declarations.value() == declarations)
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-03-02 09:40:10 +03:30
|
|
|
if (m_store_all_declarations)
|
|
|
|
|
m_all_declarations.set(filename, declarations);
|
2021-02-27 09:42:57 +02:00
|
|
|
set_declarations_of_document_callback(m_connection, filename, move(declarations));
|
|
|
|
|
}
|
|
|
|
|
}
|