Skip to content

Commit 2d519a9

Browse files
committed
lol claude cheated but now this should work?
1 parent 937fcee commit 2d519a9

File tree

12 files changed

+1520
-444
lines changed

12 files changed

+1520
-444
lines changed

Sources/SwiftTSGo/BuildFileSystem.swift

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
import Foundation
22
import TSCBridge
33

4-
// MARK: - C String Helpers
5-
6-
private func withMutableCString<T>(_ string: String, _ body: (UnsafeMutablePointer<CChar>) -> T)
7-
-> T
8-
{
9-
string.withCString { cString in
10-
let mutableCString = strdup(cString)!
11-
defer { free(mutableCString) }
12-
return body(mutableCString)
13-
}
14-
}
15-
164
// MARK: - File System Build Functions
175

186
/// Build TypeScript project from filesystem
@@ -160,28 +148,6 @@ private func processFileSystemResult(_ cResult: UnsafeMutablePointer<c_build_res
160148
)
161149
}
162150

163-
private func convertCDiagnostics(_ cDiagnostics: UnsafeMutablePointer<c_diagnostic>?, count: Int)
164-
-> [DiagnosticInfo]
165-
{
166-
guard let cDiagnostics, count > 0 else { return [] }
167-
168-
var diagnostics: [DiagnosticInfo] = []
169-
for i in 0 ..< count {
170-
let cDiag = cDiagnostics[i]
171-
let diagnostic = DiagnosticInfo(
172-
code: Int(cDiag.code),
173-
category: String(cString: cDiag.category),
174-
message: String(cString: cDiag.message),
175-
file: String(cString: cDiag.file),
176-
line: Int(cDiag.line),
177-
column: Int(cDiag.column),
178-
length: Int(cDiag.length)
179-
)
180-
diagnostics.append(diagnostic)
181-
}
182-
return diagnostics
183-
}
184-
185151
private func convertCEmittedFiles(
186152
_ files: UnsafeMutablePointer<UnsafeMutablePointer<CChar>?>?,
187153
count: Int
@@ -198,31 +164,6 @@ private func convertCEmittedFiles(
198164
return emittedFiles
199165
}
200166

201-
private func convertCWrittenFiles(
202-
_ paths: UnsafeMutablePointer<UnsafeMutablePointer<CChar>?>?,
203-
_ contents: UnsafeMutablePointer<UnsafeMutablePointer<CChar>?>?,
204-
count: Int
205-
) -> [String: String] {
206-
guard let paths, let contents, count > 0 else { return [:] }
207-
208-
var writtenFiles: [String: String] = [:]
209-
for i in 0 ..< count {
210-
if let pathPtr = paths[i], let contentPtr = contents[i] {
211-
let path = String(cString: pathPtr)
212-
let content = String(cString: contentPtr)
213-
writtenFiles[path] = content
214-
}
215-
}
216-
return writtenFiles
217-
}
218-
219-
private func convertCCompiledFiles(from writtenFiles: [String: String]) -> [Source] {
220-
writtenFiles.map { path, content in
221-
let filename = (path as NSString).lastPathComponent
222-
return Source(name: filename, content: content)
223-
}
224-
}
225-
226167
// MARK: - Convenience Functions
227168

228169
/// Validate TypeScript project configuration without compilation
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import Foundation
2+
import TSCBridge
3+
4+
// MARK: - C Bridge Helpers
5+
6+
func convertCDiagnostics(_ cDiagnostics: UnsafeMutablePointer<c_diagnostic>?, count: Int)
7+
-> [DiagnosticInfo]
8+
{
9+
guard let cDiagnostics, count > 0 else { return [] }
10+
11+
var diagnostics: [DiagnosticInfo] = []
12+
for i in 0 ..< count {
13+
let cDiag = cDiagnostics[i]
14+
let diagnostic = DiagnosticInfo(
15+
code: Int(cDiag.code),
16+
category: String(cString: cDiag.category),
17+
message: String(cString: cDiag.message),
18+
file: String(cString: cDiag.file),
19+
line: Int(cDiag.line),
20+
column: Int(cDiag.column),
21+
length: Int(cDiag.length)
22+
)
23+
diagnostics.append(diagnostic)
24+
}
25+
return diagnostics
26+
}
27+
28+
func convertCWrittenFiles(
29+
_ paths: UnsafeMutablePointer<UnsafeMutablePointer<CChar>?>?,
30+
_ contents: UnsafeMutablePointer<UnsafeMutablePointer<CChar>?>?,
31+
count: Int
32+
) -> [String: String] {
33+
guard let paths, let contents, count > 0 else { return [:] }
34+
35+
var writtenFiles: [String: String] = [:]
36+
for i in 0 ..< count {
37+
if let pathPtr = paths[i], let contentPtr = contents[i] {
38+
let path = String(cString: pathPtr)
39+
let content = String(cString: contentPtr)
40+
writtenFiles[path] = content
41+
}
42+
}
43+
return writtenFiles
44+
}
45+
46+
func convertCCompiledFiles(from writtenFiles: [String: String]) -> [Source] {
47+
writtenFiles.map { path, content in
48+
let filename = (path as NSString).lastPathComponent
49+
return Source(name: filename, content: content)
50+
}
51+
}
52+
53+
func processResult(_ cResult: UnsafeMutablePointer<c_build_result>?) -> InMemoryBuildResult {
54+
guard let cResult else {
55+
return InMemoryBuildResult(
56+
success: false,
57+
diagnostics: [
58+
DiagnosticInfo(
59+
code: 0,
60+
category: "error",
61+
message: "Build failed with no result"
62+
),
63+
]
64+
)
65+
}
66+
67+
defer { tsc_free_result(cResult) }
68+
69+
let success = cResult.pointee.success != 0
70+
let configFile =
71+
cResult.pointee.config_file != nil ? String(cString: cResult.pointee.config_file) : ""
72+
let diagnostics = convertCDiagnostics(
73+
cResult.pointee.diagnostics, count: Int(cResult.pointee.diagnostic_count)
74+
)
75+
let writtenFiles = convertCWrittenFiles(
76+
cResult.pointee.written_file_paths,
77+
cResult.pointee.written_file_contents,
78+
count: Int(cResult.pointee.written_file_count)
79+
)
80+
let compiledFiles = convertCCompiledFiles(from: writtenFiles)
81+
82+
return InMemoryBuildResult(
83+
success: success,
84+
diagnostics: diagnostics,
85+
compiledFiles: compiledFiles,
86+
configFile: configFile,
87+
writtenFiles: writtenFiles
88+
)
89+
}
90+
91+
// MARK: - C String Helpers
92+
93+
func withMutableCString<T>(_ string: String, _ body: (UnsafeMutablePointer<CChar>) -> T)
94+
-> T
95+
{
96+
string.withCString { cString in
97+
let mutableCString = strdup(cString)!
98+
defer { free(mutableCString) }
99+
return body(mutableCString)
100+
}
101+
}

0 commit comments

Comments
 (0)