Page 1 of 1

Refactoring Support for the LC Script Editor

Posted: Wed Mar 20, 2019 6:38 pm
by mwieder
Announcing revRefactor, now uploaded to LiveCodeShare and attached here.

[Edit: the plugin now lives at https://github.com/mwieder/revRefactor]

Script Editor Refactor Plugin
Brings refactoring support to the LiveCode Script Editor.
Place the plugin into your user Plugins folder.
After launching the script editor there will be a new Refactoring menuItem in the Edit menu.
The Refactoring menuItem will also appear in the contextual menu of the Script Editor.
The Refactoring menu is inspired by the JetBrains refactoring support in RubyMine, etc.

Rename Handler
Allows you to rename in just the current script or all scripts in the stack.

Rename Variable
Both Rename Handler and Rename Variable change all uses of the object.

Convert Literal To Constant
Creates a constant for the selected literal value.
For instance, converts the string literal "hello" to
constant kHello = "hello"
and changes all references of "hello" to use kHello, i.e.,
put kHello into tVariable
instead of
put "hello" into tVariable

Change Signature
Change the parameter list for a command or function.
For instance, change "myCommand pKey" to "myCommand pKey, pValue"
Modifying parameters will modify calls to the handler in all scripts in the stack.

Safe Delete
Only deletes the handler/variable if nothing is using it.
Otherwise you get a warning specifying where it's used.

Move Handler To
Copy Handler To
These allow you to select a new home for the selected handler.

Create Getter and Setter
Allow external access to a script local variable.
The handlers will be named after the variable name:
local ArrayName
becomes
command setArrayNameTo pValue
and
function ArrayName()

Add Documentation
Creates documentation for a handler in the form
/**
* HandlerName
* parameters
* Returns (if a function)
* returnValues
*/
The documentation format is stored as a custom property template and can be modified if desired.

Add Test
Adds a template unit test for the selected handler to a file in the same folder as the stack.
The file has the same name as the stack with the ".tests" extension.
The tests file is intended to be run using Ah, Software's TestRunner unit testing stack.
The unit test format is stored as a custom property template.
Modifying it will probably cause it to cease functioning.

Convert Global To
Script Local
Getter and Setter
Property

Convert Variable To
Script Local
Parameter
Property

Extract To
Creates a new handler from the selected block of code in the current script.

Find Orphan Code
Displays a list of unused local variables and uncalled handlers.
Double-click a list item to select it in the script editor.

Undo Last Refactor
There's a full undo first-in-last-out stack mechanism for those oops moments.
Issues a warning if you attempt to undo changes already saved to disk.

Go Back (contextual menu only)
Not strictly part of a refactoring process, but since I was reworking the Edit menu anyway...
After a "Go to definition" call, this gets you back to where you were.

Re: Refactoring Support for the LC Script Editor

Posted: Wed Mar 20, 2019 9:02 pm
by bogs
Holy wow, that is a lot packed in there Image

Very gracious Mark!

Re: Refactoring Support for the LC Script Editor

Posted: Thu Mar 21, 2019 2:47 pm
by Mikey
Are you going to repo that so people can be notified of updates (aside from seeing a post here)

Re: Refactoring Support for the LC Script Editor

Posted: Thu Mar 21, 2019 3:19 pm
by Lagi Pittas
Hi Mark,

Thank you so much for this this, which we have all thought about writing - next time.

Do you want to put your paypal email here or just PM me? I for one would like to contribute/donate something because even if I have no use for it at this moment, I certainly will in the not too distant future and you can be sure it will save me a good few hours. Frankly I would put it on your website as well with a donate button - every little helps.

Regards Lagi

Re: Refactoring Support for the LC Script Editor

Posted: Fri Mar 22, 2019 12:46 am
by mwieder
Mikey -
Thanks for the suggestion. I've moved it over to github now.
And edited the announcement for the new location.

Lagi-
Nope. This is a gift for developers. It happens. Enjoy it, contribute more stuff in kind.
If you really feel like you need to do something with money, make a contribution to some organization that needs it.

Re: Refactoring Support for the LC Script Editor

Posted: Fri Mar 22, 2019 7:22 pm
by jiml
Mark ,

Very generous!
Thank you!

Jim Lambert

Re: Refactoring Support for the LC Script Editor

Posted: Sat Apr 06, 2019 12:51 am
by mwieder
The stack has been updated on github. The README.md file now lists one known issue that I'm still mulling over, but otherwise all the edge cases seem to work properly.

Re: Refactoring Support for the LC Script Editor

Posted: Fri May 24, 2019 4:55 pm
by mwieder
Thanks to Bernd Niggeman for finding *many* edge cases here.

The latest build is can be downloaded directly from
https://github.com/mwieder/revRefactor/ ... ter/Plugin
even if you don't need to build from the script text files.

And thanks to Brian Milby for ScriptTracker, which really has changed the way I maintain stacks.

Re: Refactoring Support for the LC Script Editor

Posted: Wed Oct 02, 2019 8:48 pm
by mwieder
Updated with the latest build, 1.0.14.
Now supports a FILO stack for 'go to definition' and 'go back' commands instead of just one level of breadcrumbs.

Re: Refactoring Support for the LC Script Editor

Posted: Wed Oct 02, 2019 9:43 pm
by Mikey
oh FRICK. I just had to move one of our apps to 9 which required a refactor of several containers and...I had completely forgotten about this.

Re: Refactoring Support for the LC Script Editor

Posted: Tue Apr 13, 2021 7:26 pm
by mwieder
Updated a bit to version 1.1:

Added a minimal help item to the help menu with the above information.
And added a busy cursor to the Find Orphans function since it's nested repeat loops all the way down.

The latest is on github, still at https://github.com/mwieder/revRefactor

I thought I had uploaded the stack to LiveCodeShare, but it seems to have disappeared, so I uploaded the current version there as well.

Re: Refactoring Support for the LC Script Editor

Posted: Wed Apr 14, 2021 5:22 am
by keliko
Thanks mwieder.

i will try it later