swift-syntax icon indicating copy to clipboard operation
swift-syntax copied to clipboard

Add an 'indented' method to SyntaxProtocol

Open j-f1 opened this issue 1 year ago • 1 comments

This method allows for easily indenting a node tree without needing to manually find where to place the new trivia.

I also chose not to implement a version that automatically detects an amount to indent by using BasicFormat.inferIndentation since that would probably produce better results if called higher up in the tree, and the user of this API can more easily cache that calculated indentation amount and pass it to indent multiple times as needed.

j-f1 avatar Sep 07 '24 21:09 j-f1

@swift-ci please test

j-f1 avatar Sep 07 '24 21:09 j-f1

@swift-ci please test

j-f1 avatar Oct 26 '24 22:10 j-f1

@swift-ci please test

j-f1 avatar Oct 26 '24 23:10 j-f1

Why might the indented(by:) method not be able to be found? Things work fine for me locally.

/Users/ec2-user/jenkins/workspace/swift-syntax-PR-macOS/branch-main/swift-syntax/Sources/SwiftSyntaxBuilder/Syntax+StringInterpolation.swift:85:27: error: value of type 'Node' has no member 'indented'
      indentedNode = node.indented(by: lastIndentation)
                     ~~~~ ^~~~~~~~

j-f1 avatar Oct 26 '24 23:10 j-f1

A Node is not a kind of Syntax, it’s meta-information about the declaration of a syntax node the builder will spit out. You may want to revert your change in that file.

CodaFi avatar Oct 27 '24 04:10 CodaFi

It’s a local generic type (which must be shadowing the real Node type): func appendInterpolation<Node: SyntaxProtocol>.

j-f1 avatar Oct 28 '24 00:10 j-f1

Why might the indented(by:) method not be able to be found? Things work fine for me locally.

/Users/ec2-user/jenkins/workspace/swift-syntax-PR-macOS/branch-main/swift-syntax/Sources/SwiftSyntaxBuilder/Syntax+StringInterpolation.swift:85:27: error: value of type 'Node' has no member 'indented'
      indentedNode = node.indented(by: lastIndentation)
                     ~~~~ ^~~~~~~~

You need to add Indenter.swift to CMakeLists.txt so we can find it when building swift-syntax using CMake for the compiler.

ahoppen avatar Oct 28 '24 23:10 ahoppen

@swift-ci please test

j-f1 avatar Oct 29 '24 00:10 j-f1

@swift-ci please test

j-f1 avatar Oct 29 '24 00:10 j-f1

@swift-ci please test

j-f1 avatar Oct 29 '24 15:10 j-f1

@swift-ci please test

j-f1 avatar Oct 29 '24 20:10 j-f1

@swift-ci please test

j-f1 avatar Oct 29 '24 22:10 j-f1

@swift-ci please test

j-f1 avatar Oct 30 '24 16:10 j-f1

@swift-ci please test Windows

j-f1 avatar Oct 30 '24 16:10 j-f1