@@ -106,304 +106,6 @@ package actor SkipUnless {
106
106
}
107
107
}
108
108
109
- package static func sourcekitdHasSemanticTokensRequest(
110
- file: StaticString = #filePath,
111
- line: UInt = #line
112
- ) async throws {
113
- try await shared. skipUnlessSupportedByToolchain ( swiftVersion: SwiftVersion ( 5 , 11 ) , file: file, line: line) {
114
- let testClient = try await TestSourceKitLSPClient ( )
115
- let uri = DocumentURI ( for: . swift)
116
- testClient. openDocument ( " 0.bitPattern " , uri: uri)
117
- let response = try unwrap (
118
- await testClient. send ( DocumentSemanticTokensRequest ( textDocument: TextDocumentIdentifier ( uri) ) )
119
- )
120
-
121
- let tokens = SyntaxHighlightingTokens ( lspEncodedTokens: response. data)
122
-
123
- // If we don't have semantic token support in sourcekitd, the second token is an identifier based on the syntax
124
- // tree, not a property.
125
- return tokens. tokens != [
126
- SyntaxHighlightingToken (
127
- range: Position ( line: 0 , utf16index: 0 ) ..< Position ( line: 0 , utf16index: 1 ) ,
128
- kind: . number,
129
- modifiers: [ ]
130
- ) ,
131
- SourceKitLSP . SyntaxHighlightingToken (
132
- range: Position ( line: 0 , utf16index: 2 ) ..< Position ( line: 0 , utf16index: 12 ) ,
133
- kind: . identifier,
134
- modifiers: [ ]
135
- ) ,
136
- ]
137
- }
138
- }
139
-
140
- package static func sourcekitdSupportsRename(
141
- file: StaticString = #filePath,
142
- line: UInt = #line
143
- ) async throws {
144
- try await shared. skipUnlessSupportedByToolchain ( swiftVersion: SwiftVersion ( 5 , 11 ) , file: file, line: line) {
145
- let testClient = try await TestSourceKitLSPClient ( )
146
- let uri = DocumentURI ( for: . swift)
147
- let positions = testClient. openDocument ( " func 1️⃣test() {} " , uri: uri)
148
- do {
149
- _ = try await testClient. send (
150
- RenameRequest ( textDocument: TextDocumentIdentifier ( uri) , position: positions [ " 1️⃣ " ] , newName: " test2 " )
151
- )
152
- } catch let error as ResponseError {
153
- return error. message != " Running sourcekit-lsp with a version of sourcekitd that does not support rename "
154
- }
155
- return true
156
- }
157
- }
158
-
159
- /// Checks whether the sourcekitd contains a fix to rename labels of enum cases correctly
160
- /// (https://github.com/apple/swift/pull/74241).
161
- package static func sourcekitdCanRenameEnumCaseLabels(
162
- file: StaticString = #filePath,
163
- line: UInt = #line
164
- ) async throws {
165
- return try await shared. skipUnlessSupportedByToolchain ( swiftVersion: SwiftVersion ( 6 , 0 ) , file: file, line: line) {
166
- let testClient = try await TestSourceKitLSPClient ( )
167
- let uri = DocumentURI ( for: . swift)
168
- let positions = testClient. openDocument (
169
- """
170
- enum MyEnum {
171
- case 1️⃣myCase(2️⃣String)
172
- }
173
- """ ,
174
- uri: uri
175
- )
176
-
177
- let renameResult = try await testClient. send (
178
- RenameRequest ( textDocument: TextDocumentIdentifier ( uri) , position: positions [ " 1️⃣ " ] , newName: " myCase(label:) " )
179
- )
180
- return renameResult? . changes == [ uri: [ TextEdit ( range: Range ( positions [ " 2️⃣ " ] ) , newText: " label: " ) ] ]
181
- }
182
- }
183
-
184
- /// Whether clangd has support for the `workspace/indexedRename` request.
185
- package static func clangdSupportsIndexBasedRename(
186
- file: StaticString = #filePath,
187
- line: UInt = #line
188
- ) async throws {
189
- try await shared. skipUnlessSupportedByToolchain ( swiftVersion: SwiftVersion ( 5 , 11 ) , file: file, line: line) {
190
- let testClient = try await TestSourceKitLSPClient ( )
191
- let uri = DocumentURI ( for: . c)
192
- let positions = testClient. openDocument ( " void 1️⃣test() {} " , uri: uri)
193
- do {
194
- _ = try await testClient. send (
195
- IndexedRenameRequest (
196
- textDocument: TextDocumentIdentifier ( uri) ,
197
- oldName: " test " ,
198
- newName: " test2 " ,
199
- positions: [ uri: [ positions [ " 1️⃣ " ] ] ]
200
- )
201
- )
202
- } catch let error as ResponseError {
203
- return error. message != " method not found "
204
- }
205
- return true
206
- }
207
- }
208
-
209
- /// SwiftPM moved the location where it stores Swift modules to a subdirectory in
210
- /// https://github.com/swiftlang/swift-package-manager/pull/7103.
211
- package static func swiftpmStoresModulesInSubdirectory(
212
- file: StaticString = #filePath,
213
- line: UInt = #line
214
- ) async throws {
215
- try await shared. skipUnlessSupportedByToolchain ( swiftVersion: SwiftVersion ( 5 , 11 ) , file: file, line: line) {
216
- let workspace = try await SwiftPMTestProject ( files: [ " test.swift " : " " ] )
217
- try await SwiftPMTestProject . build ( at: workspace. scratchDirectory)
218
- let modulesDirectory = workspace. scratchDirectory
219
- . appendingPathComponent ( " .build " )
220
- . appendingPathComponent ( " debug " )
221
- . appendingPathComponent ( " Modules " )
222
- . appendingPathComponent ( " MyLibrary.swiftmodule " )
223
- return FileManager . default. fileExists ( atPath: modulesDirectory. path)
224
- }
225
- }
226
-
227
- package static func toolchainContainsSwiftFormat(
228
- file: StaticString = #filePath,
229
- line: UInt = #line
230
- ) async throws {
231
- try await shared. skipUnlessSupportedByToolchain ( swiftVersion: SwiftVersion ( 5 , 11 ) , file: file, line: line) {
232
- return await ToolchainRegistry . forTesting. default? . swiftFormat != nil
233
- }
234
- }
235
-
236
- /// Checks if the toolchain contains https://github.com/apple/swift/pull/74080.
237
- package static func sourcekitdReportsOverridableFunctionDefinitionsAsDynamic(
238
- file: StaticString = #filePath,
239
- line: UInt = #line
240
- ) async throws {
241
- struct ExpectedLocationsResponse : Error { }
242
-
243
- return try await shared. skipUnlessSupportedByToolchain ( swiftVersion: SwiftVersion ( 6 , 0 ) , file: file, line: line) {
244
- let project = try await IndexedSingleSwiftFileTestProject (
245
- """
246
- protocol TestProtocol {
247
- func 1️⃣doThing()
248
- }
249
-
250
- struct TestImpl: TestProtocol {}
251
- extension TestImpl {
252
- func 2️⃣doThing() { }
253
- }
254
- """
255
- )
256
-
257
- let response = try await project. testClient. send (
258
- DefinitionRequest ( textDocument: TextDocumentIdentifier ( project. fileURI) , position: project. positions [ " 1️⃣ " ] )
259
- )
260
- guard case . locations( let locations) = response else {
261
- throw ExpectedLocationsResponse ( )
262
- }
263
- return locations. contains { $0. range == Range ( project. positions [ " 2️⃣ " ] ) }
264
- }
265
- }
266
-
267
- package static func sourcekitdReturnsRawDocumentationResponse(
268
- file: StaticString = #filePath,
269
- line: UInt = #line
270
- ) async throws {
271
- struct ExpectedMarkdownContentsError : Error { }
272
-
273
- return try await shared. skipUnlessSupportedByToolchain ( swiftVersion: SwiftVersion ( 6 , 0 ) , file: file, line: line) {
274
- // The XML-based doc comment conversion did not preserve `Precondition`.
275
- let testClient = try await TestSourceKitLSPClient ( )
276
- let uri = DocumentURI ( for: . swift)
277
- let positions = testClient. openDocument (
278
- """
279
- /// - Precondition: Must have an apple
280
- func 1️⃣test() {}
281
- """ ,
282
- uri: uri
283
- )
284
- let response = try await testClient. send (
285
- HoverRequest ( textDocument: TextDocumentIdentifier ( uri) , position: positions [ " 1️⃣ " ] )
286
- )
287
- let hover = try XCTUnwrap ( response, file: file, line: line)
288
- XCTAssertNil ( hover. range, file: file, line: line)
289
- guard case . markupContent( let content) = hover. contents else {
290
- throw ExpectedMarkdownContentsError ( )
291
- }
292
- return content. value. contains ( " Precondition " )
293
- }
294
- }
295
-
296
- /// Checks whether the index contains a fix that prevents it from adding relations to non-indexed locals
297
- /// (https://github.com/apple/swift/pull/72930).
298
- package static func indexOnlyHasContainedByRelationsToIndexedDecls(
299
- file: StaticString = #filePath,
300
- line: UInt = #line
301
- ) async throws {
302
- return try await shared. skipUnlessSupportedByToolchain ( swiftVersion: SwiftVersion ( 6 , 0 ) , file: file, line: line) {
303
- let project = try await IndexedSingleSwiftFileTestProject (
304
- """
305
- func foo() {}
306
-
307
- func 1️⃣testFunc(x: String) {
308
- let myVar = foo
309
- }
310
- """
311
- )
312
- let prepare = try await project. testClient. send (
313
- CallHierarchyPrepareRequest (
314
- textDocument: TextDocumentIdentifier ( project. fileURI) ,
315
- position: project. positions [ " 1️⃣ " ]
316
- )
317
- )
318
- let initialItem = try XCTUnwrap ( prepare? . only)
319
- let calls = try await project. testClient. send ( CallHierarchyOutgoingCallsRequest ( item: initialItem) )
320
- return calls != [ ]
321
- }
322
- }
323
-
324
- public static func swiftPMSupportsExperimentalPrepareForIndexing(
325
- file: StaticString = #filePath,
326
- line: UInt = #line
327
- ) async throws {
328
- struct NoSwiftInToolchain : Error { }
329
-
330
- return try await shared. skipUnlessSupportedByToolchain ( swiftVersion: SwiftVersion ( 6 , 0 ) , file: file, line: line) {
331
- guard let swift = await ToolchainRegistry . forTesting. default? . swift else {
332
- throw NoSwiftInToolchain ( )
333
- }
334
-
335
- let result = try await Process . run (
336
- arguments: [ swift. pathString, " build " , " --help-hidden " ] ,
337
- workingDirectory: nil
338
- )
339
- guard let output = String ( bytes: try result. output. get ( ) , encoding: . utf8) else {
340
- return false
341
- }
342
- return output. contains ( " --experimental-prepare-for-indexing " )
343
- }
344
- }
345
-
346
- package static func swiftPMStoresModulesForTargetAndHostInSeparateFolders(
347
- file: StaticString = #filePath,
348
- line: UInt = #line
349
- ) async throws {
350
- struct NoSwiftInToolchain : Error { }
351
-
352
- return try await shared. skipUnlessSupportedByToolchain ( swiftVersion: SwiftVersion ( 6 , 0 ) , file: file, line: line) {
353
- guard let swift = await ToolchainRegistry . forTesting. default? . swift else {
354
- throw NoSwiftInToolchain ( )
355
- }
356
-
357
- let project = try await SwiftPMTestProject (
358
- files: [
359
- " Lib/MyFile.swift " : """
360
- public func foo() {}
361
- """ ,
362
- " MyExec/MyExec.swift " : """
363
- import Lib
364
- func bar() {
365
- foo()
366
- }
367
- """ ,
368
- " Plugins/MyPlugin/MyPlugin.swift " : " " ,
369
- ] ,
370
- manifest: """
371
- let package = Package(
372
- name: " MyLibrary " ,
373
- targets: [
374
- .target(name: " Lib " ),
375
- .executableTarget(name: " MyExec " , dependencies: [ " Lib " ]),
376
- .plugin(
377
- name: " MyPlugin " ,
378
- capability: .command(
379
- intent: .sourceCodeFormatting(),
380
- permissions: []
381
- ),
382
- dependencies: [ " MyExec " ]
383
- )
384
- ]
385
- )
386
- """
387
- )
388
- do {
389
- // In older version of SwiftPM building `MyPlugin` followed by `Lib` resulted in an error about a redefinition
390
- // of Lib when building Lib.
391
- for target in [ " MyPlugin " , " Lib " ] {
392
- var arguments = [
393
- swift. pathString, " build " , " --package-path " , project. scratchDirectory. path, " --target " , target,
394
- ]
395
- if let globalModuleCache {
396
- arguments += [ " -Xswiftc " , " -module-cache-path " , " -Xswiftc " , globalModuleCache. path]
397
- }
398
- try await Process . run ( arguments: arguments, workingDirectory: nil )
399
- }
400
- return true
401
- } catch {
402
- return false
403
- }
404
- }
405
- }
406
-
407
109
/// A long test is a test that takes longer than 1-2s to execute.
408
110
package static func longTestsEnabled( ) throws {
409
111
if let value = ProcessInfo . processInfo. environment [ " SKIP_LONG_TESTS " ] , value == " 1 " || value == " YES " {
@@ -497,37 +199,6 @@ package actor SkipUnless {
497
199
}
498
200
}
499
201
}
500
-
501
- /// Checks if sourcekitd contains https://github.com/swiftlang/swift/pull/71049
502
- package static func solverBasedCursorInfoWorksForMemoryOnlyFiles(
503
- file: StaticString = #filePath,
504
- line: UInt = #line
505
- ) async throws {
506
- struct ExpectedLocationsResponse : Error { }
507
-
508
- return try await shared. skipUnlessSupportedByToolchain ( swiftVersion: SwiftVersion ( 6 , 0 ) , file: file, line: line) {
509
- let testClient = try await TestSourceKitLSPClient ( )
510
- let uri = DocumentURI ( for: . swift)
511
- let positions = testClient. openDocument (
512
- """
513
- func foo() -> Int { 1 }
514
- func foo() -> String { " " }
515
- func test() {
516
- _ = 3️⃣foo()
517
- }
518
- """ ,
519
- uri: uri
520
- )
521
-
522
- let response = try await testClient. send (
523
- DefinitionRequest ( textDocument: TextDocumentIdentifier ( uri) , position: positions [ " 3️⃣ " ] )
524
- )
525
- guard case . locations( let locations) = response else {
526
- throw ExpectedLocationsResponse ( )
527
- }
528
- return locations. count > 0
529
- }
530
- }
531
202
}
532
203
533
204
// MARK: - Parsing Swift compiler version
0 commit comments