summaryrefslogtreecommitdiff
path: root/Userland/DevTools/HackStudio/LanguageServers/Cpp
diff options
context:
space:
mode:
authorItamar <itamar8910@gmail.com>2021-05-16 17:25:24 +0300
committerAndreas Kling <kling@serenityos.org>2021-05-16 16:39:21 +0200
commit400d3ddb08560c9c052423540247039b066439ff (patch)
tree34a3e1b934dd905f610e11417a64c24fe7a7e530 /Userland/DevTools/HackStudio/LanguageServers/Cpp
parentb1531b78f6693d7b5b409ed90342ffd2f6abb7d4 (diff)
downloadserenity-400d3ddb08560c9c052423540247039b066439ff.zip
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.
Diffstat (limited to 'Userland/DevTools/HackStudio/LanguageServers/Cpp')
-rw-r--r--Userland/DevTools/HackStudio/LanguageServers/Cpp/CMakeLists.txt2
-rw-r--r--Userland/DevTools/HackStudio/LanguageServers/Cpp/ClientConnection.h4
-rw-r--r--Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp (renamed from Userland/DevTools/HackStudio/LanguageServers/Cpp/ParserAutoComplete.cpp)68
-rw-r--r--Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.h (renamed from Userland/DevTools/HackStudio/LanguageServers/Cpp/ParserAutoComplete.h)6
-rw-r--r--Userland/DevTools/HackStudio/LanguageServers/Cpp/Tests.cpp14
5 files changed, 47 insertions, 47 deletions
diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/CMakeLists.txt b/Userland/DevTools/HackStudio/LanguageServers/Cpp/CMakeLists.txt
index 19e5edd513..de5895e414 100644
--- a/Userland/DevTools/HackStudio/LanguageServers/Cpp/CMakeLists.txt
+++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/CMakeLists.txt
@@ -1,5 +1,5 @@
set(SOURCES
- ParserAutoComplete.cpp
+ CppComprehensionEngine.cpp
Tests.cpp
main.cpp
)
diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/ClientConnection.h b/Userland/DevTools/HackStudio/LanguageServers/Cpp/ClientConnection.h
index 405727ed46..e3eb4c33a0 100644
--- a/Userland/DevTools/HackStudio/LanguageServers/Cpp/ClientConnection.h
+++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/ClientConnection.h
@@ -6,7 +6,7 @@
#pragma once
-#include "ParserAutoComplete.h"
+#include "CppComprehensionEngine.h"
#include <DevTools/HackStudio/LanguageServers/ClientConnection.h>
namespace LanguageServers::Cpp {
@@ -18,7 +18,7 @@ public:
ClientConnection(NonnullRefPtr<Core::LocalSocket> socket, int client_id)
: LanguageServers::ClientConnection(move(socket), client_id)
{
- m_autocomplete_engine = make<ParserAutoComplete>(m_filedb);
+ m_autocomplete_engine = make<CppComprehensionEngine>(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));
};
diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/ParserAutoComplete.cpp b/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp
index ee6e5bef4b..c637b98a6b 100644
--- a/Userland/DevTools/HackStudio/LanguageServers/Cpp/ParserAutoComplete.cpp
+++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp
@@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include "ParserAutoComplete.h"
+#include "CppComprehensionEngine.h"
#include <AK/Assertions.h>
#include <AK/HashTable.h>
#include <AK/OwnPtr.h>
@@ -17,12 +17,12 @@
namespace LanguageServers::Cpp {
-ParserAutoComplete::ParserAutoComplete(const FileDB& filedb)
- : AutoCompleteEngine(filedb, true)
+CppComprehensionEngine::CppComprehensionEngine(const FileDB& filedb)
+ : CodeComprehensionEngine(filedb, true)
{
}
-const ParserAutoComplete::DocumentData* ParserAutoComplete::get_or_create_document_data(const String& file)
+const CppComprehensionEngine::DocumentData* CppComprehensionEngine::get_or_create_document_data(const String& file)
{
auto absolute_path = filedb().to_absolute_path(file);
if (!m_documents.contains(absolute_path)) {
@@ -31,7 +31,7 @@ const ParserAutoComplete::DocumentData* ParserAutoComplete::get_or_create_docume
return get_document_data(absolute_path);
}
-const ParserAutoComplete::DocumentData* ParserAutoComplete::get_document_data(const String& file) const
+const CppComprehensionEngine::DocumentData* CppComprehensionEngine::get_document_data(const String& file) const
{
auto absolute_path = filedb().to_absolute_path(file);
auto document_data = m_documents.get(absolute_path);
@@ -39,7 +39,7 @@ const ParserAutoComplete::DocumentData* ParserAutoComplete::get_document_data(co
return document_data.value();
}
-OwnPtr<ParserAutoComplete::DocumentData> ParserAutoComplete::create_document_data_for(const String& file)
+OwnPtr<CppComprehensionEngine::DocumentData> CppComprehensionEngine::create_document_data_for(const String& file)
{
auto document = filedb().get_or_create_from_filesystem(file);
if (!document)
@@ -47,16 +47,16 @@ OwnPtr<ParserAutoComplete::DocumentData> ParserAutoComplete::create_document_dat
return create_document_data(document->text(), file);
}
-void ParserAutoComplete::set_document_data(const String& file, OwnPtr<DocumentData>&& data)
+void CppComprehensionEngine::set_document_data(const String& file, OwnPtr<DocumentData>&& data)
{
m_documents.set(filedb().to_absolute_path(file), move(data));
}
-Vector<GUI::AutocompleteProvider::Entry> ParserAutoComplete::get_suggestions(const String& file, const GUI::TextPosition& autocomplete_position)
+Vector<GUI::AutocompleteProvider::Entry> CppComprehensionEngine::get_suggestions(const String& file, const GUI::TextPosition& autocomplete_position)
{
Cpp::Position position { autocomplete_position.line(), autocomplete_position.column() > 0 ? autocomplete_position.column() - 1 : 0 };
- dbgln_if(CPP_LANGUAGE_SERVER_DEBUG, "ParserAutoComplete position {}:{}", position.line, position.column);
+ dbgln_if(CPP_LANGUAGE_SERVER_DEBUG, "CppComprehensionEngine position {}:{}", position.line, position.column);
const auto* document_ptr = get_or_create_document_data(file);
if (!document_ptr)
@@ -86,7 +86,7 @@ Vector<GUI::AutocompleteProvider::Entry> ParserAutoComplete::get_suggestions(con
return {};
}
-Optional<Vector<GUI::AutocompleteProvider::Entry>> ParserAutoComplete::autocomplete_name(const DocumentData& document, const ASTNode& node, Optional<Token> containing_token) const
+Optional<Vector<GUI::AutocompleteProvider::Entry>> CppComprehensionEngine::autocomplete_name(const DocumentData& document, const ASTNode& node, Optional<Token> containing_token) const
{
auto partial_text = String::empty();
if (containing_token.has_value() && containing_token.value().type() != Token::Type::ColonColon) {
@@ -95,7 +95,7 @@ Optional<Vector<GUI::AutocompleteProvider::Entry>> ParserAutoComplete::autocompl
return autocomplete_name(document, node, partial_text);
}
-Optional<Vector<GUI::AutocompleteProvider::Entry>> ParserAutoComplete::autocomplete_property(const DocumentData& document, const ASTNode& node, Optional<Token> containing_token) const
+Optional<Vector<GUI::AutocompleteProvider::Entry>> CppComprehensionEngine::autocomplete_property(const DocumentData& document, const ASTNode& node, Optional<Token> containing_token) const
{
if (!containing_token.has_value())
return {};
@@ -115,7 +115,7 @@ Optional<Vector<GUI::AutocompleteProvider::Entry>> ParserAutoComplete::autocompl
return autocomplete_property(document, parent, partial_text);
}
-NonnullRefPtrVector<Declaration> ParserAutoComplete::get_available_declarations(const DocumentData& document, const ASTNode& node, RecurseIntoScopes recurse_into_scopes) const
+NonnullRefPtrVector<Declaration> CppComprehensionEngine::get_available_declarations(const DocumentData& document, const ASTNode& node, RecurseIntoScopes recurse_into_scopes) const
{
const Cpp::ASTNode* current = &node;
NonnullRefPtrVector<Declaration> available_declarations;
@@ -128,7 +128,7 @@ NonnullRefPtrVector<Declaration> ParserAutoComplete::get_available_declarations(
return available_declarations;
}
-Vector<GUI::AutocompleteProvider::Entry> ParserAutoComplete::autocomplete_name(const DocumentData& document, const ASTNode& node, const String& partial_text) const
+Vector<GUI::AutocompleteProvider::Entry> CppComprehensionEngine::autocomplete_name(const DocumentData& document, const ASTNode& node, const String& partial_text) const
{
auto target_scope = scope_of_name_or_identifier(node);
@@ -183,7 +183,7 @@ Vector<GUI::AutocompleteProvider::Entry> ParserAutoComplete::autocomplete_name(c
return suggestions;
}
-String ParserAutoComplete::scope_of_name_or_identifier(const ASTNode& node) const
+String CppComprehensionEngine::scope_of_name_or_identifier(const ASTNode& node) const
{
const Name* name = nullptr;
if (node.is_name()) {
@@ -206,7 +206,7 @@ String ParserAutoComplete::scope_of_name_or_identifier(const ASTNode& node) cons
return String::join("::", scope_parts);
}
-Vector<GUI::AutocompleteProvider::Entry> ParserAutoComplete::autocomplete_property(const DocumentData& document, const MemberExpression& parent, const String partial_text) const
+Vector<GUI::AutocompleteProvider::Entry> CppComprehensionEngine::autocomplete_property(const DocumentData& document, const MemberExpression& parent, const String partial_text) const
{
auto type = type_of(document, *parent.m_object);
if (type.is_null()) {
@@ -223,7 +223,7 @@ Vector<GUI::AutocompleteProvider::Entry> ParserAutoComplete::autocomplete_proper
return suggestions;
}
-bool ParserAutoComplete::is_property(const ASTNode& node) const
+bool CppComprehensionEngine::is_property(const ASTNode& node) const
{
if (!node.parent()->is_member_expression())
return false;
@@ -232,7 +232,7 @@ bool ParserAutoComplete::is_property(const ASTNode& node) const
return parent.m_property.ptr() == &node;
}
-bool ParserAutoComplete::is_empty_property(const DocumentData& document, const ASTNode& node, const Position& autocomplete_position) const
+bool CppComprehensionEngine::is_empty_property(const DocumentData& document, const ASTNode& node, const Position& autocomplete_position) const
{
if (node.parent() == nullptr)
return false;
@@ -244,7 +244,7 @@ bool ParserAutoComplete::is_empty_property(const DocumentData& document, const A
return previous_token.value().type() == Token::Type::Dot;
}
-String ParserAutoComplete::type_of_property(const DocumentData& document, const Identifier& identifier) const
+String CppComprehensionEngine::type_of_property(const DocumentData& document, const Identifier& identifier) const
{
auto& parent = (const MemberExpression&)(*identifier.parent());
auto properties = properties_of_type(document, type_of(document, *parent.m_object));
@@ -255,7 +255,7 @@ String ParserAutoComplete::type_of_property(const DocumentData& document, const
return {};
}
-String ParserAutoComplete::type_of_variable(const Identifier& identifier) const
+String CppComprehensionEngine::type_of_variable(const Identifier& identifier) const
{
const ASTNode* current = &identifier;
while (current) {
@@ -272,7 +272,7 @@ String ParserAutoComplete::type_of_variable(const Identifier& identifier) const
return {};
}
-String ParserAutoComplete::type_of(const DocumentData& document, const Expression& expression) const
+String CppComprehensionEngine::type_of(const DocumentData& document, const Expression& expression) const
{
if (expression.is_member_expression()) {
auto& member_expression = (const MemberExpression&)expression;
@@ -297,7 +297,7 @@ String ParserAutoComplete::type_of(const DocumentData& document, const Expressio
return type_of_variable(*identifier);
}
-Vector<ParserAutoComplete::PropertyInfo> ParserAutoComplete::properties_of_type(const DocumentData& document, const String& type) const
+Vector<CppComprehensionEngine::PropertyInfo> CppComprehensionEngine::properties_of_type(const DocumentData& document, const String& type) const
{
auto declarations = get_global_declarations_including_headers(document, RecurseIntoScopes::Yes);
Vector<PropertyInfo> properties;
@@ -314,7 +314,7 @@ Vector<ParserAutoComplete::PropertyInfo> ParserAutoComplete::properties_of_type(
return properties;
}
-NonnullRefPtrVector<Declaration> ParserAutoComplete::get_global_declarations_including_headers(const DocumentData& document, RecurseIntoScopes recurse_into_scopes) const
+NonnullRefPtrVector<Declaration> CppComprehensionEngine::get_global_declarations_including_headers(const DocumentData& document, RecurseIntoScopes recurse_into_scopes) const
{
NonnullRefPtrVector<Declaration> declarations;
for (auto& decl : document.m_declarations_from_headers)
@@ -325,14 +325,14 @@ NonnullRefPtrVector<Declaration> ParserAutoComplete::get_global_declarations_inc
return declarations;
}
-NonnullRefPtrVector<Declaration> ParserAutoComplete::get_global_declarations(const DocumentData& document, RecurseIntoScopes recurse_into_scopes) const
+NonnullRefPtrVector<Declaration> CppComprehensionEngine::get_global_declarations(const DocumentData& document, RecurseIntoScopes recurse_into_scopes) const
{
if (recurse_into_scopes == RecurseIntoScopes::Yes)
return get_declarations_recursive(*document.parser().root_node());
return document.parser().root_node()->declarations();
}
-NonnullRefPtrVector<Declaration> ParserAutoComplete::get_declarations_recursive(const ASTNode& node) const
+NonnullRefPtrVector<Declaration> CppComprehensionEngine::get_declarations_recursive(const ASTNode& node) const
{
NonnullRefPtrVector<Declaration> declarations;
@@ -351,7 +351,7 @@ NonnullRefPtrVector<Declaration> ParserAutoComplete::get_declarations_recursive(
return declarations;
}
-String ParserAutoComplete::document_path_from_include_path(const StringView& include_path) const
+String CppComprehensionEngine::document_path_from_include_path(const StringView& include_path) const
{
static Regex<PosixExtended> library_include("<(.+)>");
static Regex<PosixExtended> user_defined_include("\"(.+)\"");
@@ -380,17 +380,17 @@ String ParserAutoComplete::document_path_from_include_path(const StringView& inc
return result;
}
-void ParserAutoComplete::on_edit(const String& file)
+void CppComprehensionEngine::on_edit(const String& file)
{
set_document_data(file, create_document_data_for(file));
}
-void ParserAutoComplete::file_opened([[maybe_unused]] const String& file)
+void CppComprehensionEngine::file_opened([[maybe_unused]] const String& file)
{
get_or_create_document_data(file);
}
-Optional<GUI::AutocompleteProvider::ProjectLocation> ParserAutoComplete::find_declaration_of(const String& filename, const GUI::TextPosition& identifier_position)
+Optional<GUI::AutocompleteProvider::ProjectLocation> CppComprehensionEngine::find_declaration_of(const String& filename, const GUI::TextPosition& identifier_position)
{
const auto* document_ptr = get_or_create_document_data(filename);
if (!document_ptr)
@@ -409,7 +409,7 @@ Optional<GUI::AutocompleteProvider::ProjectLocation> ParserAutoComplete::find_de
return find_preprocessor_definition(document, identifier_position);
}
-Optional<GUI::AutocompleteProvider::ProjectLocation> ParserAutoComplete::find_preprocessor_definition(const DocumentData& document, const GUI::TextPosition& text_position)
+Optional<GUI::AutocompleteProvider::ProjectLocation> CppComprehensionEngine::find_preprocessor_definition(const DocumentData& document, const GUI::TextPosition& text_position)
{
Position cpp_position { text_position.line(), text_position.column() };
@@ -457,7 +457,7 @@ static Optional<TargetDeclaration> get_target_declaration(const ASTNode& node)
return TargetDeclaration { TargetDeclaration::Type::Variable, name };
}
-RefPtr<Declaration> ParserAutoComplete::find_declaration_of(const DocumentData& document_data, const ASTNode& node) const
+RefPtr<Declaration> CppComprehensionEngine::find_declaration_of(const DocumentData& document_data, const ASTNode& node) const
{
dbgln_if(CPP_LANGUAGE_SERVER_DEBUG, "find_declaration_of: {} ({})", document_data.parser().text_of_node(node), node.class_name());
auto target_decl = get_target_declaration(node);
@@ -493,7 +493,7 @@ RefPtr<Declaration> ParserAutoComplete::find_declaration_of(const DocumentData&
return {};
}
-void ParserAutoComplete::update_declared_symbols(DocumentData& document)
+void CppComprehensionEngine::update_declared_symbols(DocumentData& document)
{
for (auto& include : document.preprocessor().included_paths()) {
auto included_document = get_or_create_document_data(document_path_from_include_path(include));
@@ -516,7 +516,7 @@ void ParserAutoComplete::update_declared_symbols(DocumentData& document)
set_declarations_of_document(document.filename(), move(declarations));
}
-GUI::AutocompleteProvider::DeclarationType ParserAutoComplete::type_of_declaration(const Declaration& decl)
+GUI::AutocompleteProvider::DeclarationType CppComprehensionEngine::type_of_declaration(const Declaration& decl)
{
if (decl.is_struct())
return GUI::AutocompleteProvider::DeclarationType::Struct;
@@ -533,7 +533,7 @@ GUI::AutocompleteProvider::DeclarationType ParserAutoComplete::type_of_declarati
return GUI::AutocompleteProvider::DeclarationType::Variable;
}
-OwnPtr<ParserAutoComplete::DocumentData> ParserAutoComplete::create_document_data(String&& text, const String& filename)
+OwnPtr<CppComprehensionEngine::DocumentData> CppComprehensionEngine::create_document_data(String&& text, const String& filename)
{
auto document_data = make<DocumentData>();
document_data->m_filename = move(filename);
@@ -566,7 +566,7 @@ OwnPtr<ParserAutoComplete::DocumentData> ParserAutoComplete::create_document_dat
return document_data;
}
-String ParserAutoComplete::scope_of_declaration(const Declaration& decl) const
+String CppComprehensionEngine::scope_of_declaration(const Declaration& decl) const
{
auto parent = decl.parent();
if (!parent)
diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/ParserAutoComplete.h b/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.h
index c3b735d948..b3f02b970c 100644
--- a/Userland/DevTools/HackStudio/LanguageServers/Cpp/ParserAutoComplete.h
+++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.h
@@ -10,7 +10,7 @@
#include <AK/String.h>
#include <AK/Vector.h>
#include <DevTools/HackStudio/AutoCompleteResponse.h>
-#include <DevTools/HackStudio/LanguageServers/AutoCompleteEngine.h>
+#include <DevTools/HackStudio/LanguageServers/CodeComprehensionEngine.h>
#include <DevTools/HackStudio/LanguageServers/FileDB.h>
#include <LibCpp/AST.h>
#include <LibCpp/Parser.h>
@@ -21,9 +21,9 @@ namespace LanguageServers::Cpp {
using namespace ::Cpp;
-class ParserAutoComplete : public AutoCompleteEngine {
+class CppComprehensionEngine : public CodeComprehensionEngine {
public:
- ParserAutoComplete(const FileDB& filedb);
+ CppComprehensionEngine(const FileDB& filedb);
virtual Vector<GUI::AutocompleteProvider::Entry> get_suggestions(const String& file, const GUI::TextPosition& autocomplete_position) override;
virtual void on_edit(const String& file) override;
diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/Tests.cpp b/Userland/DevTools/HackStudio/LanguageServers/Cpp/Tests.cpp
index 1116fe937e..7f69238596 100644
--- a/Userland/DevTools/HackStudio/LanguageServers/Cpp/Tests.cpp
+++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/Tests.cpp
@@ -6,7 +6,7 @@
#include "Tests.h"
#include "../FileDB.h"
-#include "ParserAutoComplete.h"
+#include "CppComprehensionEngine.h"
using namespace LanguageServers;
using namespace LanguageServers::Cpp;
@@ -57,8 +57,8 @@ ar
}
)";
filedb.add("a.cpp", content);
- ParserAutoComplete autocomplete(filedb);
- auto suggestions = autocomplete.get_suggestions("a.cpp", { 2, 2 });
+ CppComprehensionEngine engine(filedb);
+ auto suggestions = engine.get_suggestions("a.cpp", { 2, 2 });
if (suggestions.size() != 2)
FAIL(bad size);
@@ -79,7 +79,7 @@ myv
}
)";
filedb.add("a.cpp", content);
- ParserAutoComplete autocomplete(filedb);
+ CppComprehensionEngine autocomplete(filedb);
auto suggestions = autocomplete.get_suggestions("a.cpp", { 3, 3 });
if (suggestions.size() != 1)
FAIL(bad size);
@@ -103,7 +103,7 @@ MyS
}
)";
filedb.add("a.cpp", content);
- ParserAutoComplete autocomplete(filedb);
+ CppComprehensionEngine autocomplete(filedb);
auto suggestions = autocomplete.get_suggestions("a.cpp", { 5, 3 });
if (suggestions.size() != 1)
FAIL(bad size);
@@ -124,8 +124,8 @@ argv = nullptr;
}
)";
filedb.add("a.cpp", content);
- ParserAutoComplete autocomplete(filedb);
- auto position = autocomplete.find_declaration_of("a.cpp", { 2, 1 });
+ CppComprehensionEngine engine(filedb);
+ auto position = engine.find_declaration_of("a.cpp", { 2, 1 });
if (!position.has_value())
FAIL("declaration not found");