diff options
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/DevTools/HackStudio/LanguageServers/Cpp/ParserAutoComplete.cpp | 24 | ||||
-rw-r--r-- | Userland/Libraries/LibCpp/AST.cpp | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibCpp/AST.h | 4 |
3 files changed, 23 insertions, 12 deletions
diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/ParserAutoComplete.cpp b/Userland/DevTools/HackStudio/LanguageServers/Cpp/ParserAutoComplete.cpp index b526bfa2af..9ef47ec73a 100644 --- a/Userland/DevTools/HackStudio/LanguageServers/Cpp/ParserAutoComplete.cpp +++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/ParserAutoComplete.cpp @@ -308,6 +308,11 @@ NonnullRefPtrVector<Declaration> ParserAutoComplete::get_global_declarations(con if (decl.is_namespace()) { declarations.append(get_global_declarations(decl)); } + if (decl.is_struct_or_class()) { + for (auto& member_decl : static_cast<StructOrClassDeclaration&>(decl).declarations()) { + declarations.append(member_decl); + } + } } return declarations; @@ -511,7 +516,6 @@ OwnPtr<ParserAutoComplete::DocumentData> ParserAutoComplete::create_document_dat String ParserAutoComplete::scope_of_declaration(const Declaration& decl) { - auto parent = decl.parent(); if (!parent) return {}; @@ -521,15 +525,17 @@ String ParserAutoComplete::scope_of_declaration(const Declaration& decl) auto& parent_decl = static_cast<Declaration&>(*parent); - if (parent_decl.is_namespace()) { - auto& containing_namespace = static_cast<NamespaceDeclaration&>(parent_decl); - auto scope_of_parent = scope_of_declaration(parent_decl); - if (scope_of_parent.is_null()) - return containing_namespace.m_name; - return String::formatted("{}::{}", scope_of_parent, containing_namespace.m_name); - } + auto parent_scope = scope_of_declaration(parent_decl); + String containing_scope; + if (parent_decl.is_namespace()) + containing_scope = static_cast<NamespaceDeclaration&>(parent_decl).m_name; + if (parent_decl.is_struct_or_class()) + containing_scope = static_cast<StructOrClassDeclaration&>(parent_decl).name(); - return {}; + if (parent_scope.is_null()) + return containing_scope; + + return String::formatted("{}::{}", parent_scope, containing_scope); } } diff --git a/Userland/Libraries/LibCpp/AST.cpp b/Userland/Libraries/LibCpp/AST.cpp index 0b77c21828..0764cfe5bf 100644 --- a/Userland/Libraries/LibCpp/AST.cpp +++ b/Userland/Libraries/LibCpp/AST.cpp @@ -309,6 +309,13 @@ void StructOrClassDeclaration::dump(size_t indent) const member.dump(indent + 1); } } +NonnullRefPtrVector<Declaration> StructOrClassDeclaration::declarations() const +{ + NonnullRefPtrVector<Declaration> declarations; + for (auto& member : m_members) + declarations.append(member); + return declarations; +} void MemberDeclaration::dump(size_t indent) const { diff --git a/Userland/Libraries/LibCpp/AST.h b/Userland/Libraries/LibCpp/AST.h index 5551751fd1..d2ada70b8a 100644 --- a/Userland/Libraries/LibCpp/AST.h +++ b/Userland/Libraries/LibCpp/AST.h @@ -521,7 +521,6 @@ public: { } - StringView m_name; Vector<StringView> m_entries; }; @@ -537,7 +536,6 @@ public: } RefPtr<Type> m_type; - StringView m_name; RefPtr<Expression> m_initial_value; }; @@ -549,6 +547,7 @@ public: virtual bool is_struct_or_class() const override { return true; } virtual bool is_struct() const override { return m_type == Type::Struct; } virtual bool is_class() const override { return m_type == Type::Class; } + virtual NonnullRefPtrVector<Declaration> declarations() const override; enum class Type { Struct, @@ -683,7 +682,6 @@ public: virtual NonnullRefPtrVector<Declaration> declarations() const override { return m_declarations; } - StringView m_name; NonnullRefPtrVector<Declaration> m_declarations; }; |