Skip to content

Commit e7a7887

Browse files
committed
Include language in RichValue.asCode
1 parent ac74c44 commit e7a7887

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

Sources/D2Commands/File/ToFileCommand.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class ToFileCommand: Command {
2929
return
3030
}
3131

32-
guard let data = (content.asText ?? content.asCode ?? "").data(using: .utf8) else {
32+
guard let data = (content.asText ?? content.asCode?.code ?? "").data(using: .utf8) else {
3333
await output.append(errorText: "Could not encode file data as UTF-8")
3434
return
3535
}

Sources/D2Commands/Output/RichValue.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public enum RichValue: Addable, Sendable {
3333
public var asText: String? {
3434
extract { if case let .text(text) = $0 { text } else { nil } }.nilIfEmpty?.joined(separator: " ")
3535
}
36-
public var asCode: String? {
37-
extract { if case let .code(code, language: _) = $0 { code } else { nil } }.first
36+
public var asCode: (code: String, language: String?)? {
37+
extract { if case let .code(code, language: language) = $0 { (code: code, language: language) } else { nil } }.first
3838
}
3939
public var asEmbed: Embed? {
4040
extract { if case let .embed(embed) = $0 { embed } else { nil } }.first

Sources/D2Commands/Programming/PrologCommand.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class PrologCommand: Command {
1717
public init() {
1818
subcommands = [
1919
"load": { [unowned self] input, output in
20-
guard let rawProgram = input.asCode ?? input.asText else {
20+
guard let rawProgram = input.asCode?.code ?? input.asText else {
2121
await output.append("Please enter a Prolog program (a collection of rules)!")
2222
return
2323
}
@@ -32,7 +32,7 @@ public class PrologCommand: Command {
3232
await output.append("Please load a program first!")
3333
return
3434
}
35-
guard let rawGoal = input.asCode ?? input.asText else {
35+
guard let rawGoal = input.asCode?.code ?? input.asText else {
3636
await output.append("Please enter a Prolog goal (a collection of provable statements)!")
3737
return
3838
}

Sources/D2Commands/Programming/ReindentCommand.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@ public class ReindentCommand: Command {
7070
return
7171
}
7272

73-
await output.append(.code(spec.reindent(code: code), language: nil))
73+
await output.append(.code(spec.reindent(code: code.code), language: code.language))
7474
}
7575
}

Sources/D2Commands/StringCommand.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ extension StringCommand {
1010
public var inputValueType: RichValueType { .text }
1111

1212
public func invoke(with input: RichValue, output: any CommandOutput, context: CommandContext) async {
13-
await invoke(with: input.asText ?? input.asCode ?? "", output: output, context: context)
13+
await invoke(with: input.asText ?? input.asCode?.code ?? "", output: output, context: context)
1414
}
1515
}

0 commit comments

Comments
 (0)