Skip to content

Commit

Permalink
Progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjprescott committed Dec 10, 2024
1 parent 818d841 commit 0b07b0f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/swift/SwiftAPIViewCore/Sources/APIViewManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// The MIT License (MIT)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the ""Software""), to
// of this software and associated documenxtation files (the ""Software""), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
Expand Down
10 changes: 7 additions & 3 deletions src/swift/SwiftAPIViewCore/Sources/Models/APIViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ class APIViewModel: Tokenizable, Encodable {

/// Returns the text-based representation of all lines
var text: String {
return reviewLines.map { $0.text }.joined()
return reviewLines.map { line in
let lineText = line.text()
return lineText
}.joined()
}

// MARK: Initializers
Expand Down Expand Up @@ -312,7 +315,8 @@ class APIViewModel: Tokenizable, Encodable {
}
}

func indent(_ indentedLines: () -> Void) {
/// Wraps code in indentattion
func indent(_ indentedCode: () -> Void) {
// ensure no trailing space at the end of the line
let lastToken = self.currentLine.tokens.last
lastToken?.hasSuffixSpace = false
Expand All @@ -327,7 +331,7 @@ class APIViewModel: Tokenizable, Encodable {
self.currentLine = ReviewLine()

// handle the indented bodies
indentedLines()
indentedCode()

// handle the de-indent logic
guard let currentParent = self.currentParent else {
Expand Down
16 changes: 12 additions & 4 deletions src/swift/SwiftAPIViewCore/Sources/Models/ReviewLine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,18 @@ class ReviewLine: Tokenizable, Encodable {
var relatedToLine: String?

/// Returns the text-based representation of all tokens
var text: String {
var tokenText = tokens.map { $0.text }
tokenText.append("\n")
return tokenText.joined()
func text(indent: Int = 0) -> String {
let indentString = String(repeating: " ", count: indent)
var tokenText = ""
for token in tokens {
tokenText += token.text
}
let childrenText = self.children?.map { $0.text(indent: indent + 2) }.joined(separator: "\n")
if let childrenText {
return "\(indentString)\(tokenText)\n\(childrenText)"
} else {
return "\(indentString)\(tokenText)"
}
}

// MARK: Codable
Expand Down

0 comments on commit 0b07b0f

Please sign in to comment.