mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[SourceKit] CursorInfo: The result of cursor info for a module name starts to include group names in that module.
This commit is contained in:
@@ -1234,6 +1234,7 @@ public:
|
|||||||
|
|
||||||
bool isSystemModule() const;
|
bool isSystemModule() const;
|
||||||
bool isBuiltinModule() const;
|
bool isBuiltinModule() const;
|
||||||
|
const ModuleDecl *getAsSwiftModule() const;
|
||||||
|
|
||||||
explicit operator bool() const { return !Mod.isNull(); }
|
explicit operator bool() const { return !Mod.isNull(); }
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1649,3 +1649,10 @@ bool ModuleEntity::isBuiltinModule() const {
|
|||||||
return SwiftMod->isBuiltinModule();
|
return SwiftMod->isBuiltinModule();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ModuleDecl* ModuleEntity::getAsSwiftModule() const {
|
||||||
|
assert(!Mod.isNull());
|
||||||
|
if (auto SwiftMod = Mod.dyn_cast<const Module*>())
|
||||||
|
return SwiftMod;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1621,7 +1621,16 @@ void ModuleFile::collectAllGroups(std::vector<StringRef> &Names) const {
|
|||||||
if (!GroupNamesMap)
|
if (!GroupNamesMap)
|
||||||
return;
|
return;
|
||||||
for (auto It = GroupNamesMap->begin(); It != GroupNamesMap->end(); ++ It) {
|
for (auto It = GroupNamesMap->begin(); It != GroupNamesMap->end(); ++ It) {
|
||||||
Names.push_back(It->getSecond());
|
StringRef FullGroupName = It->getSecond();
|
||||||
|
if (FullGroupName.empty())
|
||||||
|
continue;
|
||||||
|
auto Sep = FullGroupName.find_last_of(Separator);
|
||||||
|
assert(Sep != StringRef::npos);
|
||||||
|
auto Group = FullGroupName.substr(0, Sep);
|
||||||
|
auto Found = std::find(Names.begin(), Names.end(), Group);
|
||||||
|
if (Found != Names.end())
|
||||||
|
continue;
|
||||||
|
Names.push_back(Group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ func foo2(var a : [S1]) {
|
|||||||
a.append(S1())
|
a.append(S1())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
import Swift
|
||||||
|
|
||||||
// RUN: %sourcekitd-test -req=cursor -pos=3:18 %s -- %s %mcp_opt %clang-importer-sdk | FileCheck -check-prefix=CHECK-OVERLAY %s
|
// RUN: %sourcekitd-test -req=cursor -pos=3:18 %s -- %s %mcp_opt %clang-importer-sdk | FileCheck -check-prefix=CHECK-OVERLAY %s
|
||||||
// CHECK-OVERLAY: source.lang.swift.ref.var.global
|
// CHECK-OVERLAY: source.lang.swift.ref.var.global
|
||||||
// CHECK-OVERLAY-NEXT: NSUTF8StringEncoding
|
// CHECK-OVERLAY-NEXT: NSUTF8StringEncoding
|
||||||
@@ -52,3 +54,10 @@ func foo2(var a : [S1]) {
|
|||||||
// RUN: %sourcekitd-test -req=cursor -pos=18:8 %s -- %s %mcp_opt %clang-importer-sdk | FileCheck -check-prefix=CHECK-REPLACEMENT4 %s
|
// RUN: %sourcekitd-test -req=cursor -pos=18:8 %s -- %s %mcp_opt %clang-importer-sdk | FileCheck -check-prefix=CHECK-REPLACEMENT4 %s
|
||||||
// CHECK-REPLACEMENT4: <Group>Collection/Array</Group>
|
// CHECK-REPLACEMENT4: <Group>Collection/Array</Group>
|
||||||
// CHECK-REPLACEMENT4: <Declaration>mutating func append(newElement: <Type usr="s:V13cursor_stdlib2S1">S1</Type>)</Declaration>
|
// CHECK-REPLACEMENT4: <Declaration>mutating func append(newElement: <Type usr="s:V13cursor_stdlib2S1">S1</Type>)</Declaration>
|
||||||
|
|
||||||
|
// RUN: %sourcekitd-test -req=cursor -pos=21:10 %s -- %s %mcp_opt %clang-importer-sdk | FileCheck -check-prefix=CHECK-MODULE-GROUP1 %s
|
||||||
|
// CHECK-MODULE-GROUP1: MODULE GROUPS BEGIN
|
||||||
|
// CHECK-MODULE-GROUP1-DAG: Math
|
||||||
|
// CHECK-MODULE-GROUP1-DAG: Collection
|
||||||
|
// CHECK-MODULE-GROUP1-DAG: Collection/Array
|
||||||
|
// CHECK-MODULE-GROUP1: MODULE GROUPS END
|
||||||
|
|||||||
@@ -294,6 +294,8 @@ struct CursorInfo {
|
|||||||
ArrayRef<StringRef> OverrideUSRs;
|
ArrayRef<StringRef> OverrideUSRs;
|
||||||
/// Related declarations, overloaded functions etc., in annotated XML form.
|
/// Related declarations, overloaded functions etc., in annotated XML form.
|
||||||
ArrayRef<StringRef> AnnotatedRelatedDeclarations;
|
ArrayRef<StringRef> AnnotatedRelatedDeclarations;
|
||||||
|
/// All groups of the module name under cursor.
|
||||||
|
ArrayRef<StringRef> ModuleGroupArray;
|
||||||
bool IsSystem = false;
|
bool IsSystem = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -581,6 +581,11 @@ static bool passCursorInfoForModule(ModuleEntity Mod,
|
|||||||
if (auto IFaceGenRef = IFaceGenContexts.find(Info.ModuleName, Invok))
|
if (auto IFaceGenRef = IFaceGenContexts.find(Info.ModuleName, Invok))
|
||||||
Info.ModuleInterfaceName = IFaceGenRef->getDocumentName();
|
Info.ModuleInterfaceName = IFaceGenRef->getDocumentName();
|
||||||
Info.IsSystem = Mod.isSystemModule();
|
Info.IsSystem = Mod.isSystemModule();
|
||||||
|
std::vector<StringRef> Groups;
|
||||||
|
if (auto MD = Mod.getAsSwiftModule()) {
|
||||||
|
Info.ModuleGroupArray = ide::collectModuleGroups(const_cast<ModuleDecl*>(MD),
|
||||||
|
Groups);
|
||||||
|
}
|
||||||
Receiver(Info);
|
Receiver(Info);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -961,6 +961,16 @@ static void printCursorInfo(sourcekitd_variant_t Info, StringRef FilenameIn,
|
|||||||
OverrideUSRs.push_back(sourcekitd_variant_dictionary_get_string(Entry, KeyUSR));
|
OverrideUSRs.push_back(sourcekitd_variant_dictionary_get_string(Entry, KeyUSR));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<const char *> GroupNames;
|
||||||
|
sourcekitd_variant_t GroupObj =
|
||||||
|
sourcekitd_variant_dictionary_get_value(Info, KeyModuleGroups);
|
||||||
|
for (unsigned i = 0, e = sourcekitd_variant_array_get_count(GroupObj);
|
||||||
|
i != e; ++i) {
|
||||||
|
sourcekitd_variant_t Entry =
|
||||||
|
sourcekitd_variant_array_get_value(GroupObj, i);
|
||||||
|
GroupNames.push_back(sourcekitd_variant_dictionary_get_string(Entry, KeyGroupName));
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<const char *> RelatedDecls;
|
std::vector<const char *> RelatedDecls;
|
||||||
sourcekitd_variant_t RelatedDeclsObj =
|
sourcekitd_variant_t RelatedDeclsObj =
|
||||||
sourcekitd_variant_dictionary_get_value(Info, KeyRelatedDecls);
|
sourcekitd_variant_dictionary_get_value(Info, KeyRelatedDecls);
|
||||||
@@ -1013,6 +1023,10 @@ static void printCursorInfo(sourcekitd_variant_t Info, StringRef FilenameIn,
|
|||||||
if (TypeInterface)
|
if (TypeInterface)
|
||||||
OS << TypeInterface << '\n';
|
OS << TypeInterface << '\n';
|
||||||
OS << "TYPE INTERFACE END\n";
|
OS << "TYPE INTERFACE END\n";
|
||||||
|
OS << "MODULE GROUPS BEGIN\n";
|
||||||
|
for (auto Group : GroupNames)
|
||||||
|
OS << Group << '\n';
|
||||||
|
OS << "MODULE GROUPS END\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
static void printFoundInterface(sourcekitd_variant_t Info,
|
static void printFoundInterface(sourcekitd_variant_t Info,
|
||||||
|
|||||||
@@ -1299,6 +1299,13 @@ static void reportCursorInfo(const CursorInfo &Info, ResponseReceiver Rec) {
|
|||||||
Override.set(KeyUSR, USR);
|
Override.set(KeyUSR, USR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!Info.ModuleGroupArray.empty()) {
|
||||||
|
auto Groups = Elem.setArray(KeyModuleGroups);
|
||||||
|
for (auto Name : Info.ModuleGroupArray) {
|
||||||
|
auto Entry = Groups.appendDictionary();
|
||||||
|
Entry.set(KeyGroupName, Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!Info.AnnotatedRelatedDeclarations.empty()) {
|
if (!Info.AnnotatedRelatedDeclarations.empty()) {
|
||||||
auto RelDecls = Elem.setArray(KeyRelatedDecls);
|
auto RelDecls = Elem.setArray(KeyRelatedDecls);
|
||||||
for (auto AnnotDecl : Info.AnnotatedRelatedDeclarations) {
|
for (auto AnnotDecl : Info.AnnotatedRelatedDeclarations) {
|
||||||
|
|||||||
Reference in New Issue
Block a user