Skip to content

Commit

Permalink
Improve block formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
gcotelli committed May 29, 2024
1 parent b23e642 commit 20cb1f4
Showing 1 changed file with 36 additions and 9 deletions.
45 changes: 36 additions & 9 deletions source/Buoy-Development-Tools/BAStFormatter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,43 @@ BAStFormatter >> formatArrayBody: aSequenceNode [
statements isEmpty ifTrue: [ ^ self ].
statements
do: [ :statement |
self visitNode: statement.
self formatStatementCommentsFor: statement.
currentStatement := statement
self visitNode: statement.
self formatStatementCommentsFor: statement.
currentStatement := statement
]
separatedBy: [
codeStream
nextPutAll: self spacesBeforeDotInDynamicArray;
nextPut: $..
( self isLineTooLongWithNode: currentStatement )
ifTrue: [ self newLine ]
ifFalse: [ self space ]
codeStream
nextPutAll: self spacesBeforeDotInDynamicArray;
nextPut: $..
( self isLineTooLongWithNode: currentStatement )
ifTrue: [ self newLine ]
ifFalse: [ self space ]
]
]

{ #category : 'private - formatting' }
BAStFormatter >> formatBlock: aBlockNode [

| isMultiline isBodyTooLong |
isMultiline := self willBeMultiline: aBlockNode body.

codeStream nextPutAll: self spacesInsideBlocksString.

self formatBlockArgumentsFor: aBlockNode.
self formatBlockCommentFor: aBlockNode.

isBodyTooLong := self isLineTooLongWithNode: aBlockNode body.

( isMultiline or: [ isBodyTooLong ] )
ifTrue: [
self indentAround: [
( self shouldPassNewLineAfterHeadOfBlock: aBlockNode ) ifTrue: [ self newLine ].
self visitSequenceNode: aBlockNode body
]
]
ifFalse: [ self visitSequenceNode: aBlockNode body ].

( self lineUpBlockBrackets and: [ isMultiline ] )
ifTrue: [ self newLine ]
ifFalse: [ codeStream nextPutAll: self spacesInsideBlocksString ]
]

0 comments on commit 20cb1f4

Please sign in to comment.