Skip to content

[SourceKit] Add a SourceKitd test argument -pos-end. #5679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions test/SourceKit/RangeInfo/basic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ struct S { func foo() {} }
// RUN: %sourcekitd-test -req=range -pos=3:1 -length 55 %s -- %s | %FileCheck %s -check-prefix=CHECK9
// RUN: %sourcekitd-test -req=range -pos=4:1 -length 36 %s -- %s | %FileCheck %s -check-prefix=CHECK10

// RUN: %sourcekitd-test -req=range -pos=8:1 -end-pos 8:32 %s -- %s | %FileCheck %s -check-prefix=CHECK5
// RUN: %sourcekitd-test -req=range -pos=9:1 -end-pos 9:26 %s -- %s | %FileCheck %s -check-prefix=CHECK6
// RUN: %sourcekitd-test -req=range -pos=10:1 -end-pos 10:27 %s -- %s | %FileCheck %s -check-prefix=CHECK7
// RUN: %sourcekitd-test -req=range -pos=3:1 -end-pos=4:26 %s -- %s | %FileCheck %s -check-prefix=CHECK8
// RUN: %sourcekitd-test -req=range -pos=3:1 -end-pos=5:13 %s -- %s | %FileCheck %s -check-prefix=CHECK9
// RUN: %sourcekitd-test -req=range -pos=4:1 -end-pos=5:13 %s -- %s | %FileCheck %s -check-prefix=CHECK10

// CHECK1-DAG: <kind>source.lang.swift.range.singleexpression</kind>
// CHECK1-DAG: <content>1 + 2</content>
// CHECK1-DAG: <type>Int</type>
Expand Down
3 changes: 3 additions & 0 deletions tools/SourceKit/tools/sourcekitd-test/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,6 @@ def interested_usr : Separate<["-"], "interested-usr">,

def async : Flag<["-"], "async">,
HelpText<"Perform request asynchronously">;

def end_pos : Separate<["-"], "end-pos">, HelpText<"line:col">;
def end_pos_EQ : Joined<["-"], "end-pos=">, Alias<end_pos>;
7 changes: 7 additions & 0 deletions tools/SourceKit/tools/sourcekitd-test/TestOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ bool TestOptions::parseArgs(llvm::ArrayRef<const char *> Args) {
break;
}

case OPT_end_pos: {
auto linecol = parseLineCol(InputArg->getValue());
EndLine = linecol.first;
EndCol = linecol.second;
break;
}

case OPT_line:
if (StringRef(InputArg->getValue()).getAsInteger(10, Line)) {
llvm::errs() << "error: expected integer for 'line'\n";
Expand Down
2 changes: 2 additions & 0 deletions tools/SourceKit/tools/sourcekitd-test/TestOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ struct TestOptions {
std::string InterestedUSR;
unsigned Line = 0;
unsigned Col = 0;
unsigned EndLine = 0;
unsigned EndCol = 0;
unsigned Offset = 0;
unsigned Length = 0;
llvm::Optional<std::string> ReplaceText;
Expand Down
11 changes: 8 additions & 3 deletions tools/SourceKit/tools/sourcekitd-test/sourcekitd-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,12 +543,17 @@ static int handleTestInvocation(ArrayRef<const char *> Args,
sourcekitd_request_dictionary_set_int64(Req, KeyOffset, ByteOffset);
}
break;
case SourceKitRequest::RangeInfo:
case SourceKitRequest::RangeInfo: {
sourcekitd_request_dictionary_set_uid(Req, KeyRequest, RequestRangeInfo);
sourcekitd_request_dictionary_set_int64(Req, KeyOffset, ByteOffset);
sourcekitd_request_dictionary_set_int64(Req, KeyLength, Opts.Length);
auto Length = Opts.Length;
if (Opts.Length == 0 && Opts.EndLine > 0) {
auto EndOff = resolveFromLineCol(Opts.EndLine, Opts.EndCol, SourceFile);
Length = EndOff - ByteOffset;
}
sourcekitd_request_dictionary_set_int64(Req, KeyLength, Length);
break;

}
case SourceKitRequest::RelatedIdents:
sourcekitd_request_dictionary_set_uid(Req, KeyRequest, RequestRelatedIdents);
sourcekitd_request_dictionary_set_int64(Req, KeyOffset, ByteOffset);
Expand Down