Skip to content

Commit f538c97

Browse files
committed
chore: format all swift files
Signed-off-by: peefy <[email protected]>
1 parent db74a21 commit f538c97

File tree

4 files changed

+187
-148
lines changed

4 files changed

+187
-148
lines changed

swift/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ all: build
66

77
.PHONY: build
88
build: cargo
9-
swift build
9+
swift build -c release
10+
11+
.PHONY: fmt
12+
fmt:
13+
swift format
1014

1115
.PHONY: cargo
1216
cargo:

swift/Sources/KclLib/API.swift

Lines changed: 144 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,149 @@
1+
import CKclLib
12
import Foundation
23
import SwiftProtobuf
3-
import CKclLib
44

55
public class API: Service {
6-
private static let ERROR_PREFIX = "ERROR:"
7-
8-
public init() {}
9-
10-
// Parses a single KCL file and returns its Abstract Syntax Tree (AST) as a JSON string.
11-
public func parseFile(_ args: ParseFile_Args) throws -> ParseFile_Result {
12-
return try ParseFile_Result(serializedBytes: callNative(name: "KclvmService.ParseFile", args: try args.serializedBytes()))
13-
}
14-
15-
// Parses a KCL program and returns the Abstract Syntax Tree (AST) in JSON format.
16-
public func parseProgram(_ args: ParseProgram_Args) throws -> ParseProgram_Result {
17-
return try ParseProgram_Result(serializedBytes: callNative(name: "KclvmService.ParseProgram", args: try args.serializedBytes()))
18-
}
19-
20-
// Loads a KCL package and retrieves AST, symbol, type, and definition information.
21-
public func loadPackage(_ args: LoadPackage_Args) throws -> LoadPackage_Result {
22-
return try LoadPackage_Result(serializedBytes: callNative(name: "KclvmService.LoadPackage", args: try args.serializedBytes()))
23-
}
24-
25-
// Executes a KCL file with provided arguments.
26-
public func execProgram(_ args: ExecProgram_Args) throws -> ExecProgram_Result {
27-
return try ExecProgram_Result(serializedBytes: callNative(name: "KclvmService.ExecProgram", args: try args.serializedBytes()))
28-
}
29-
30-
// Overrides specified elements in a KCL file according to given arguments.
31-
public func overrideFile(_ args: OverrideFile_Args) throws -> OverrideFile_Result {
32-
return try OverrideFile_Result(serializedBytes: callNative(name: "KclvmService.OverrideFile", args: try args.serializedBytes()))
33-
}
34-
35-
// Lists all variables declared in a KCL file.
36-
public func listVariables(_ args: ListVariables_Args) throws -> ListVariables_Result {
37-
return try ListVariables_Result(serializedBytes: callNative(name: "KclvmService.ListVariables", args: try args.serializedBytes()))
38-
}
39-
40-
// Lists all options defined in a KCL program.
41-
public func listOptions(_ args: ParseProgram_Args) throws -> ListOptions_Result {
42-
return try ListOptions_Result(serializedBytes: callNative(name: "KclvmService.ListOptions", args: try args.serializedBytes()))
43-
}
44-
45-
// Retrieves the full schema type mapping for a KCL program.
46-
public func getSchemaTypeMapping(_ args: GetSchemaTypeMapping_Args) throws -> GetSchemaTypeMapping_Result {
47-
return try GetSchemaTypeMapping_Result(serializedBytes: callNative(name: "KclvmService.GetSchemaTypeMapping", args: try args.serializedBytes()))
48-
}
49-
50-
// Formats source code according to KCL style guidelines.
51-
public func formatCode(_ args: FormatCode_Args) throws -> FormatCode_Result {
52-
return try FormatCode_Result(serializedBytes: callNative(name: "KclvmService.FormatCode", args: try args.serializedBytes()))
53-
}
54-
55-
// Formats KCL files or directories to conform to style guidelines.
56-
public func formatPath(_ args: FormatPath_Args) throws -> FormatPath_Result {
57-
return try FormatPath_Result(serializedBytes: callNative(name: "KclvmService.FormatPath", args: try args.serializedBytes()))
58-
}
59-
60-
// Runs linting checks on KCL files and reports errors and warnings.
61-
public func lintPath(_ args: LintPath_Args) throws -> LintPath_Result {
62-
return try LintPath_Result(serializedBytes: callNative(name: "KclvmService.LintPath", args: try args.serializedBytes()))
63-
}
64-
65-
// Validates a data string against a schema defined in a KCL code string.
66-
public func validateCode(_ args: ValidateCode_Args) throws -> ValidateCode_Result {
67-
return try ValidateCode_Result(serializedBytes: callNative(name: "KclvmService.ValidateCode", args: try args.serializedBytes()))
68-
}
69-
70-
// Builds configuration from settings files.
71-
public func loadSettingsFiles(_ args: LoadSettingsFiles_Args) throws -> LoadSettingsFiles_Result {
72-
return try LoadSettingsFiles_Result(serializedBytes: callNative(name: "KclvmService.LoadSettingsFiles", args: try args.serializedBytes()))
73-
}
74-
75-
// Renames symbols across files within a KCL package.
76-
public func rename(_ args: Rename_Args) throws -> Rename_Result {
77-
return try Rename_Result(serializedBytes: callNative(name: "KclvmService.Rename", args: try args.serializedBytes()))
78-
}
79-
80-
// Renames symbols in source code without modifying files directly.
81-
public func renameCode(_ args: RenameCode_Args) throws -> RenameCode_Result {
82-
return try RenameCode_Result(serializedBytes: callNative(name: "KclvmService.RenameCode", args: try args.serializedBytes()))
83-
}
84-
85-
// Executes tests on KCL packages using specified test arguments.
86-
public func test(_ args: Test_Args) throws -> Test_Result {
87-
return try Test_Result(serializedBytes: callNative(name: "KclvmService.Test", args: try args.serializedBytes()))
88-
}
89-
90-
// Updates dependencies for a KCL project based on defined specifications.
91-
public func updateDependencies(_ args: UpdateDependencies_Args) throws -> UpdateDependencies_Result {
92-
return try UpdateDependencies_Result(serializedBytes: callNative(name: "KclvmService.UpdateDependencies", args: try args.serializedBytes()))
93-
}
94-
95-
// Retrieves version information about the KCL service.
96-
public func getVersion(_ args: GetVersion_Args) throws -> GetVersion_Result {
97-
return try GetVersion_Result(serializedBytes: callNative(name: "KclvmService.GetVersion", args: try args.serializedBytes()))
98-
}
99-
100-
private func callNative(name: String, args: Data) -> Data {
101-
// Convert name to byte array
102-
let nameBytes = [UInt8](name.utf8)
103-
var resultBuf = [UInt8](repeating: 0, count: 2048 * 2048)
104-
let resultLength = CKclLib.callNative(nameBytes, UInt(nameBytes.count), [UInt8](args), UInt(args.count), &resultBuf)
105-
let result = Data(bytes: resultBuf, count: Int(resultLength))
106-
let resultString = String(bytes: result, encoding: .utf8) ?? ""
107-
if resultString.isEmpty || !resultString.hasPrefix(API.ERROR_PREFIX) {
108-
return result
109-
}
110-
fatalError(String(resultString.dropFirst(API.ERROR_PREFIX.count)))
111-
}
6+
private static let ERROR_PREFIX = "ERROR:"
7+
8+
public init() {}
9+
10+
// Parses a single KCL file and returns its Abstract Syntax Tree (AST) as a JSON string.
11+
public func parseFile(_ args: ParseFile_Args) throws -> ParseFile_Result {
12+
return try ParseFile_Result(
13+
serializedBytes: callNative(name: "KclvmService.ParseFile", args: try args.serializedBytes()))
14+
}
15+
16+
// Parses a KCL program and returns the Abstract Syntax Tree (AST) in JSON format.
17+
public func parseProgram(_ args: ParseProgram_Args) throws -> ParseProgram_Result {
18+
return try ParseProgram_Result(
19+
serializedBytes: callNative(
20+
name: "KclvmService.ParseProgram", args: try args.serializedBytes()))
21+
}
22+
23+
// Loads a KCL package and retrieves AST, symbol, type, and definition information.
24+
public func loadPackage(_ args: LoadPackage_Args) throws -> LoadPackage_Result {
25+
return try LoadPackage_Result(
26+
serializedBytes: callNative(
27+
name: "KclvmService.LoadPackage", args: try args.serializedBytes()))
28+
}
29+
30+
// Executes a KCL file with provided arguments.
31+
public func execProgram(_ args: ExecProgram_Args) throws -> ExecProgram_Result {
32+
return try ExecProgram_Result(
33+
serializedBytes: callNative(
34+
name: "KclvmService.ExecProgram", args: try args.serializedBytes()))
35+
}
36+
37+
// Overrides specified elements in a KCL file according to given arguments.
38+
public func overrideFile(_ args: OverrideFile_Args) throws -> OverrideFile_Result {
39+
return try OverrideFile_Result(
40+
serializedBytes: callNative(
41+
name: "KclvmService.OverrideFile", args: try args.serializedBytes()))
42+
}
43+
44+
// Lists all variables declared in a KCL file.
45+
public func listVariables(_ args: ListVariables_Args) throws -> ListVariables_Result {
46+
return try ListVariables_Result(
47+
serializedBytes: callNative(
48+
name: "KclvmService.ListVariables", args: try args.serializedBytes()))
49+
}
50+
51+
// Lists all options defined in a KCL program.
52+
public func listOptions(_ args: ParseProgram_Args) throws -> ListOptions_Result {
53+
return try ListOptions_Result(
54+
serializedBytes: callNative(
55+
name: "KclvmService.ListOptions", args: try args.serializedBytes()))
56+
}
57+
58+
// Retrieves the full schema type mapping for a KCL program.
59+
public func getSchemaTypeMapping(_ args: GetSchemaTypeMapping_Args) throws
60+
-> GetSchemaTypeMapping_Result
61+
{
62+
return try GetSchemaTypeMapping_Result(
63+
serializedBytes: callNative(
64+
name: "KclvmService.GetSchemaTypeMapping", args: try args.serializedBytes()))
65+
}
66+
67+
// Formats source code according to KCL style guidelines.
68+
public func formatCode(_ args: FormatCode_Args) throws -> FormatCode_Result {
69+
return try FormatCode_Result(
70+
serializedBytes: callNative(name: "KclvmService.FormatCode", args: try args.serializedBytes())
71+
)
72+
}
73+
74+
// Formats KCL files or directories to conform to style guidelines.
75+
public func formatPath(_ args: FormatPath_Args) throws -> FormatPath_Result {
76+
return try FormatPath_Result(
77+
serializedBytes: callNative(name: "KclvmService.FormatPath", args: try args.serializedBytes())
78+
)
79+
}
80+
81+
// Runs linting checks on KCL files and reports errors and warnings.
82+
public func lintPath(_ args: LintPath_Args) throws -> LintPath_Result {
83+
return try LintPath_Result(
84+
serializedBytes: callNative(name: "KclvmService.LintPath", args: try args.serializedBytes()))
85+
}
86+
87+
// Validates a data string against a schema defined in a KCL code string.
88+
public func validateCode(_ args: ValidateCode_Args) throws -> ValidateCode_Result {
89+
return try ValidateCode_Result(
90+
serializedBytes: callNative(
91+
name: "KclvmService.ValidateCode", args: try args.serializedBytes()))
92+
}
93+
94+
// Builds configuration from settings files.
95+
public func loadSettingsFiles(_ args: LoadSettingsFiles_Args) throws -> LoadSettingsFiles_Result {
96+
return try LoadSettingsFiles_Result(
97+
serializedBytes: callNative(
98+
name: "KclvmService.LoadSettingsFiles", args: try args.serializedBytes()))
99+
}
100+
101+
// Renames symbols across files within a KCL package.
102+
public func rename(_ args: Rename_Args) throws -> Rename_Result {
103+
return try Rename_Result(
104+
serializedBytes: callNative(name: "KclvmService.Rename", args: try args.serializedBytes()))
105+
}
106+
107+
// Renames symbols in source code without modifying files directly.
108+
public func renameCode(_ args: RenameCode_Args) throws -> RenameCode_Result {
109+
return try RenameCode_Result(
110+
serializedBytes: callNative(name: "KclvmService.RenameCode", args: try args.serializedBytes())
111+
)
112+
}
113+
114+
// Executes tests on KCL packages using specified test arguments.
115+
public func test(_ args: Test_Args) throws -> Test_Result {
116+
return try Test_Result(
117+
serializedBytes: callNative(name: "KclvmService.Test", args: try args.serializedBytes()))
118+
}
119+
120+
// Updates dependencies for a KCL project based on defined specifications.
121+
public func updateDependencies(_ args: UpdateDependencies_Args) throws
122+
-> UpdateDependencies_Result
123+
{
124+
return try UpdateDependencies_Result(
125+
serializedBytes: callNative(
126+
name: "KclvmService.UpdateDependencies", args: try args.serializedBytes()))
127+
}
128+
129+
// Retrieves version information about the KCL service.
130+
public func getVersion(_ args: GetVersion_Args) throws -> GetVersion_Result {
131+
return try GetVersion_Result(
132+
serializedBytes: callNative(name: "KclvmService.GetVersion", args: try args.serializedBytes())
133+
)
134+
}
135+
136+
private func callNative(name: String, args: Data) -> Data {
137+
// Convert name to byte array
138+
let nameBytes = [UInt8](name.utf8)
139+
var resultBuf = [UInt8](repeating: 0, count: 2048 * 2048)
140+
let resultLength = CKclLib.callNative(
141+
nameBytes, UInt(nameBytes.count), [UInt8](args), UInt(args.count), &resultBuf)
142+
let result = Data(bytes: resultBuf, count: Int(resultLength))
143+
let resultString = String(bytes: result, encoding: .utf8) ?? ""
144+
if resultString.isEmpty || !resultString.hasPrefix(API.ERROR_PREFIX) {
145+
return result
146+
}
147+
fatalError(String(resultString.dropFirst(API.ERROR_PREFIX.count)))
148+
}
112149
}

swift/Sources/KclLib/Service.swift

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,57 @@ import Foundation
22

33
// Define the protocol for services that manage various operations on KCL programs.
44
public protocol Service {
5-
// Parses a single KCL file and returns its Abstract Syntax Tree (AST) as a JSON string.
6-
func parseFile(_ args: ParseFile_Args) throws -> ParseFile_Result
5+
// Parses a single KCL file and returns its Abstract Syntax Tree (AST) as a JSON string.
6+
func parseFile(_ args: ParseFile_Args) throws -> ParseFile_Result
77

8-
// Parses a KCL program and returns the Abstract Syntax Tree (AST) in JSON format.
9-
func parseProgram(_ args: ParseProgram_Args) throws -> ParseProgram_Result
8+
// Parses a KCL program and returns the Abstract Syntax Tree (AST) in JSON format.
9+
func parseProgram(_ args: ParseProgram_Args) throws -> ParseProgram_Result
1010

11-
// Loads a KCL package and retrieves AST, symbol, type, and definition information.
12-
func loadPackage(_ args: LoadPackage_Args) throws -> LoadPackage_Result
11+
// Loads a KCL package and retrieves AST, symbol, type, and definition information.
12+
func loadPackage(_ args: LoadPackage_Args) throws -> LoadPackage_Result
1313

14-
// Executes a KCL file with provided arguments.
15-
func execProgram(_ args: ExecProgram_Args) throws -> ExecProgram_Result
14+
// Executes a KCL file with provided arguments.
15+
func execProgram(_ args: ExecProgram_Args) throws -> ExecProgram_Result
1616

17-
// Overrides specified elements in a KCL file according to given arguments.
18-
func overrideFile(_ args: OverrideFile_Args) throws -> OverrideFile_Result
17+
// Overrides specified elements in a KCL file according to given arguments.
18+
func overrideFile(_ args: OverrideFile_Args) throws -> OverrideFile_Result
1919

20-
// Lists all variables declared in a KCL file.
21-
func listVariables(_ args: ListVariables_Args) throws -> ListVariables_Result
20+
// Lists all variables declared in a KCL file.
21+
func listVariables(_ args: ListVariables_Args) throws -> ListVariables_Result
2222

23-
// Lists all options defined in a KCL program.
24-
func listOptions(_ args: ParseProgram_Args) throws -> ListOptions_Result
23+
// Lists all options defined in a KCL program.
24+
func listOptions(_ args: ParseProgram_Args) throws -> ListOptions_Result
2525

26-
// Retrieves the full schema type mapping for a KCL program.
27-
func getSchemaTypeMapping(_ args: GetSchemaTypeMapping_Args) throws -> GetSchemaTypeMapping_Result
26+
// Retrieves the full schema type mapping for a KCL program.
27+
func getSchemaTypeMapping(_ args: GetSchemaTypeMapping_Args) throws -> GetSchemaTypeMapping_Result
2828

29-
// Formats source code according to KCL style guidelines.
30-
func formatCode(_ args: FormatCode_Args) throws -> FormatCode_Result
29+
// Formats source code according to KCL style guidelines.
30+
func formatCode(_ args: FormatCode_Args) throws -> FormatCode_Result
3131

32-
// Formats KCL files or directories to conform to style guidelines.
33-
func formatPath(_ args: FormatPath_Args) throws -> FormatPath_Result
32+
// Formats KCL files or directories to conform to style guidelines.
33+
func formatPath(_ args: FormatPath_Args) throws -> FormatPath_Result
3434

35-
// Runs linting checks on KCL files and reports errors and warnings.
36-
func lintPath(_ args: LintPath_Args) throws -> LintPath_Result
35+
// Runs linting checks on KCL files and reports errors and warnings.
36+
func lintPath(_ args: LintPath_Args) throws -> LintPath_Result
3737

38-
// Validates a data string against a schema defined in a KCL code string.
39-
func validateCode(_ args: ValidateCode_Args) throws -> ValidateCode_Result
38+
// Validates a data string against a schema defined in a KCL code string.
39+
func validateCode(_ args: ValidateCode_Args) throws -> ValidateCode_Result
4040

41-
// Builds configuration from settings files.
42-
func loadSettingsFiles(_ args: LoadSettingsFiles_Args) throws -> LoadSettingsFiles_Result
41+
// Builds configuration from settings files.
42+
func loadSettingsFiles(_ args: LoadSettingsFiles_Args) throws -> LoadSettingsFiles_Result
4343

44-
// Renames symbols across files within a KCL package.
45-
func rename(_ args: Rename_Args) throws -> Rename_Result
44+
// Renames symbols across files within a KCL package.
45+
func rename(_ args: Rename_Args) throws -> Rename_Result
4646

47-
// Renames symbols in source code without modifying files directly.
48-
func renameCode(_ args: RenameCode_Args) throws -> RenameCode_Result
47+
// Renames symbols in source code without modifying files directly.
48+
func renameCode(_ args: RenameCode_Args) throws -> RenameCode_Result
4949

50-
// Executes tests on KCL packages using specified test arguments.
51-
func test(_ args: Test_Args) throws -> Test_Result
50+
// Executes tests on KCL packages using specified test arguments.
51+
func test(_ args: Test_Args) throws -> Test_Result
5252

53-
// Updates dependencies for a KCL project based on defined specifications.
54-
func updateDependencies(_ args: UpdateDependencies_Args) throws -> UpdateDependencies_Result
53+
// Updates dependencies for a KCL project based on defined specifications.
54+
func updateDependencies(_ args: UpdateDependencies_Args) throws -> UpdateDependencies_Result
5555

56-
// Retrieves version information about the KCL service.
57-
func getVersion(_ args: GetVersion_Args) throws -> GetVersion_Result
56+
// Retrieves version information about the KCL service.
57+
func getVersion(_ args: GetVersion_Args) throws -> GetVersion_Result
5858
}

wasm/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@
1818
},
1919
"license": "Apache-2.0",
2020
"dependencies": {
21-
"wasi-js": "^1.7.3"
21+
"wasi-js": "^1.7.3",
22+
"prettier": "^2.8.4"
2223
},
23-
"bundledDependencies": [
24-
"wasi-js"
25-
],
2624
"devDependencies": {
2725
"@types/node": "^20.11.0",
2826
"prettier": "^2.8.4",

0 commit comments

Comments
 (0)