From 726d4c6d5a0256f03e410ab20693e7965d200880 Mon Sep 17 00:00:00 2001 From: Eduardo Speroni Date: Wed, 10 Apr 2024 14:42:36 -0300 Subject: [PATCH 01/10] feat: add `@deprecation` and `@since` docs --- metadata-generator/src/Meta/MetaEntities.h | 13 +++++++++++++ .../src/TypeScript/DocSetManager.cpp | 18 +++++++++++++++--- .../src/TypeScript/DocSetManager.h | 6 +++++- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/metadata-generator/src/Meta/MetaEntities.h b/metadata-generator/src/Meta/MetaEntities.h index 18709ead..1bacf55b 100644 --- a/metadata-generator/src/Meta/MetaEntities.h +++ b/metadata-generator/src/Meta/MetaEntities.h @@ -62,6 +62,19 @@ struct Version { bool operator >=(const Version& other) const { return !(*this < other); } + std::string toString() const { + std::string result; + if (Major >= 0) { + result.append(std::to_string(Major)); + if (Minor >= 0) { + result.append("." + std::to_string(Minor)); + if (SubMinor >= 0) { + result.append("." + std::to_string(SubMinor)); + } + } + } + return result; + } }; enum MetaFlags : uint16_t { diff --git a/metadata-generator/src/TypeScript/DocSetManager.cpp b/metadata-generator/src/TypeScript/DocSetManager.cpp index 13de5a52..bf28bdc8 100644 --- a/metadata-generator/src/TypeScript/DocSetManager.cpp +++ b/metadata-generator/src/TypeScript/DocSetManager.cpp @@ -90,7 +90,7 @@ using namespace std; std::string TSComment::toString(std::string linePrefix) { - if (description.length() == 0 && params.size() == 0) { + if (description.length() == 0 && params.size() == 0 && deprecatedIn.isUnknown() && introducedIn.isUnknown()) { return std::string(); } @@ -98,19 +98,31 @@ std::string TSComment::toString(std::string linePrefix) result << linePrefix << "/**" << std::endl; std::string processedDesc = description; findAndReplaceIn(processedDesc, "\n", ""); - result << linePrefix << " * " << processedDesc << std::endl; + if (processedDesc.length() > 0) { + result << linePrefix << " * " << processedDesc << std::endl; + } for (std::pair& param : params) { // @param paramName - paramDesc result << linePrefix << " * " << "@param " + param.first + " - " + param.second << std::endl; } + if (!introducedIn.isUnknown()) { + result << linePrefix << " * " << "@since " << introducedIn.toString() << std::endl; + } + if (!deprecatedIn.isUnknown()) { + result << linePrefix << " * " << "@deprecated " << deprecatedIn.toString() << std::endl; + } result << linePrefix << " */" << std::endl; return result.str(); } TSComment DocSetManager::getCommentFor(Meta::Meta* meta, Meta::Meta* parent) { - return (parent == nullptr) ? getCommentFor(meta->name, meta->type) : getCommentFor(meta->name, meta->type, parent->name, parent->type); + auto comment = (parent == nullptr) ? getCommentFor(meta->name, meta->type) : getCommentFor(meta->name, meta->type, parent->name, parent->type); + comment.deprecatedIn = meta->deprecatedIn; + comment.introducedIn = meta->introducedIn; + comment.obsoletedIn = meta->obsoletedIn; + return comment; } TSComment DocSetManager::getCommentFor(std::string name, Meta::MetaType type, std::string parentName, Meta::MetaType parentType) diff --git a/metadata-generator/src/TypeScript/DocSetManager.h b/metadata-generator/src/TypeScript/DocSetManager.h index 06cc2d41..2c146e02 100644 --- a/metadata-generator/src/TypeScript/DocSetManager.h +++ b/metadata-generator/src/TypeScript/DocSetManager.h @@ -21,6 +21,10 @@ struct TSComment { * \brief A brief description of the symbol. */ std::string description; + + Meta::Version introducedIn = UNKNOWN_VERSION; + Meta::Version obsoletedIn = UNKNOWN_VERSION; + Meta::Version deprecatedIn = UNKNOWN_VERSION; /* * \brief An optional list of parameters. Useful in method and function comments. @@ -74,4 +78,4 @@ class DocSetManager { }; } -#endif //METADATAGENERATOR_DOCSETPARSER_H \ No newline at end of file +#endif //METADATAGENERATOR_DOCSETPARSER_H From 64276b43b59b8992b625c86c7889f80501dc7afe Mon Sep 17 00:00:00 2001 From: Eduardo Speroni Date: Wed, 10 Apr 2024 14:45:20 -0300 Subject: [PATCH 02/10] feat: add protocol information to native types --- .../src/TypeScript/DefinitionWriter.cpp | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/metadata-generator/src/TypeScript/DefinitionWriter.cpp b/metadata-generator/src/TypeScript/DefinitionWriter.cpp index 6d20d891..2fe08a1e 100644 --- a/metadata-generator/src/TypeScript/DefinitionWriter.cpp +++ b/metadata-generator/src/TypeScript/DefinitionWriter.cpp @@ -976,7 +976,26 @@ std::string DefinitionWriter::tsifyType(const Type& type, const bool isFuncParam } } - if (interface.name == "NSArray" && isFuncParam) { + std::vector protocols; + if (type.is(TypeType::TypeInterface) && type.as().protocols.size() > 0) { + for (auto & protocol : type.as().protocols) { + if (protocol->jsName != "NSCopying") { + protocols.push_back(protocol->jsName); + } + } + } + + if (protocols.size() > 0) { + // Example: -(NSObject