Refactoring Support for the LC Script Editor

Find out what's going on with LiveCode (the company), product releases, announcements, and events.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Refactoring Support for the LC Script Editor

Post by mwieder » Wed Mar 20, 2019 6:38 pm

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.
Last edited by mwieder on Fri Mar 22, 2019 12:38 am, edited 3 times in total.

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Refactoring Support for the LC Script Editor

Post by bogs » Wed Mar 20, 2019 9:02 pm

Holy wow, that is a lot packed in there Image

Very gracious Mark!
Image

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 755
Joined: Fri Jun 27, 2008 9:00 pm

Re: Refactoring Support for the LC Script Editor

Post by Mikey » Thu Mar 21, 2019 2:47 pm

Are you going to repo that so people can be notified of updates (aside from seeing a post here)

Lagi Pittas
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 365
Joined: Mon Jun 10, 2013 1:32 pm

Re: Refactoring Support for the LC Script Editor

Post by Lagi Pittas » Thu Mar 21, 2019 3:19 pm

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

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Refactoring Support for the LC Script Editor

Post by mwieder » Fri Mar 22, 2019 12:46 am

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.

jiml
Posts: 336
Joined: Sat Dec 09, 2006 1:27 am
Location: Los Angeles

Re: Refactoring Support for the LC Script Editor

Post by jiml » Fri Mar 22, 2019 7:22 pm

Mark ,

Very generous!
Thank you!

Jim Lambert

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Refactoring Support for the LC Script Editor

Post by mwieder » Sat Apr 06, 2019 12:51 am

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.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Refactoring Support for the LC Script Editor

Post by mwieder » Fri May 24, 2019 4:55 pm

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.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Refactoring Support for the LC Script Editor

Post by mwieder » Wed Oct 02, 2019 8:48 pm

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.

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 755
Joined: Fri Jun 27, 2008 9:00 pm

Re: Refactoring Support for the LC Script Editor

Post by Mikey » Wed Oct 02, 2019 9:43 pm

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.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Refactoring Support for the LC Script Editor

Post by mwieder » Tue Apr 13, 2021 7:26 pm

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.

keliko
Posts: 85
Joined: Thu Aug 01, 2019 8:15 am

Re: Refactoring Support for the LC Script Editor

Post by keliko » Wed Apr 14, 2021 5:22 am

Thanks mwieder.

i will try it later

Post Reply

Return to “Announcements”