mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[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:
@@ -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:
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user