Skip to content

Commit e17df96

Browse files
committed
[SourceKit] Factor out wrapper code from reportCursorInfo
The guts of the callback are the interesting part that we want to share between offset-based and usr-based cursor info. Pull the code that actually finds the cursor info up into the caller.
1 parent ea531f2 commit e17df96

File tree

1 file changed

+54
-59
lines changed

1 file changed

+54
-59
lines changed

tools/SourceKit/tools/sourcekitd/lib/API/Requests.cpp

Lines changed: 54 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,7 @@ static sourcekitd_response_t reportDocInfo(llvm::MemoryBuffer *InputBuf,
160160
StringRef ModuleName,
161161
ArrayRef<const char *> Args);
162162

163-
static void reportCursorInfo(StringRef Filename,
164-
int64_t Offset,
165-
ArrayRef<const char *> Args,
166-
ResponseReceiver Rec);
163+
static void reportCursorInfo(const CursorInfo &Info, ResponseReceiver Rec);
167164

168165
static void findRelatedIdents(StringRef Filename,
169166
int64_t Offset,
@@ -707,7 +704,10 @@ handleSemanticRequest(RequestDict Req,
707704
int64_t Offset;
708705
if (Req.getInt64(KeyOffset, Offset, /*isOptional=*/false))
709706
return Rec(createErrorRequestInvalid("missing 'key.offset'"));
710-
return reportCursorInfo(*SourceFile, Offset, Args, Rec);
707+
LangSupport &Lang = getGlobalContext().getSwiftLangSupport();
708+
return Lang.getCursorInfo(
709+
*SourceFile, Offset, Args,
710+
[Rec](const CursorInfo &Info) { reportCursorInfo(Info, Rec); });
711711
}
712712

713713
if (ReqUID == RequestRelatedIdents) {
@@ -1249,65 +1249,60 @@ bool SKDocConsumer::handleDiagnostic(const DiagnosticEntryInfo &Info) {
12491249
// ReportCursorInfo
12501250
//===----------------------------------------------------------------------===//
12511251

1252-
static void reportCursorInfo(StringRef Filename,
1253-
int64_t Offset,
1254-
ArrayRef<const char *> Args,
1255-
ResponseReceiver Rec) {
1256-
LangSupport &Lang = getGlobalContext().getSwiftLangSupport();
1257-
Lang.getCursorInfo(Filename, Offset, Args, [Rec](const CursorInfo &Info) {
1258-
if (Info.IsCancelled)
1259-
return Rec(createErrorRequestCancelled());
1252+
static void reportCursorInfo(const CursorInfo &Info, ResponseReceiver Rec) {
12601253

1261-
ResponseBuilder RespBuilder;
1262-
if (Info.Kind.isInvalid())
1263-
return Rec(RespBuilder.createResponse());
1254+
if (Info.IsCancelled)
1255+
return Rec(createErrorRequestCancelled());
12641256

1265-
auto Elem = RespBuilder.getDictionary();
1266-
Elem.set(KeyKind, Info.Kind);
1267-
Elem.set(KeyName, Info.Name);
1268-
if (!Info.USR.empty())
1269-
Elem.set(KeyUSR, Info.USR);
1270-
if (!Info.TypeName.empty())
1271-
Elem.set(KeyTypeName, Info.TypeName);
1272-
if (!Info.DocComment.empty())
1273-
Elem.set(KeyDocFullAsXML, Info.DocComment);
1274-
if (!Info.AnnotatedDeclaration.empty())
1275-
Elem.set(KeyAnnotatedDecl, Info.AnnotatedDeclaration);
1276-
if (!Info.FullyAnnotatedDeclaration.empty())
1277-
Elem.set(KeyFullyAnnotatedDecl, Info.FullyAnnotatedDeclaration);
1278-
if (!Info.ModuleName.empty())
1279-
Elem.set(KeyModuleName, Info.ModuleName);
1280-
if (!Info.GroupName.empty())
1281-
Elem.set(KeyGroupName, Info.GroupName);
1282-
if (!Info.ModuleInterfaceName.empty())
1283-
Elem.set(KeyModuleInterfaceName, Info.ModuleInterfaceName);
1284-
if (Info.DeclarationLoc.hasValue()) {
1285-
Elem.set(KeyOffset, Info.DeclarationLoc.getValue().first);
1286-
Elem.set(KeyLength, Info.DeclarationLoc.getValue().second);
1287-
if (!Info.Filename.empty())
1288-
Elem.set(KeyFilePath, Info.Filename);
1289-
}
1290-
if (!Info.OverrideUSRs.empty()) {
1291-
auto Overrides = Elem.setArray(KeyOverrides);
1292-
for (auto USR : Info.OverrideUSRs) {
1293-
auto Override = Overrides.appendDictionary();
1294-
Override.set(KeyUSR, USR);
1295-
}
1257+
ResponseBuilder RespBuilder;
1258+
if (Info.Kind.isInvalid())
1259+
return Rec(RespBuilder.createResponse());
1260+
1261+
auto Elem = RespBuilder.getDictionary();
1262+
Elem.set(KeyKind, Info.Kind);
1263+
Elem.set(KeyName, Info.Name);
1264+
if (!Info.USR.empty())
1265+
Elem.set(KeyUSR, Info.USR);
1266+
if (!Info.TypeName.empty())
1267+
Elem.set(KeyTypeName, Info.TypeName);
1268+
if (!Info.DocComment.empty())
1269+
Elem.set(KeyDocFullAsXML, Info.DocComment);
1270+
if (!Info.AnnotatedDeclaration.empty())
1271+
Elem.set(KeyAnnotatedDecl, Info.AnnotatedDeclaration);
1272+
if (!Info.FullyAnnotatedDeclaration.empty())
1273+
Elem.set(KeyFullyAnnotatedDecl, Info.FullyAnnotatedDeclaration);
1274+
if (!Info.ModuleName.empty())
1275+
Elem.set(KeyModuleName, Info.ModuleName);
1276+
if (!Info.GroupName.empty())
1277+
Elem.set(KeyGroupName, Info.GroupName);
1278+
if (!Info.ModuleInterfaceName.empty())
1279+
Elem.set(KeyModuleInterfaceName, Info.ModuleInterfaceName);
1280+
if (Info.DeclarationLoc.hasValue()) {
1281+
Elem.set(KeyOffset, Info.DeclarationLoc.getValue().first);
1282+
Elem.set(KeyLength, Info.DeclarationLoc.getValue().second);
1283+
if (!Info.Filename.empty())
1284+
Elem.set(KeyFilePath, Info.Filename);
1285+
}
1286+
if (!Info.OverrideUSRs.empty()) {
1287+
auto Overrides = Elem.setArray(KeyOverrides);
1288+
for (auto USR : Info.OverrideUSRs) {
1289+
auto Override = Overrides.appendDictionary();
1290+
Override.set(KeyUSR, USR);
12961291
}
1297-
if (!Info.AnnotatedRelatedDeclarations.empty()) {
1298-
auto RelDecls = Elem.setArray(KeyRelatedDecls);
1299-
for (auto AnnotDecl : Info.AnnotatedRelatedDeclarations) {
1300-
auto RelDecl = RelDecls.appendDictionary();
1301-
RelDecl.set(KeyAnnotatedDecl, AnnotDecl);
1302-
}
1292+
}
1293+
if (!Info.AnnotatedRelatedDeclarations.empty()) {
1294+
auto RelDecls = Elem.setArray(KeyRelatedDecls);
1295+
for (auto AnnotDecl : Info.AnnotatedRelatedDeclarations) {
1296+
auto RelDecl = RelDecls.appendDictionary();
1297+
RelDecl.set(KeyAnnotatedDecl, AnnotDecl);
13031298
}
1304-
if (Info.IsSystem)
1305-
Elem.setBool(KeyIsSystem, true);
1306-
if (!Info.TypeInterface.empty())
1307-
Elem.set(KeyTypeInterface, Info.TypeInterface);
1299+
}
1300+
if (Info.IsSystem)
1301+
Elem.setBool(KeyIsSystem, true);
1302+
if (!Info.TypeInterface.empty())
1303+
Elem.set(KeyTypeInterface, Info.TypeInterface);
13081304

1309-
return Rec(RespBuilder.createResponse());
1310-
});
1305+
return Rec(RespBuilder.createResponse());
13111306
}
13121307

13131308
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)