Incorporating the Code Formatter in Envy QA into VA9

42 views
Skip to first unread message

Steven LaFavor

unread,
Aug 7, 2019, 4:34:38 PM8/7/19
to VA Smalltalk
VA 9.1

One of the things that I have noticed on larger (and smaller) Smalltalk development teams is that everyone has their own way of how they like code formatted.  And since the envy repository treats it as a string, even adding a space will trigger the need to "save" a method.   And over the life of a project, with developers coming and going, how the code looks/formats can go a great way in is its readability.

With the Envy QA apps now as part of the VA standard, I made a slight modification to some internal coding so that it doesn't matter how anyone saved their code in the repository.  You can see it as you would like it formatted without having to resave it.

In CompiledMethod>>sourceString

sourceString
"Return the source code for the receiver."

| source |

##PR = ##'1PQCXCI'.
self isDoit
ifTrue: [source := (self at: self size) value]
ifFalse: [
| residentClass |
self
canSee: (
self isPrivate
ifTrue: [#readPrivateSource]
ifFalse: [#readPublicSource])
ifNot: [^nil].
residentClass := self methodClass residentClass.
source := (residentClass notNil and: [residentClass classHasSourceFor: self])
ifTrue: [residentClass classSuppliedSourceFor: self] "Ask the class for its source"
ifFalse: [
EmLibrary cache
methodSourceAt: self filePointer
decompress: true]. "No class-supplied source, get it from the library"
(Smalltalk classAt: #CfFormatter) notNil
ifTrue: [
source := CfFormatter new
formatText: source
class: residentClass
width: nil]].
^EmImageSupport sourceFilter filter: source
  
I throw this out there for any one to use, or tell me that I've missed something, or that they know of a less "intrusive" way to do this.......

Any thoughts?   I've found it to be incredibly helpful to set up my CfFormatter settings the way I like it, and then be able to peruse code in a format that makes it easier for me to read and understand.....

Reply all
Reply to author
Forward
0 new messages