Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't render just spaces in a line #2114

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Sources/GRPCCodeGen/Internal/Renderer/TextBasedRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ final class StringCodeWriter {
if nextWriteAppendsToLastLine && !lines.isEmpty {
let existingLine = lines.removeLast()
newLine = existingLine + line
} else if line.isEmpty {
// Skip indentation to avoid trailing whitespace on blank lines.
newLine = line
} else {
let indentation = Array(repeating: " ", count: self.indentation * level).joined()
newLine = indentation + line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ final class ClientCodeTranslatorSnippetBasedTests: XCTestCase {
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
public struct NamespaceA_ServiceA_Client: NamespaceA_ServiceA.ClientProtocol {
private let client: GRPCCore.GRPCClient

public init(wrapping client: GRPCCore.GRPCClient) {
self.client = client
}

/// Documentation for MethodA
public func methodA<R>(
request: GRPCCore.ClientRequest<NamespaceA_ServiceARequest>,
Expand Down Expand Up @@ -205,11 +205,11 @@ final class ClientCodeTranslatorSnippetBasedTests: XCTestCase {
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
public struct NamespaceA_ServiceA_Client: NamespaceA_ServiceA.ClientProtocol {
private let client: GRPCCore.GRPCClient

public init(wrapping client: GRPCCore.GRPCClient) {
self.client = client
}

/// Documentation for MethodA
public func methodA<R>(
request: GRPCCore.StreamingClientRequest<NamespaceA_ServiceARequest>,
Expand Down Expand Up @@ -308,11 +308,11 @@ final class ClientCodeTranslatorSnippetBasedTests: XCTestCase {
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
public struct NamespaceA_ServiceA_Client: NamespaceA_ServiceA.ClientProtocol {
private let client: GRPCCore.GRPCClient

public init(wrapping client: GRPCCore.GRPCClient) {
self.client = client
}

/// Documentation for MethodA
public func methodA<R>(
request: GRPCCore.ClientRequest<NamespaceA_ServiceARequest>,
Expand Down Expand Up @@ -409,11 +409,11 @@ final class ClientCodeTranslatorSnippetBasedTests: XCTestCase {
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
public struct NamespaceA_ServiceA_Client: NamespaceA_ServiceA.ClientProtocol {
private let client: GRPCCore.GRPCClient

public init(wrapping client: GRPCCore.GRPCClient) {
self.client = client
}

/// Documentation for MethodA
public func methodA<R>(
request: GRPCCore.StreamingClientRequest<NamespaceA_ServiceARequest>,
Expand Down Expand Up @@ -477,7 +477,7 @@ final class ClientCodeTranslatorSnippetBasedTests: XCTestCase {
options: GRPCCore.CallOptions,
_ body: @Sendable @escaping (GRPCCore.ClientResponse<NamespaceA_ServiceAResponse>) async throws -> R
) async throws -> R where R: Sendable

/// Documentation for MethodB
func methodB<R>(
request: GRPCCore.ClientRequest<NamespaceA_ServiceARequest>,
Expand All @@ -504,7 +504,7 @@ final class ClientCodeTranslatorSnippetBasedTests: XCTestCase {
body
)
}

package func methodB<R>(
request: GRPCCore.ClientRequest<NamespaceA_ServiceARequest>,
options: GRPCCore.CallOptions = .defaults,
Expand Down Expand Up @@ -540,7 +540,7 @@ final class ClientCodeTranslatorSnippetBasedTests: XCTestCase {
handleResponse
)
}

/// Documentation for MethodB
package func methodB<Result>(
_ message: NamespaceA_ServiceARequest,
Expand All @@ -563,11 +563,11 @@ final class ClientCodeTranslatorSnippetBasedTests: XCTestCase {
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
package struct NamespaceA_ServiceA_Client: NamespaceA_ServiceA.ClientProtocol {
private let client: GRPCCore.GRPCClient

package init(wrapping client: GRPCCore.GRPCClient) {
self.client = client
}

/// Documentation for MethodA
package func methodA<R>(
request: GRPCCore.StreamingClientRequest<NamespaceA_ServiceARequest>,
Expand All @@ -587,7 +587,7 @@ final class ClientCodeTranslatorSnippetBasedTests: XCTestCase {
handler: body
)
}

/// Documentation for MethodB
package func methodB<R>(
request: GRPCCore.ClientRequest<NamespaceA_ServiceARequest>,
Expand Down Expand Up @@ -688,11 +688,11 @@ final class ClientCodeTranslatorSnippetBasedTests: XCTestCase {
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
internal struct ServiceA_Client: ServiceA.ClientProtocol {
private let client: GRPCCore.GRPCClient

internal init(wrapping client: GRPCCore.GRPCClient) {
self.client = client
}

/// Documentation for MethodA
internal func methodA<R>(
request: GRPCCore.ClientRequest<ServiceARequest>,
Expand Down Expand Up @@ -758,7 +758,7 @@ final class ClientCodeTranslatorSnippetBasedTests: XCTestCase {
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
public struct NamespaceA_ServiceA_Client: NamespaceA_ServiceA.ClientProtocol {
private let client: GRPCCore.GRPCClient

public init(wrapping client: GRPCCore.GRPCClient) {
self.client = client
}
Expand All @@ -780,7 +780,7 @@ final class ClientCodeTranslatorSnippetBasedTests: XCTestCase {
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
public struct ServiceB_Client: ServiceB.ClientProtocol {
private let client: GRPCCore.GRPCClient

public init(wrapping client: GRPCCore.GRPCClient) {
self.client = client
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ final class ServerCodeTranslatorSnippetBasedTests: XCTestCase {
request: GRPCCore.StreamingServerRequest<NamespaceA_ServiceARequest>,
context: GRPCCore.ServerContext
) async throws -> GRPCCore.StreamingServerResponse<NamespaceA_ServiceAResponse>

/// Documentation for outputStreamingMethod
func outputStreaming(
request: GRPCCore.StreamingServerRequest<NamespaceA_ServiceARequest>,
Expand Down Expand Up @@ -452,7 +452,7 @@ final class ServerCodeTranslatorSnippetBasedTests: XCTestCase {
request: GRPCCore.StreamingServerRequest<NamespaceA_ServiceARequest>,
context: GRPCCore.ServerContext
) async throws -> GRPCCore.ServerResponse<NamespaceA_ServiceAResponse>

/// Documentation for outputStreamingMethod
func outputStreaming(
request: GRPCCore.ServerRequest<NamespaceA_ServiceARequest>,
Expand All @@ -472,7 +472,7 @@ final class ServerCodeTranslatorSnippetBasedTests: XCTestCase {
)
return GRPCCore.StreamingServerResponse(single: response)
}

internal func outputStreaming(
request: GRPCCore.StreamingServerRequest<NamespaceA_ServiceARequest>,
context: GRPCCore.ServerContext
Expand Down
Loading