summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authoraidanfnv <aidanf@nvidia.com>2025-08-07 02:25:42 -0700
committerGitHub <noreply@github.com>2025-08-07 09:25:42 +0000
commit67a96920674d628f615532a302504544a45e8187 (patch)
tree71f62db43dc3ea86b5547490440577dd59f1982b /source
parent9ed7b5264676547855e1378d2b9c9d51c8ba7162 (diff)
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 <name> : <interface>`. 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 <ellieh+slangbot@nvidia.com> Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-doc-markdown-writer.cpp37
-rw-r--r--source/slang/slang-doc-markdown-writer.h1
2 files changed, 38 insertions, 0 deletions
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<Decl>(extDecl->targetType))
+ {
+ buf << "extension " << _getName(declRef.getDecl()).getUnownedSlice();
+
+ List<InheritanceDecl*> inheritanceDecls;
+ _getDecls(extDecl, inheritanceDecls);
+
+ const Index count = inheritanceDecls.getCount();
+ if (count)
+ {
+ buf << " : ";
+
+ List<String> 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<ExtensionDecl>(decl))
+ {
+ page->shortName = _getName(extDecl);
+ if (auto declRef = isDeclRefTypeOf<Decl>(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);