@@ -58,12 +58,12 @@ package struct RelativeFileLocation: Hashable, ExpressibleByStringLiteral {
58
58
/// The temporary files will be deleted when the `TestSourceKitLSPClient` is destructed.
59
59
package class MultiFileTestProject {
60
60
/// Information necessary to open a file in the LSP server by its filename.
61
- private struct FileData {
61
+ package struct FileData {
62
62
/// The URI at which the file is stored on disk.
63
- let uri : DocumentURI
63
+ package let uri : DocumentURI
64
64
65
65
/// The contents of the file including location markers.
66
- let markedText : String
66
+ package let markedText : String
67
67
}
68
68
69
69
package let testClient : TestSourceKitLSPClient
@@ -79,29 +79,10 @@ package class MultiFileTestProject {
79
79
/// The directory in which the temporary files are being placed.
80
80
package let scratchDirectory : URL
81
81
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(
90
83
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 ] {
105
86
try FileManager . default. createDirectory ( at: scratchDirectory, withIntermediateDirectories: true )
106
87
107
88
var fileData : [ String : FileData ] = [ : ]
@@ -134,7 +115,33 @@ package class MultiFileTestProject {
134
115
)
135
116
}
136
117
}
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)
138
145
139
146
self . testClient = try await TestSourceKitLSPClient (
140
147
options: options,
0 commit comments