summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorItamar <itamar8910@gmail.com>2021-06-26 17:17:46 +0300
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-06-29 00:07:19 +0430
commitccb52b005e7d2deec5de235f51bdf0b5b4083523 (patch)
treecc609833b9afab41628153ffa1c152bdcee02758
parentd7aa831a430800ed5ce16b00a0cdcc72e434eeba (diff)
downloadserenity-ccb52b005e7d2deec5de235f51bdf0b5b4083523.zip
CppLanguageServer: Make properties_of_type return any property
Previously, CppComprehensionEngine::properties_of_type only returned variables.
-rw-r--r--Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp42
-rw-r--r--Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.h7
2 files changed, 33 insertions, 16 deletions
diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp b/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp
index 8f5628bb17..87c0eb96ce 100644
--- a/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp
+++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp
@@ -206,8 +206,8 @@ Vector<GUI::AutocompleteProvider::Entry> CppComprehensionEngine::autocomplete_pr
Vector<GUI::AutocompleteProvider::Entry> suggestions;
for (auto& prop : properties_of_type(document, type)) {
- if (prop.name.starts_with(partial_text)) {
- suggestions.append({ prop.name, partial_text.length(), GUI::AutocompleteProvider::CompletionKind::Identifier });
+ if (prop.name.name.starts_with(partial_text)) {
+ suggestions.append({ prop.name.name, partial_text.length(), GUI::AutocompleteProvider::CompletionKind::Identifier });
}
}
return suggestions;
@@ -227,8 +227,18 @@ String CppComprehensionEngine::type_of_property(const DocumentData& document, co
auto& parent = (const MemberExpression&)(*identifier.parent());
auto properties = properties_of_type(document, type_of(document, *parent.m_object));
for (auto& prop : properties) {
- if (prop.name == identifier.m_name && prop.type->is_named_type())
- return ((NamedType&)prop.type).m_name->full_name();
+ if (prop.name.name != identifier.m_name)
+ continue;
+ Type* type { nullptr };
+ if (prop.declaration->is_variable_declaration()) {
+ type = ((VariableDeclaration&)*prop.declaration).m_type.ptr();
+ }
+ if (!type)
+ continue;
+ if (!type->is_named_type())
+ continue;
+
+ return ((NamedType&)*type).m_name->full_name();
}
return {};
}
@@ -275,9 +285,10 @@ String CppComprehensionEngine::type_of(const DocumentData& document, const Expre
return type_of_variable(*identifier);
}
-Vector<CppComprehensionEngine::PropertyInfo> CppComprehensionEngine::properties_of_type(const DocumentData& document, const String& type) const
+Vector<CppComprehensionEngine::Symbol> CppComprehensionEngine::properties_of_type(const DocumentData& document, const String& type) const
{
- auto decl = find_declaration_of(document, SymbolName::create(type, {}));
+ auto type_symbol = SymbolName::create(type);
+ auto decl = find_declaration_of(document, type_symbol);
if (!decl) {
dbgln("Couldn't find declaration of type: {}", type);
return {};
@@ -289,13 +300,14 @@ Vector<CppComprehensionEngine::PropertyInfo> CppComprehensionEngine::properties_
}
auto& struct_or_class = (StructOrClassDeclaration&)*decl;
- VERIFY(struct_or_class.m_name == type); // FIXME: this won't work with scoped types
+ VERIFY(struct_or_class.name() == type_symbol.name);
- Vector<PropertyInfo> properties;
+ Vector<Symbol> properties;
for (auto& member : struct_or_class.m_members) {
- if (!member.is_variable_declaration())
- continue;
- properties.append({ member.m_name, ((VariableDeclaration&)member).m_type });
+ Vector<StringView> scope(type_symbol.scope);
+ scope.append(type_symbol.name);
+ // FIXME: We don't have to create the Symbol here, it should already exist in the 'm_symbol' table of some DocumentData we already parsed.
+ properties.append(Symbol::create(member.m_name, scope, member, Symbol::IsLocal::No));
}
return properties;
}
@@ -681,6 +693,14 @@ CppComprehensionEngine::SymbolName CppComprehensionEngine::SymbolName::create(St
return { name, move(scope) };
}
+CppComprehensionEngine::SymbolName CppComprehensionEngine::SymbolName::create(StringView qualified_name)
+{
+ auto parts = qualified_name.split_view("::");
+ VERIFY(!parts.is_empty());
+ auto name = parts.take_last();
+ return SymbolName::create(name, move(parts));
+}
+
String CppComprehensionEngine::SymbolName::to_string() const
{
if (scope.is_empty())
diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.h b/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.h
index f25b704d0c..e77e276f5d 100644
--- a/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.h
+++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.h
@@ -36,6 +36,7 @@ private:
Vector<StringView> scope;
static SymbolName create(StringView, Vector<StringView>&&);
+ static SymbolName create(StringView);
String scope_as_string() const;
String to_string() const;
@@ -106,11 +107,7 @@ private:
Yes
};
- struct PropertyInfo {
- StringView name;
- RefPtr<Type> type;
- };
- Vector<PropertyInfo> properties_of_type(const DocumentData& document, const String& type) const;
+ Vector<Symbol> properties_of_type(const DocumentData& document, const String& type) const;
Vector<Symbol> get_child_symbols(const ASTNode&) const;
Vector<Symbol> get_child_symbols(const ASTNode&, const Vector<StringView>& scope, Symbol::IsLocal) const;