mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
SourceKit/DocSupport: Report sub-module information, if any, for top-level decls imported from clang. rdar://31415030
This commit is contained in:
@@ -7550,7 +7550,8 @@ var FooSubUnnamedEnumeratorA1: Int { get }
|
||||
key.offset: 7514,
|
||||
key.length: 5
|
||||
}
|
||||
]
|
||||
],
|
||||
key.modulename: "Foo.FooSub"
|
||||
},
|
||||
{
|
||||
key.kind: source.lang.swift.decl.struct,
|
||||
@@ -7628,7 +7629,8 @@ var FooSubUnnamedEnumeratorA1: Int { get }
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
key.modulename: "Foo.FooSub"
|
||||
},
|
||||
{
|
||||
key.kind: source.lang.swift.decl.var.global,
|
||||
@@ -7636,7 +7638,8 @@ var FooSubUnnamedEnumeratorA1: Int { get }
|
||||
key.usr: "c:@E@FooSubEnum1@FooSubEnum1X",
|
||||
key.offset: 7676,
|
||||
key.length: 37,
|
||||
key.fully_annotated_decl: "<decl.var.global><syntaxtype.keyword>var</syntaxtype.keyword> <decl.name>FooSubEnum1X</decl.name>: <decl.var.type><ref.struct usr=\"c:@E@FooSubEnum1\">FooSubEnum1</ref.struct></decl.var.type> { <syntaxtype.keyword>get</syntaxtype.keyword> }</decl.var.global>"
|
||||
key.fully_annotated_decl: "<decl.var.global><syntaxtype.keyword>var</syntaxtype.keyword> <decl.name>FooSubEnum1X</decl.name>: <decl.var.type><ref.struct usr=\"c:@E@FooSubEnum1\">FooSubEnum1</ref.struct></decl.var.type> { <syntaxtype.keyword>get</syntaxtype.keyword> }</decl.var.global>",
|
||||
key.modulename: "Foo.FooSub"
|
||||
},
|
||||
{
|
||||
key.kind: source.lang.swift.decl.var.global,
|
||||
@@ -7644,7 +7647,8 @@ var FooSubUnnamedEnumeratorA1: Int { get }
|
||||
key.usr: "c:@E@FooSubEnum1@FooSubEnum1Y",
|
||||
key.offset: 7714,
|
||||
key.length: 37,
|
||||
key.fully_annotated_decl: "<decl.var.global><syntaxtype.keyword>var</syntaxtype.keyword> <decl.name>FooSubEnum1Y</decl.name>: <decl.var.type><ref.struct usr=\"c:@E@FooSubEnum1\">FooSubEnum1</ref.struct></decl.var.type> { <syntaxtype.keyword>get</syntaxtype.keyword> }</decl.var.global>"
|
||||
key.fully_annotated_decl: "<decl.var.global><syntaxtype.keyword>var</syntaxtype.keyword> <decl.name>FooSubEnum1Y</decl.name>: <decl.var.type><ref.struct usr=\"c:@E@FooSubEnum1\">FooSubEnum1</ref.struct></decl.var.type> { <syntaxtype.keyword>get</syntaxtype.keyword> }</decl.var.global>",
|
||||
key.modulename: "Foo.FooSub"
|
||||
},
|
||||
{
|
||||
key.kind: source.lang.swift.decl.var.global,
|
||||
@@ -7652,6 +7656,7 @@ var FooSubUnnamedEnumeratorA1: Int { get }
|
||||
key.usr: "c:@Ea@FooSubUnnamedEnumeratorA1@FooSubUnnamedEnumeratorA1",
|
||||
key.offset: 7752,
|
||||
key.length: 42,
|
||||
key.fully_annotated_decl: "<decl.var.global><syntaxtype.keyword>var</syntaxtype.keyword> <decl.name>FooSubUnnamedEnumeratorA1</decl.name>: <decl.var.type><ref.struct usr=\"s:Si\">Int</ref.struct></decl.var.type> { <syntaxtype.keyword>get</syntaxtype.keyword> }</decl.var.global>"
|
||||
key.fully_annotated_decl: "<decl.var.global><syntaxtype.keyword>var</syntaxtype.keyword> <decl.name>FooSubUnnamedEnumeratorA1</decl.name>: <decl.var.type><ref.struct usr=\"s:Si\">Int</ref.struct></decl.var.type> { <syntaxtype.keyword>get</syntaxtype.keyword> }</decl.var.global>",
|
||||
key.modulename: "Foo.FooSub"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -328,6 +328,7 @@ struct DocGenericParam {
|
||||
struct DocEntityInfo {
|
||||
UIdent Kind;
|
||||
llvm::SmallString<32> Name;
|
||||
llvm::SmallString<32> SubModuleName;
|
||||
llvm::SmallString<32> Argument;
|
||||
llvm::SmallString<64> USR;
|
||||
llvm::SmallString<64> OriginalUSR;
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "clang/AST/Decl.h"
|
||||
#include "clang/Basic/Module.h"
|
||||
#include "SwiftASTManager.h"
|
||||
#include "SwiftEditorDiagConsumer.h"
|
||||
#include "SwiftLangSupport.h"
|
||||
@@ -391,6 +393,44 @@ static bool initDocEntityInfo(const Decl *D, const Decl *SynthesizedTarget,
|
||||
}
|
||||
}
|
||||
|
||||
switch(D->getDeclContext()->getContextKind()) {
|
||||
case DeclContextKind::AbstractClosureExpr:
|
||||
case DeclContextKind::TopLevelCodeDecl:
|
||||
case DeclContextKind::AbstractFunctionDecl:
|
||||
case DeclContextKind::SubscriptDecl:
|
||||
case DeclContextKind::Initializer:
|
||||
case DeclContextKind::SerializedLocal:
|
||||
case DeclContextKind::ExtensionDecl:
|
||||
case DeclContextKind::GenericTypeDecl:
|
||||
break;
|
||||
|
||||
// We report sub-module information only for top-level decls.
|
||||
case DeclContextKind::Module:
|
||||
case DeclContextKind::FileUnit: {
|
||||
if (auto* CD = D->getClangDecl()) {
|
||||
if (auto *M = CD->getImportedOwningModule()) {
|
||||
const clang::Module *Root = M->getTopLevelModule();
|
||||
|
||||
// If Root differs from the owning module, then the owning module is
|
||||
// a sub-module.
|
||||
if (M != Root) {
|
||||
llvm::raw_svector_ostream OS(Info.SubModuleName);
|
||||
llvm::SmallVector<StringRef, 4> Names;
|
||||
|
||||
// Climb up and collect sub-module names.
|
||||
for (auto Current = M; Current != Root; Current = Current->Parent) {
|
||||
Names.insert(Names.begin(), Current->Name);
|
||||
}
|
||||
OS << Root->Name;
|
||||
std::for_each(Names.begin(), Names.end(),
|
||||
[&](StringRef N) { OS << "." << N; });
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1208,6 +1208,8 @@ void SKDocConsumer::addDocEntityInfoToDict(const DocEntityInfo &Info,
|
||||
Elem.set(KeyName, Info.Name);
|
||||
if (!Info.Argument.empty())
|
||||
Elem.set(KeyKeyword, Info.Argument);
|
||||
if (!Info.SubModuleName.empty())
|
||||
Elem.set(KeyModuleName, Info.SubModuleName);
|
||||
if (!Info.USR.empty())
|
||||
Elem.set(KeyUSR, Info.USR);
|
||||
if (!Info.OriginalUSR.empty())
|
||||
|
||||
Reference in New Issue
Block a user