mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[sourcekitd-test] Support refactoring based on a byte offset location
If an offset position but no line/column combination is given to `sourcekitd-test` when requesting a refactoring action, compute the line/column from the offset.
This commit is contained in:
@@ -129,6 +129,7 @@ func hasCallToAsyncAlternative() {
|
|||||||
// CHECK1-NEXT: ACTIONS END
|
// CHECK1-NEXT: ACTIONS END
|
||||||
|
|
||||||
// RUN: %sourcekitd-test -req=cursor -pos=1:16 -cursor-action %s -- %s | %FileCheck %s -check-prefix=CHECK2
|
// RUN: %sourcekitd-test -req=cursor -pos=1:16 -cursor-action %s -- %s | %FileCheck %s -check-prefix=CHECK2
|
||||||
|
// RUN: %sourcekitd-test -req=cursor -offset=16 -cursor-action %s -- %s | %FileCheck %s -check-prefix=CHECK2
|
||||||
|
|
||||||
// RUN: %sourcekitd-test -req=cursor -pos=12:8 -cursor-action %s -- %s | %FileCheck %s -check-prefix=CHECK3
|
// RUN: %sourcekitd-test -req=cursor -pos=12:8 -cursor-action %s -- %s | %FileCheck %s -check-prefix=CHECK3
|
||||||
// RUN: %sourcekitd-test -req=cursor -pos=21:5 -cursor-action %s -- %s | %FileCheck %s -check-prefix=CHECK4
|
// RUN: %sourcekitd-test -req=cursor -pos=21:5 -cursor-action %s -- %s | %FileCheck %s -check-prefix=CHECK4
|
||||||
|
|||||||
@@ -489,6 +489,23 @@ static int handleTestInvocation(ArrayRef<const char *> Args,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void setRefactoringFields(sourcekitd_object_t &Req, TestOptions Opts,
|
||||||
|
sourcekitd_uid_t RefactoringKind,
|
||||||
|
llvm::MemoryBuffer *SourceBuf) {
|
||||||
|
if (Opts.Offset && !Opts.Line && !Opts.Col) {
|
||||||
|
auto LineCol = resolveToLineCol(Opts.Offset, SourceBuf);
|
||||||
|
Opts.Line = LineCol.first;
|
||||||
|
Opts.Col = LineCol.second;
|
||||||
|
}
|
||||||
|
sourcekitd_request_dictionary_set_uid(Req, KeyRequest,
|
||||||
|
RequestSemanticRefactoring);
|
||||||
|
sourcekitd_request_dictionary_set_uid(Req, KeyActionUID, RefactoringKind);
|
||||||
|
sourcekitd_request_dictionary_set_string(Req, KeyName, Opts.Name.c_str());
|
||||||
|
sourcekitd_request_dictionary_set_int64(Req, KeyLine, Opts.Line);
|
||||||
|
sourcekitd_request_dictionary_set_int64(Req, KeyColumn, Opts.Col);
|
||||||
|
sourcekitd_request_dictionary_set_int64(Req, KeyLength, Opts.Length);
|
||||||
|
}
|
||||||
|
|
||||||
static int handleTestInvocation(TestOptions Opts, TestOptions &InitOpts) {
|
static int handleTestInvocation(TestOptions Opts, TestOptions &InitOpts) {
|
||||||
if (!Opts.JsonRequestPath.empty())
|
if (!Opts.JsonRequestPath.empty())
|
||||||
return handleJsonRequestPath(Opts.JsonRequestPath, Opts);
|
return handleJsonRequestPath(Opts.JsonRequestPath, Opts);
|
||||||
@@ -721,16 +738,10 @@ static int handleTestInvocation(TestOptions Opts, TestOptions &InitOpts) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SEMANTIC_REFACTORING(KIND, NAME, ID) case SourceKitRequest::KIND: \
|
#define SEMANTIC_REFACTORING(KIND, NAME, ID) \
|
||||||
{ \
|
case SourceKitRequest::KIND: \
|
||||||
sourcekitd_request_dictionary_set_uid(Req, KeyRequest, RequestSemanticRefactoring); \
|
setRefactoringFields(Req, Opts, KindRefactoring##KIND, SourceBuf.get()); \
|
||||||
sourcekitd_request_dictionary_set_uid(Req, KeyActionUID, KindRefactoring##KIND); \
|
break;
|
||||||
sourcekitd_request_dictionary_set_string(Req, KeyName, Opts.Name.c_str()); \
|
|
||||||
sourcekitd_request_dictionary_set_int64(Req, KeyLine, Opts.Line); \
|
|
||||||
sourcekitd_request_dictionary_set_int64(Req, KeyColumn, Opts.Col); \
|
|
||||||
sourcekitd_request_dictionary_set_int64(Req, KeyLength, Opts.Length); \
|
|
||||||
break; \
|
|
||||||
}
|
|
||||||
#include "swift/IDE/RefactoringKinds.def"
|
#include "swift/IDE/RefactoringKinds.def"
|
||||||
|
|
||||||
case SourceKitRequest::MarkupToXML: {
|
case SourceKitRequest::MarkupToXML: {
|
||||||
|
|||||||
Reference in New Issue
Block a user