From 67a96920674d628f615532a302504544a45e8187 Mon Sep 17 00:00:00 2001 From: aidanfnv Date: Thu, 7 Aug 2025 02:25:42 -0700 Subject: Add new _getName to get extension decl names for core module docs (#7985) Fixes #7479 This adds a new variant of `_getName(ExtensionDecl* decl)` to our markdown doc writer that takes an ExtensionDecl* and returns the name in the format `extension : `. This is required to display "extension T : ITexelElement" properly in the core module docs, as the existing `_getName(Decl* decl)` returns an empty string because the name does not come from the `decl` itself, but rather its `targetType`. The target type alone is not enough, as that would return `T`, which will be erroneously interpreted as the name for the generic parameter, and the doc system will link every mention of `T` to the extension's page. ReadTheDocs already displays the name correctly in the TOC of the docs there, but that is because it falls back to the page title when the name in the TOC is empty. --------- Co-authored-by: slangbot Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- source/slang/slang-doc-markdown-writer.cpp | 37 ++++++++++++++++++++++++++++++ source/slang/slang-doc-markdown-writer.h | 1 + 2 files changed, 38 insertions(+) (limited to 'source') diff --git a/source/slang/slang-doc-markdown-writer.cpp b/source/slang/slang-doc-markdown-writer.cpp index 2a9a83361..2a215d6bd 100644 --- a/source/slang/slang-doc-markdown-writer.cpp +++ b/source/slang/slang-doc-markdown-writer.cpp @@ -356,6 +356,35 @@ String DocMarkdownWriter::_getName(InheritanceDecl* decl) return buf.produceString(); } +String DocMarkdownWriter::_getName(ExtensionDecl* extDecl) +{ + StringBuilder buf; + buf.clear(); + + if (auto declRef = isDeclRefTypeOf(extDecl->targetType)) + { + buf << "extension " << _getName(declRef.getDecl()).getUnownedSlice(); + + List inheritanceDecls; + _getDecls(extDecl, inheritanceDecls); + + const Index count = inheritanceDecls.getCount(); + if (count) + { + buf << " : "; + + List baseNames; + for (Index i = 0; i < count; ++i) + { + baseNames.add(_getName(inheritanceDecls[i])); + } + StringUtil::join(baseNames, UnownedStringSlice(", "), buf); + } + } + + return buf.produceString(); +} + DocMarkdownWriter::NameAndText DocMarkdownWriter::_getNameAndText( ASTMarkup::Entry* entry, Decl* decl) @@ -2973,6 +3002,14 @@ DocumentPage* DocMarkdownWriter::getPage(Decl* decl) page->path = path; page->shortName = _getName(decl); page->decl = decl; + if (auto extDecl = as(decl)) + { + page->shortName = _getName(extDecl); + if (auto declRef = isDeclRefTypeOf(extDecl->targetType)) + { + page->decl = declRef.getDecl(); + } + } m_output[path] = page; // If parent page exists, add this page to it's children diff --git a/source/slang/slang-doc-markdown-writer.h b/source/slang/slang-doc-markdown-writer.h index 36d851e61..f4ca4de7f 100644 --- a/source/slang/slang-doc-markdown-writer.h +++ b/source/slang/slang-doc-markdown-writer.h @@ -214,6 +214,7 @@ struct DocMarkdownWriter String _getFullName(Decl* decl); String _getDocFilePath(Decl* decl); String _getName(InheritanceDecl* decl); + String _getName(ExtensionDecl* extDecl); NameAndText _getNameAndText(ASTMarkup::Entry* entry, Decl* decl); NameAndText _getNameAndText(Decl* decl); -- cgit v1.2.3