Skip to content

Commit c48e578

Browse files
authored
Merge pull request #70174 from ahoppen/ahoppen/dont-build-swift-refactor-without-swiftsyntax
[SourceKit] Support building sourcekitd without building swift-syntax
2 parents e5742b2 + a710111 commit c48e578

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+90
-23
lines changed

include/swift/Refactoring/Refactoring.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class RenameLocs {
100100
/// - valueDecl: The declaration that should be renamed
101101
RenameLocs localRenameLocs(SourceFile *sourceFile, const ValueDecl *valueDecl);
102102

103+
#if SWIFT_BUILD_SWIFT_SYNTAX
103104
/// Given a list of `RenameLoc`s, get the corresponding `ResolveLoc`s.
104105
///
105106
/// These resolve locations contain more structured information, such as the
@@ -112,6 +113,7 @@ std::vector<ResolvedLoc> resolveRenameLocations(ArrayRef<RenameLoc> renameLocs,
112113
StringRef newName,
113114
SourceFile &sourceFile,
114115
DiagnosticEngine &diags);
116+
#endif
115117

116118
struct RangeConfig {
117119
unsigned BufferID;

lib/IDE/Utils.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@ class ClangFileRewriterHelper {
808808
getBuffer());
809809
RewriteBuf.Initialize(Input);
810810
removeCommentLines(RewriteBuf, Input, "RUN");
811+
removeCommentLines(RewriteBuf, Input, "REQUIRES");
811812
removeCommentLines(RewriteBuf, Input, "CHECK");
812813
}
813814

lib/Refactoring/CMakeLists.txt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
if (NOT SWIFT_BUILD_SWIFT_SYNTAX)
2-
# swiftRefactoring requires SwiftIDEUtilsBriding, which isn't built if SWIFT_BUILD_SWIFT_SYNTAX is `NO`.
3-
return()
4-
endif()
5-
61
add_swift_host_library(swiftRefactoring STATIC
72
AddEquatableConformance.cpp
83
AddExplicitCodableImplementation.cpp
@@ -55,5 +50,11 @@ target_link_libraries(swiftRefactoring PRIVATE
5550
swiftParse
5651
swiftSema)
5752

58-
set_swift_llvm_is_available(swiftRefactoring)
53+
if(SWIFT_BUILD_SWIFT_SYNTAX)
54+
target_compile_definitions(swiftRefactoring
55+
PRIVATE
56+
SWIFT_BUILD_SWIFT_SYNTAX
57+
)
58+
endif()
5959

60+
set_swift_llvm_is_available(swiftRefactoring)

lib/Refactoring/SyntacticRename.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using namespace swift;
2222
using namespace swift::ide;
2323

24+
#if SWIFT_BUILD_SWIFT_SYNTAX
2425
std::vector<ResolvedLoc>
2526
swift::ide::resolveRenameLocations(ArrayRef<RenameLoc> RenameLocs,
2627
StringRef NewName, SourceFile &SF,
@@ -105,13 +106,17 @@ swift::ide::resolveRenameLocations(ArrayRef<RenameLoc> RenameLocs,
105106
}
106107
return resolvedLocsInRequestedOrder;
107108
}
109+
#endif
108110

109111
CancellableResult<std::vector<SyntacticRenameRangeDetails>>
110112
swift::ide::findSyntacticRenameRanges(SourceFile *SF,
111113
ArrayRef<RenameLoc> RenameLocs,
112114
StringRef NewName) {
113115
using ResultType =
114116
CancellableResult<std::vector<SyntacticRenameRangeDetails>>;
117+
#if !SWIFT_BUILD_SWIFT_SYNTAX
118+
return ResultType::failure("find-syntactic-rename-ranges is not supported because sourcekitd was built without swift-syntax");
119+
#else
115120
assert(SF && "null source file");
116121

117122
SourceManager &SM = SF->getASTContext().SourceMgr;
@@ -146,4 +151,5 @@ swift::ide::findSyntacticRenameRanges(SourceFile *SF,
146151
return ResultType::failure(ErrBuffer);
147152

148153
return ResultType::success(Result);
154+
#endif
149155
}

test/SourceKit/CursorInfo/cursor_callargs.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class C1 {
66
var c1 = C1(passInt: 0, andThis: 0)
77
c1.meth(0, passFloat: 0)
88

9+
// REQUIRES: swift_swift_parser
910
// RUN: %sourcekitd-test -req=cursor -pos=6:11 %s -- %s | %FileCheck -check-prefix=CHECK-CLASS %s
1011
// CHECK-CLASS: source.lang.swift.ref.class (2:7-2:9)
1112
// CHECK-CLASS: s:15cursor_callargs2C1C

test/SourceKit/Misc/stats.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
func foo() {}
22

3+
// REQUIRES: swift_swift_parser
34
// RUN: %sourcekitd-test -req=syntax-map %s == -req=stats | %FileCheck %s -check-prefix=SYNTAX_1
45

56
// SYNTAX_1: {{.*}} source.statistic.instruction-count

test/SourceKit/Refactoring/find-rename-ranges.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ struct Foo {
117117
static var test: Int = 10
118118
}
119119

120+
// REQUIRES: swift_swift_parser
121+
120122
// RUN: %empty-directory(%t.result)
121123

122124
// Ensure that a syntactic rename request does not require the stdlib

test/SourceKit/Refactoring/ordering.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func test(c: C) {
3535
/*C_foo3_call_arg2*/b: 2)
3636
}
3737

38+
// REQUIRES: swift_swift_parser
3839
// RUN: %empty-directory(%t.result)
3940
// RUN: %sourcekitd-test -req=find-rename-ranges -rename-spec %S/ordering/ordering.in.json %s >> %t.result/ordering.expected
4041
// RUN: %diff -u %S/ordering/ordering.expected %t.result/ordering.expected

test/SourceKit/Refactoring/rename-mismatch.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// REQUIRES: swift_swift_parser
12
// RUN: %empty-directory(%t)
23
// RUN: split-file --leading-lines %s %t
34

@@ -17,11 +18,11 @@ _ = Sss()
1718
// RUN: %sourcekitd-test -req=find-rename-ranges -rename-spec %t/rename-spec.json %t/input.swift | %FileCheck %s
1819

1920
// CHECK: source.edit.kind.active:
20-
// CHECK: 5:8-5:11 source.refactoring.range.kind.basename
21+
// CHECK: 6:8-6:11 source.refactoring.range.kind.basename
2122
// CHECK: source.edit.kind.unknown:
2223
// CHECK: source.edit.kind.mismatch:
2324
// CHECK: source.edit.kind.active:
24-
// CHECK: 10:5-10:8 source.refactoring.range.kind.basename
25+
// CHECK: 11:5-11:8 source.refactoring.range.kind.basename
2526

2627
//--- rename-spec.json
2728

@@ -33,22 +34,22 @@ _ = Sss()
3334
"key.is_non_protocol_type": 1,
3435
"key.locations": [
3536
{
36-
"key.line": 5,
37+
"key.line": 6,
3738
"key.column": 8,
3839
"key.nametype": source.syntacticrename.definition
3940
},
4041
{
41-
"key.line": 8,
42+
"key.line": 9,
4243
"key.column": 5,
4344
"key.nametype": source.syntacticrename.unknown
4445
},
4546
{
46-
"key.line": 9,
47+
"key.line": 10,
4748
"key.column": 5,
4849
"key.nametype": source.syntacticrename.unknown
4950
},
5051
{
51-
"key.line": 10,
52+
"key.line": 11,
5253
"key.column": 5,
5354
"key.nametype": source.syntacticrename.reference
5455
}

test/SourceKit/Refactoring/rename-with-location-directive.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
func test() {}
33
#sourceLocation()
44

5+
// REQUIRES: swift_swift_parser
56
// RUN: %sourcekitd-test -req=find-local-rename-ranges -pos=2:6 %s -- %s | %FileCheck %s
67
// CHECK: 2:6-2:10 source.refactoring.range.kind.basename

0 commit comments

Comments
 (0)