Skip to content

Commit 95f7fc9

Browse files
committed
Partially cherry-pick MultiFileTestProject changes
This was a small refactoring in a much larger PR.
1 parent 9e10ece commit 95f7fc9

File tree

1 file changed

+33
-26
lines changed

1 file changed

+33
-26
lines changed

Sources/SKTestSupport/MultiFileTestProject.swift

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ package struct RelativeFileLocation: Hashable, ExpressibleByStringLiteral {
5858
/// The temporary files will be deleted when the `TestSourceKitLSPClient` is destructed.
5959
package class MultiFileTestProject {
6060
/// Information necessary to open a file in the LSP server by its filename.
61-
private struct FileData {
61+
package struct FileData {
6262
/// The URI at which the file is stored on disk.
63-
let uri: DocumentURI
63+
package let uri: DocumentURI
6464

6565
/// The contents of the file including location markers.
66-
let markedText: String
66+
package let markedText: String
6767
}
6868

6969
package let testClient: TestSourceKitLSPClient
@@ -79,29 +79,10 @@ package class MultiFileTestProject {
7979
/// The directory in which the temporary files are being placed.
8080
package let scratchDirectory: URL
8181

82-
/// Writes the specified files to a temporary directory on disk and creates a `TestSourceKitLSPClient` for that
83-
/// temporary directory.
84-
///
85-
/// The file contents can contain location markers, which are returned when opening a document using
86-
/// ``openDocument(_:)``.
87-
///
88-
/// File contents can also contain `$TEST_DIR`, which gets replaced by the temporary directory.
89-
package init(
82+
package static func writeFilesToDisk(
9083
files: [RelativeFileLocation: String],
91-
workspaces: (_ scratchDirectory: URL) async throws -> [WorkspaceFolder] = {
92-
[WorkspaceFolder(uri: DocumentURI($0))]
93-
},
94-
initializationOptions: LSPAny? = nil,
95-
capabilities: ClientCapabilities = ClientCapabilities(),
96-
options: SourceKitLSPOptions = .testDefault(),
97-
testHooks: TestHooks = TestHooks(),
98-
enableBackgroundIndexing: Bool = false,
99-
usePullDiagnostics: Bool = true,
100-
preInitialization: ((TestSourceKitLSPClient) -> Void)? = nil,
101-
cleanUp: (@Sendable () -> Void)? = nil,
102-
testName: String = #function
103-
) async throws {
104-
scratchDirectory = try testScratchDir(testName: testName)
84+
scratchDirectory: URL
85+
) throws -> [String: FileData] {
10586
try FileManager.default.createDirectory(at: scratchDirectory, withIntermediateDirectories: true)
10687

10788
var fileData: [String: FileData] = [:]
@@ -134,7 +115,33 @@ package class MultiFileTestProject {
134115
)
135116
}
136117
}
137-
self.fileData = fileData
118+
return fileData
119+
}
120+
121+
/// Writes the specified files to a temporary directory on disk and creates a `TestSourceKitLSPClient` for that
122+
/// temporary directory.
123+
///
124+
/// The file contents can contain location markers, which are returned when opening a document using
125+
/// ``openDocument(_:)``.
126+
///
127+
/// File contents can also contain `$TEST_DIR`, which gets replaced by the temporary directory.
128+
package init(
129+
files: [RelativeFileLocation: String],
130+
workspaces: (_ scratchDirectory: URL) async throws -> [WorkspaceFolder] = {
131+
[WorkspaceFolder(uri: DocumentURI($0))]
132+
},
133+
initializationOptions: LSPAny? = nil,
134+
capabilities: ClientCapabilities = ClientCapabilities(),
135+
options: SourceKitLSPOptions = .testDefault(),
136+
testHooks: TestHooks = TestHooks(),
137+
enableBackgroundIndexing: Bool = false,
138+
usePullDiagnostics: Bool = true,
139+
preInitialization: ((TestSourceKitLSPClient) -> Void)? = nil,
140+
cleanUp: (@Sendable () -> Void)? = nil,
141+
testName: String = #function
142+
) async throws {
143+
scratchDirectory = try testScratchDir(testName: testName)
144+
self.fileData = try Self.writeFilesToDisk(files: files, scratchDirectory: scratchDirectory)
138145

139146
self.testClient = try await TestSourceKitLSPClient(
140147
options: options,

0 commit comments

Comments
 (0)