mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:27:45 +00:00
LanguageServers: Rename AutoCompleteEngine => CodeComprehensionEngine
This feels like a better name since the "autocomplete engine" can, in addition to providing autocomplete suggestions, also find declarations of symbols and report back the symbols that are defined in a document. Also, Cpp/ParserAutoComplete has been renamed to CppComprehensionEngine and Shell/AutoComplete has been renamed to ShellComprehensionEngine.
This commit is contained in:
parent
b1531b78f6
commit
400d3ddb08
13 changed files with 82 additions and 82 deletions
|
@ -1,5 +1,5 @@
|
|||
set(SOURCES
|
||||
AutoComplete.cpp
|
||||
ShellComprehensionEngine.cpp
|
||||
main.cpp
|
||||
)
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "AutoComplete.h"
|
||||
#include "ShellComprehensionEngine.h"
|
||||
#include <DevTools/HackStudio/LanguageServers/ClientConnection.h>
|
||||
|
||||
namespace LanguageServers::Shell {
|
||||
|
@ -17,7 +17,7 @@ class ClientConnection final : public LanguageServers::ClientConnection {
|
|||
ClientConnection(NonnullRefPtr<Core::LocalSocket> socket, int client_id)
|
||||
: LanguageServers::ClientConnection(move(socket), client_id)
|
||||
{
|
||||
m_autocomplete_engine = make<AutoComplete>(m_filedb);
|
||||
m_autocomplete_engine = make<ShellComprehensionEngine>(m_filedb);
|
||||
m_autocomplete_engine->set_declarations_of_document_callback = [this](const String& filename, Vector<GUI::AutocompleteProvider::Declaration>&& declarations) {
|
||||
async_declarations_in_document(filename, move(declarations));
|
||||
};
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "AutoComplete.h"
|
||||
#include "ShellComprehensionEngine.h"
|
||||
#include <AK/Assertions.h>
|
||||
#include <AK/HashTable.h>
|
||||
#include <LibRegex/Regex.h>
|
||||
|
@ -12,14 +12,14 @@
|
|||
|
||||
namespace LanguageServers::Shell {
|
||||
|
||||
RefPtr<::Shell::Shell> AutoComplete::s_shell {};
|
||||
RefPtr<::Shell::Shell> ShellComprehensionEngine::s_shell {};
|
||||
|
||||
AutoComplete::AutoComplete(const FileDB& filedb)
|
||||
: AutoCompleteEngine(filedb, true)
|
||||
ShellComprehensionEngine::ShellComprehensionEngine(const FileDB& filedb)
|
||||
: CodeComprehensionEngine(filedb, true)
|
||||
{
|
||||
}
|
||||
|
||||
const AutoComplete::DocumentData& AutoComplete::get_or_create_document_data(const String& file)
|
||||
const ShellComprehensionEngine::DocumentData& ShellComprehensionEngine::get_or_create_document_data(const String& file)
|
||||
{
|
||||
auto absolute_path = filedb().to_absolute_path(file);
|
||||
if (!m_documents.contains(absolute_path)) {
|
||||
|
@ -28,7 +28,7 @@ const AutoComplete::DocumentData& AutoComplete::get_or_create_document_data(cons
|
|||
return get_document_data(absolute_path);
|
||||
}
|
||||
|
||||
const AutoComplete::DocumentData& AutoComplete::get_document_data(const String& file) const
|
||||
const ShellComprehensionEngine::DocumentData& ShellComprehensionEngine::get_document_data(const String& file) const
|
||||
{
|
||||
auto absolute_path = filedb().to_absolute_path(file);
|
||||
auto document_data = m_documents.get(absolute_path);
|
||||
|
@ -36,7 +36,7 @@ const AutoComplete::DocumentData& AutoComplete::get_document_data(const String&
|
|||
return *document_data.value();
|
||||
}
|
||||
|
||||
OwnPtr<AutoComplete::DocumentData> AutoComplete::create_document_data_for(const String& file)
|
||||
OwnPtr<ShellComprehensionEngine::DocumentData> ShellComprehensionEngine::create_document_data_for(const String& file)
|
||||
{
|
||||
auto document = filedb().get(file);
|
||||
if (!document)
|
||||
|
@ -50,19 +50,19 @@ OwnPtr<AutoComplete::DocumentData> AutoComplete::create_document_data_for(const
|
|||
return document_data;
|
||||
}
|
||||
|
||||
void AutoComplete::set_document_data(const String& file, OwnPtr<DocumentData>&& data)
|
||||
void ShellComprehensionEngine::set_document_data(const String& file, OwnPtr<DocumentData>&& data)
|
||||
{
|
||||
m_documents.set(filedb().to_absolute_path(file), move(data));
|
||||
}
|
||||
|
||||
AutoComplete::DocumentData::DocumentData(String&& _text, String _filename)
|
||||
ShellComprehensionEngine::DocumentData::DocumentData(String&& _text, String _filename)
|
||||
: filename(move(_filename))
|
||||
, text(move(_text))
|
||||
, node(parse())
|
||||
{
|
||||
}
|
||||
|
||||
const Vector<String>& AutoComplete::DocumentData::sourced_paths() const
|
||||
const Vector<String>& ShellComprehensionEngine::DocumentData::sourced_paths() const
|
||||
{
|
||||
if (all_sourced_paths.has_value())
|
||||
return all_sourced_paths.value();
|
||||
|
@ -101,7 +101,7 @@ const Vector<String>& AutoComplete::DocumentData::sourced_paths() const
|
|||
return all_sourced_paths.value();
|
||||
}
|
||||
|
||||
NonnullRefPtr<::Shell::AST::Node> AutoComplete::DocumentData::parse() const
|
||||
NonnullRefPtr<::Shell::AST::Node> ShellComprehensionEngine::DocumentData::parse() const
|
||||
{
|
||||
::Shell::Parser parser { text };
|
||||
if (auto node = parser.parse())
|
||||
|
@ -110,7 +110,7 @@ NonnullRefPtr<::Shell::AST::Node> AutoComplete::DocumentData::parse() const
|
|||
return ::Shell::AST::create<::Shell::AST::SyntaxError>(::Shell::AST::Position {}, "Unable to parse file");
|
||||
}
|
||||
|
||||
size_t AutoComplete::resolve(const AutoComplete::DocumentData& document, const GUI::TextPosition& position)
|
||||
size_t ShellComprehensionEngine::resolve(const ShellComprehensionEngine::DocumentData& document, const GUI::TextPosition& position)
|
||||
{
|
||||
size_t offset = 0;
|
||||
|
||||
|
@ -133,9 +133,9 @@ size_t AutoComplete::resolve(const AutoComplete::DocumentData& document, const G
|
|||
return offset;
|
||||
}
|
||||
|
||||
Vector<GUI::AutocompleteProvider::Entry> AutoComplete::get_suggestions(const String& file, const GUI::TextPosition& position)
|
||||
Vector<GUI::AutocompleteProvider::Entry> ShellComprehensionEngine::get_suggestions(const String& file, const GUI::TextPosition& position)
|
||||
{
|
||||
dbgln_if(SH_LANGUAGE_SERVER_DEBUG, "AutoComplete position {}:{}", position.line(), position.column());
|
||||
dbgln_if(SH_LANGUAGE_SERVER_DEBUG, "ShellComprehensionEngine position {}:{}", position.line(), position.column());
|
||||
|
||||
const auto& document = get_or_create_document_data(file);
|
||||
size_t offset_in_file = resolve(document, position);
|
||||
|
@ -154,17 +154,17 @@ Vector<GUI::AutocompleteProvider::Entry> AutoComplete::get_suggestions(const Str
|
|||
return entries;
|
||||
}
|
||||
|
||||
void AutoComplete::on_edit(const String& file)
|
||||
void ShellComprehensionEngine::on_edit(const String& file)
|
||||
{
|
||||
set_document_data(file, create_document_data_for(file));
|
||||
}
|
||||
|
||||
void AutoComplete::file_opened([[maybe_unused]] const String& file)
|
||||
void ShellComprehensionEngine::file_opened([[maybe_unused]] const String& file)
|
||||
{
|
||||
set_document_data(file, create_document_data_for(file));
|
||||
}
|
||||
|
||||
Optional<GUI::AutocompleteProvider::ProjectLocation> AutoComplete::find_declaration_of(const String& filename, const GUI::TextPosition& identifier_position)
|
||||
Optional<GUI::AutocompleteProvider::ProjectLocation> ShellComprehensionEngine::find_declaration_of(const String& filename, const GUI::TextPosition& identifier_position)
|
||||
{
|
||||
dbgln_if(SH_LANGUAGE_SERVER_DEBUG, "find_declaration_of({}, {}:{})", filename, identifier_position.line(), identifier_position.column());
|
||||
const auto& document = get_or_create_document_data(filename);
|
||||
|
@ -192,7 +192,7 @@ Optional<GUI::AutocompleteProvider::ProjectLocation> AutoComplete::find_declarat
|
|||
return {};
|
||||
}
|
||||
|
||||
void AutoComplete::update_declared_symbols(const DocumentData& document)
|
||||
void ShellComprehensionEngine::update_declared_symbols(const DocumentData& document)
|
||||
{
|
||||
struct Visitor : public ::Shell::AST::NodeVisitor {
|
||||
explicit Visitor(const String& filename)
|
|
@ -6,14 +6,14 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <DevTools/HackStudio/LanguageServers/AutoCompleteEngine.h>
|
||||
#include <DevTools/HackStudio/LanguageServers/CodeComprehensionEngine.h>
|
||||
#include <Shell/Shell.h>
|
||||
|
||||
namespace LanguageServers::Shell {
|
||||
|
||||
class AutoComplete : public AutoCompleteEngine {
|
||||
class ShellComprehensionEngine : public CodeComprehensionEngine {
|
||||
public:
|
||||
AutoComplete(const FileDB& filedb);
|
||||
ShellComprehensionEngine(const FileDB& filedb);
|
||||
virtual Vector<GUI::AutocompleteProvider::Entry> get_suggestions(const String& file, const GUI::TextPosition& position) override;
|
||||
virtual void on_edit(const String& file) override;
|
||||
virtual void file_opened([[maybe_unused]] const String& file) override;
|
||||
|
@ -42,7 +42,7 @@ private:
|
|||
String document_path_from_include_path(const StringView& include_path) const;
|
||||
void update_declared_symbols(const DocumentData&);
|
||||
|
||||
static size_t resolve(const AutoComplete::DocumentData& document, const GUI::TextPosition& position);
|
||||
static size_t resolve(const ShellComprehensionEngine::DocumentData& document, const GUI::TextPosition& position);
|
||||
|
||||
::Shell::Shell& shell()
|
||||
{
|
Loading…
Add table
Add a link
Reference in a new issue