summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorItamar <itamar8910@gmail.com>2022-02-27 21:24:14 +0200
committerAndreas Kling <kling@serenityos.org>2022-02-27 21:42:05 +0100
commit7fa7c7d63cb4abd4c1fd9116b2288bdec6896990 (patch)
treee23f8792b19dff8d67714d3e7bb25da0ffc73bd0
parent4335bd453d67b21275f598b43e506148b90c7ddf (diff)
downloadserenity-7fa7c7d63cb4abd4c1fd9116b2288bdec6896990.zip
LanguageServers/Cpp: Make find declaration of enums work
-rw-r--r--Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp6
-rw-r--r--Userland/Libraries/LibCpp/AST.h2
2 files changed, 5 insertions, 3 deletions
diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp b/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp
index 7cf0360d9f..33d2727eb0 100644
--- a/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp
+++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp
@@ -482,7 +482,7 @@ static Optional<TargetDeclaration> get_target_declaration(const ASTNode& node, S
}
if (name_node.parent() && name_node.parent()->is_declaration()) {
auto declaration = verify_cast<Declaration>(name_node.parent());
- if (declaration->is_struct_or_class()) {
+ if (declaration->is_struct_or_class() || declaration->is_enum()) {
return TargetDeclaration { TargetDeclaration::Type::Type, name };
}
if (declaration->is_function()) {
@@ -517,7 +517,7 @@ RefPtr<Declaration> CppComprehensionEngine::find_declaration_of(const DocumentDa
auto symbol_matches = [&](const Symbol& symbol) {
bool match_function = target_decl.value().type == TargetDeclaration::Function && symbol.declaration->is_function();
bool match_variable = target_decl.value().type == TargetDeclaration::Variable && symbol.declaration->is_variable_declaration();
- bool match_type = target_decl.value().type == TargetDeclaration::Type && symbol.declaration->is_struct_or_class();
+ bool match_type = target_decl.value().type == TargetDeclaration::Type && (symbol.declaration->is_struct_or_class() || symbol.declaration->is_enum());
bool match_property = target_decl.value().type == TargetDeclaration::Property && symbol.declaration->parent()->is_declaration() && verify_cast<Declaration>(symbol.declaration->parent())->is_struct_or_class();
bool match_parameter = target_decl.value().type == TargetDeclaration::Variable && symbol.declaration->is_parameter();
bool match_scope = target_decl.value().type == TargetDeclaration::Scope && (symbol.declaration->is_namespace() || symbol.declaration->is_struct_or_class());
@@ -990,7 +990,7 @@ GUI::AutocompleteProvider::TokenInfo::SemanticType CppComprehensionEngine::get_s
return GUI::AutocompleteProvider::TokenInfo::SemanticType::Member;
return GUI::AutocompleteProvider::TokenInfo::SemanticType::Variable;
}
- if (decl->is_struct_or_class())
+ if (decl->is_struct_or_class() || decl->is_enum())
return GUI::AutocompleteProvider::TokenInfo::SemanticType::CustomType;
if (decl->is_namespace())
return GUI::AutocompleteProvider::TokenInfo::SemanticType::Namespace;
diff --git a/Userland/Libraries/LibCpp/AST.h b/Userland/Libraries/LibCpp/AST.h
index 537ab5509c..f5a6d11eaf 100644
--- a/Userland/Libraries/LibCpp/AST.h
+++ b/Userland/Libraries/LibCpp/AST.h
@@ -124,6 +124,7 @@ public:
virtual bool is_class() const { return false; }
virtual bool is_function() const { return false; }
virtual bool is_namespace() const { return false; }
+ virtual bool is_enum() const { return false; }
bool is_member() const { return parent() != nullptr && parent()->is_declaration() && verify_cast<Declaration>(parent())->is_struct_or_class(); }
const Name* name() const { return m_name; }
StringView full_name() const;
@@ -655,6 +656,7 @@ public:
virtual ~EnumDeclaration() override = default;
virtual const char* class_name() const override { return "EnumDeclaration"; }
virtual void dump(FILE* = stdout, size_t indent = 0) const override;
+ virtual bool is_enum() const override { return true; }
EnumDeclaration(ASTNode* parent, Optional<Position> start, Optional<Position> end, const String& filename)
: Declaration(parent, start, end, filename)