Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion clang-tools-extra/clang-doc/JSONGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,12 +584,20 @@ static SmallString<16> determineFileName(Info *I, SmallString<128> &Path) {
FileName = RecordSymbolInfo->MangledName;
} else if (I->USR == GlobalNamespaceID)
FileName = "index";
else
else if (I->IT == InfoType::IT_namespace) {
for (const auto &NS : I->Namespace) {
FileName += NS.Name;
FileName += "_";
}
FileName += I->Name;
} else
Comment on lines +587 to +593
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking we'd be better off just moving away from the the flat dir structure. the number of files/items in a namespace can be quite large, and its probably a better choice to keep the number of files in a directory relatively small. Things like the global namespace may need more thought, since I think they may have lots of things in it. for example C projects will all just have everything in the global namespace, right? so we may also want to consider mirroring the source file directory structure. but moving away from the flat structure first and then using a different schema if we decide its worth the effort seems like a good path.

For now though, I'd like to get these bugs fixed, so lets just add a TODO about that, and go w/ what you have here. I think its more important to have a working thing, than stay in limbo while we figure out a path forward.

FileName = I->Name;
sys::path::append(Path, FileName + ".json");
return FileName;
}

// FIXME: Revert back to creating nested directories for namespaces instead of
// putting everything in a flat directory structure.
Error JSONGenerator::generateDocs(
StringRef RootDir, llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
const ClangDocContext &CDCtx) {
Expand Down
20 changes: 20 additions & 0 deletions clang-tools-extra/test/clang-doc/json/multiple-namespaces.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: clang-doc --output=%t --format=json --executor=standalone %s
// RUN: FileCheck %s < %t/json/foo_tools.json --check-prefix=CHECK-FOO
// RUN: FileCheck %s < %t/json/bar_tools.json --check-prefix=CHECK-BAR

namespace foo {
namespace tools {
class FooTools {};
} // namespace tools
} // namespace foo

namespace bar {
namespace tools {
class BarTools {};
} // namespace tools
} // namespace bar

// CHECK-FOO: "Name": "tools"

// CHECK-BAR: "Name": "tools"
2 changes: 1 addition & 1 deletion clang-tools-extra/test/clang-doc/json/nested-namespace.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: clang-doc --output=%t --format=json --executor=standalone %s
// RUN: FileCheck %s < %t/json/nested.json --check-prefix=NESTED
// RUN: FileCheck %s < %t/json/inner.json --check-prefix=INNER
// RUN: FileCheck %s < %t/json/nested_inner.json --check-prefix=INNER

namespace nested {
int Global;
Expand Down