-
Notifications
You must be signed in to change notification settings - Fork 441
Move Format
from SwiftSyntaxBuilder into a separate module
#830
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
Conversation
import SwiftSyntax | ||
import SwiftSyntaxBuilder | ||
|
||
/// SwiftSyntaxBuilder sources to be generated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// SwiftSyntaxBuilder sources to be generated | |
/// SwiftBasicFormat sources to be generated |
] | ||
|
||
@main | ||
struct GenerateSwiftSyntaxBuilder: ParsableCommand { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
struct GenerateSwiftSyntaxBuilder: ParsableCommand { | |
struct GenerateSwiftBasicFormat: ParsableCommand { |
attributes: nil | ||
) | ||
|
||
for (sourceFile, name) in sourceTemplates { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we could move all of this logic from main
into a function taking the generation path/url and a [(SourceFile, String)]
and share it with generate-swiftsyntaxbuilder
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I wanted to do that but forgot about it while I was working on this PR. Moved it to Utils
now. Thanks!
Format
from SwiftSyntaxBuilder into a separate packageFormat
from SwiftSyntaxBuilder into a separate module
b0a1e40
to
86c555c
Compare
@swift-ci Please test |
var result = syntax | ||
let leadingTrivia = result.leadingTrivia ?? [] | ||
if !leadingTrivia.isEmpty { | ||
result = result.withLeadingTrivia(leadingTrivia.addingSpacingAfterNewlinesIfNeeded()) | ||
} | ||
return result | ||
} | ||
func format(syntax: DeclNameArgumentSyntax) -> DeclNameArgumentSyntax { | ||
public func format(syntax: DeclNameArgumentSyntax) -> DeclNameArgumentSyntax { | ||
var result = syntax |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is so repetitive. Can we not put it into an extension of SyntaxProtocol
somehow instead of stamping out a hundred copies?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could definitely be something we can investigate in a follow-up PR.
build-script.py
Outdated
env = dict(os.environ) | ||
env["SWIFT_BUILD_SCRIPT_ENVIRONMENT"] = "1" | ||
# Tell other projects in the unified build to use local dependencies | ||
env["SWIFT_SYNTAX_PARSER_LIB_SEARCH_PATH"] = \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use SwiftParser
now for the code generation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by using SwiftParser
for code generation? We are using SwiftSyntaxBuilder
and I don’t see a reason why SwiftSyntaxBuilder
shouldn’t be able to use SwiftParser
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should have been more specific: can we remove the env["SWIFT_SYNTAX_PARSER_LIB_SEARCH_PATH"]
bit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, good catch. We can absolutely do that because CodeGeneration
doesn’t depend on neither the old nor the new parser.
This way we can use `Format` to format Fix-Its in the parser Share generate command between generate-swiftbasicformat and generate-swiftsyntaxbuilder
5ab399a
to
9965cbb
Compare
@swift-ci Please test |
This way we can use
Format
to determine whether spaces should be inserted after tokens when creating Fix-Its in the parser.