@@ -239,42 +239,67 @@ final class WorkspaceTests: XCTestCase {
239
239
}
240
240
241
241
func testChangeWorkspaceFolders( ) async throws {
242
- guard let ws = try await staticSourceKitSwiftPMWorkspace ( name: " ChangeWorkspaceFolders " ) else { return }
243
- // Build the package. We can't use ws.buildAndIndex() because that doesn't put the build products in .build where SourceKit-LSP expects them.
242
+ let ws = try await MultiFileTestWorkspace (
243
+ files: [
244
+ " subdir/Sources/otherPackage/otherPackage.swift " : """
245
+ import package
246
+
247
+ func test() {
248
+ Package().1️⃣helloWorld()
249
+ }
250
+ """ ,
251
+ " subdir/Sources/package/package.swift " : """
252
+ public struct Package {
253
+ public init() {}
254
+
255
+ public func helloWorld() {
256
+ print( " Hello world! " )
257
+ }
258
+ }
259
+ """ ,
260
+ " subdir/Package.swift " : """
261
+ // swift-tools-version: 5.5
262
+
263
+ import PackageDescription
264
+
265
+ let package = Package(
266
+ name: " package " ,
267
+ products: [
268
+ .library(name: " package " , targets: [ " package " ]),
269
+ .library(name: " otherPackage " , targets: [ " otherPackage " ]),
270
+ ],
271
+ targets: [
272
+ .target(
273
+ name: " package " ,
274
+ dependencies: []
275
+ ),
276
+ .target(
277
+ name: " otherPackage " ,
278
+ dependencies: [ " package " ]
279
+ ),
280
+ ]
281
+ )
282
+ """ ,
283
+ ]
284
+ )
285
+
286
+ let packageDir = try ws. uri ( for: " Package.swift " ) . fileURL!. deletingLastPathComponent ( )
287
+
244
288
try await TSCBasic . Process. checkNonZeroExit ( arguments: [
245
289
ToolchainRegistry . shared. default!. swift!. pathString,
246
290
" build " ,
247
- " --package-path " , ws . sources . rootDirectory . path,
291
+ " --package-path " , packageDir . path,
248
292
" -Xswiftc " , " -index-ignore-system-modules " ,
249
293
" -Xcc " , " -index-ignore-system-symbols " ,
250
294
] )
251
295
252
- let otherPackLoc = ws. testLoc ( " otherPackage:call " )
253
-
254
- let testClient = try await TestSourceKitLSPClient (
255
- capabilities: ClientCapabilities (
256
- workspace: . init( workspaceFolders: true )
257
- ) ,
258
- workspaceFolders: [ WorkspaceFolder ( uri: DocumentURI ( ws. sources. rootDirectory. deletingLastPathComponent ( ) ) ) ]
259
- )
296
+ let ( otherPackageUri, positions) = try ws. openDocument ( " otherPackage.swift " )
297
+ let testPosition = positions [ " 1️⃣ " ]
260
298
261
- let docString = try String ( data: Data ( contentsOf: otherPackLoc. url) , encoding: . utf8) !
262
-
263
- testClient. send (
264
- DidOpenTextDocumentNotification (
265
- textDocument: TextDocumentItem (
266
- uri: otherPackLoc. docUri,
267
- language: . swift,
268
- version: 1 ,
269
- text: docString
270
- )
271
- )
272
- )
273
-
274
- let preChangeWorkspaceResponse = try await testClient. send (
299
+ let preChangeWorkspaceResponse = try await ws. testClient. send (
275
300
CompletionRequest (
276
- textDocument: TextDocumentIdentifier ( otherPackLoc . docUri ) ,
277
- position: otherPackLoc . position
301
+ textDocument: TextDocumentIdentifier ( otherPackageUri ) ,
302
+ position: testPosition
278
303
)
279
304
)
280
305
@@ -284,18 +309,18 @@ final class WorkspaceTests: XCTestCase {
284
309
" Did not expect to receive cross-module code completion results if we opened the parent directory of the package "
285
310
)
286
311
287
- testClient. send (
312
+ ws . testClient. send (
288
313
DidChangeWorkspaceFoldersNotification (
289
314
event: WorkspaceFoldersChangeEvent ( added: [
290
- WorkspaceFolder ( uri: DocumentURI ( ws . sources . rootDirectory ) )
315
+ WorkspaceFolder ( uri: DocumentURI ( packageDir ) )
291
316
] )
292
317
)
293
318
)
294
319
295
- let postChangeWorkspaceResponse = try await testClient. send (
320
+ let postChangeWorkspaceResponse = try await ws . testClient. send (
296
321
CompletionRequest (
297
- textDocument: TextDocumentIdentifier ( otherPackLoc . docUri ) ,
298
- position: otherPackLoc . position
322
+ textDocument: TextDocumentIdentifier ( otherPackageUri ) ,
323
+ position: testPosition
299
324
)
300
325
)
301
326
@@ -314,7 +339,7 @@ final class WorkspaceTests: XCTestCase {
314
339
insertTextFormat: . plain,
315
340
textEdit: . textEdit(
316
341
TextEdit (
317
- range: otherPackLoc . position ..< otherPackLoc . position ,
342
+ range: Range ( testPosition ) ,
318
343
newText: " helloWorld() "
319
344
)
320
345
)
@@ -331,7 +356,7 @@ final class WorkspaceTests: XCTestCase {
331
356
insertTextFormat: . plain,
332
357
textEdit: . textEdit(
333
358
TextEdit (
334
- range: otherPackLoc . position ..< otherPackLoc . position ,
359
+ range: Range ( testPosition ) ,
335
360
newText: " self "
336
361
)
337
362
)
0 commit comments