[SourceKit] Allow cursorinfo to take a USR instead of an offset

This eventually calls the code from ReconstructType to try to find the
Decl for a USR. For now, only works in a file, not a generated
interface.

rdar://problem/25017817
This commit is contained in:
Ben Langmuir
2016-03-16 09:00:38 -07:00
parent 0acc0a8464
commit d36708838b
6 changed files with 232 additions and 7 deletions

View File

@@ -384,6 +384,7 @@ static int handleTestInvocation(ArrayRef<const char *> Args,
getBufferForFilename(SourceFile)->getBuffer(), SourceFile);
}
// FIXME: we should detect if offset is required but not set.
unsigned ByteOffset = Opts.Offset;
if (Opts.Line != 0) {
ByteOffset = resolveFromLineCol(Opts.Line, Opts.Col, SourceBuf.get());
@@ -486,7 +487,11 @@ static int handleTestInvocation(ArrayRef<const char *> Args,
case SourceKitRequest::CursorInfo:
sourcekitd_request_dictionary_set_uid(Req, KeyRequest, RequestCursorInfo);
sourcekitd_request_dictionary_set_int64(Req, KeyOffset, ByteOffset);
if (!Opts.USR.empty()) {
sourcekitd_request_dictionary_set_string(Req, KeyUSR, Opts.USR.c_str());
} else {
sourcekitd_request_dictionary_set_int64(Req, KeyOffset, ByteOffset);
}
break;
case SourceKitRequest::RelatedIdents:

View File

@@ -701,13 +701,22 @@ handleSemanticRequest(RequestDict Req,
return Rec(createErrorRequestFailed("semantic editor is disabled"));
if (ReqUID == RequestCursorInfo) {
int64_t Offset;
if (Req.getInt64(KeyOffset, Offset, /*isOptional=*/false))
return Rec(createErrorRequestInvalid("missing 'key.offset'"));
LangSupport &Lang = getGlobalContext().getSwiftLangSupport();
return Lang.getCursorInfo(
*SourceFile, Offset, Args,
[Rec](const CursorInfo &Info) { reportCursorInfo(Info, Rec); });
int64_t Offset;
if (!Req.getInt64(KeyOffset, Offset, /*isOptional=*/false)) {
return Lang.getCursorInfo(
*SourceFile, Offset, Args,
[Rec](const CursorInfo &Info) { reportCursorInfo(Info, Rec); });
}
if (auto USR = Req.getString(KeyUSR)) {
return Lang.getCursorInfoFromUSR(
*SourceFile, *USR, Args,
[Rec](const CursorInfo &Info) { reportCursorInfo(Info, Rec); });
}
return Rec(createErrorRequestInvalid(
"either 'key.offset' or 'key.usr' is required"));
}
if (ReqUID == RequestRelatedIdents) {