Skip to content

Commit 4c213c4

Browse files
committed
[sourcekitd-test] Add ability to expand single placeholder
1 parent 54683ca commit 4c213c4

File tree

2 files changed

+28
-23
lines changed

2 files changed

+28
-23
lines changed

test/SourceKit/CodeExpand/code-expand-rdar77665805.swift

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,13 @@
1-
// BEGIN main.swift
21
enum E { case foo, bar }
32
func foo(x: (E) -> Void) {}
43
func test() {
54
foo(x: <#T##(E) -> Void#>)
65
}
76

8-
// BEGIN expand.json.in
9-
{
10-
key.request: source.request.editor.expand_placeholder,
11-
key.offset: 23,
12-
key.length: 18,
13-
key.name: "FILENAME"
14-
}
15-
16-
// RUN: %empty-directory(%t)
17-
// RUN: %{python} %utils/split_file.py -o %t %s
18-
19-
// RUN: sed "s#FILENAME#%t/main.swift#" %t/expand.json.in > %t/expand.json
20-
217
// RUN: %sourcekitd-test \
22-
// RUN: -req=open %t/main.swift -- %t/main.swift == \
23-
// RUN: -req=edit -offset=0 -length=53 -replace="" -req-opts=enablesyntaxmap=0,enablesubstructure=0,enablediagnostics=0 %t/main.swift -- %t/main.swift == \
24-
// RUN: -json-request-path %t/expand.json \
8+
// RUN: -req=open %s -- %s == \
9+
// RUN: -req=edit -offset=0 -length=53 -replace="" -req-opts=enablesyntaxmap=0,enablesubstructure=0,enablediagnostics=0 %s -- %s == \
10+
// RUN: -req=expand-placeholder -offset=23 -length=18 %s \
2511
// RUN: | %FileCheck %s
2612

2713
// CHECK: {

tools/SourceKit/tools/sourcekitd-test/sourcekitd-test.cpp

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -834,11 +834,24 @@ static int handleTestInvocation(TestOptions Opts, TestOptions &InitOpts) {
834834
break;
835835

836836
case SourceKitRequest::ExpandPlaceholder:
837-
sourcekitd_request_dictionary_set_uid(Req, KeyRequest, RequestEditorOpen);
838-
sourcekitd_request_dictionary_set_string(Req, KeyName, SemaName.c_str());
839-
sourcekitd_request_dictionary_set_int64(Req, KeyEnableSyntaxMap, false);
840-
sourcekitd_request_dictionary_set_int64(Req, KeyEnableStructure, false);
841-
sourcekitd_request_dictionary_set_int64(Req, KeySyntacticOnly, !Opts.UsedSema);
837+
if (Opts.Length) {
838+
// Single placeholder by location.
839+
sourcekitd_request_dictionary_set_uid(Req, KeyRequest, RequestEditorExpandPlaceholder);
840+
sourcekitd_request_dictionary_set_string(Req, KeyName, SemaName.c_str());
841+
sourcekitd_request_dictionary_set_int64(Req, KeyOffset, ByteOffset);
842+
sourcekitd_request_dictionary_set_int64(Req, KeyLength, Opts.Length);
843+
} else {
844+
if (ByteOffset) {
845+
llvm::errs() << "Missing '-length <number>'\n";
846+
return 1;
847+
}
848+
// Expand all placeholders.
849+
sourcekitd_request_dictionary_set_uid(Req, KeyRequest, RequestEditorOpen);
850+
sourcekitd_request_dictionary_set_string(Req, KeyName, SemaName.c_str());
851+
sourcekitd_request_dictionary_set_int64(Req, KeyEnableSyntaxMap, false);
852+
sourcekitd_request_dictionary_set_int64(Req, KeyEnableStructure, false);
853+
sourcekitd_request_dictionary_set_int64(Req, KeySyntacticOnly, !Opts.UsedSema);
854+
}
842855
break;
843856

844857
case SourceKitRequest::SyntaxTree:
@@ -1341,7 +1354,13 @@ static bool handleResponse(sourcekitd_response_t Resp, const TestOptions &Opts,
13411354
break;
13421355

13431356
case SourceKitRequest::ExpandPlaceholder:
1344-
expandPlaceholders(SourceBuf.get(), llvm::outs());
1357+
if (Opts.Length) {
1358+
// Single placeholder by location.
1359+
sourcekitd_response_description_dump_filedesc(Resp, STDOUT_FILENO);
1360+
} else {
1361+
// Expand all placeholders.
1362+
expandPlaceholders(SourceBuf.get(), llvm::outs());
1363+
}
13451364
break;
13461365
case SourceKitRequest::ModuleGroups:
13471366
printModuleGroupNames(Info, llvm::outs());

0 commit comments

Comments
 (0)