-
Notifications
You must be signed in to change notification settings - Fork 3
Conversation
… of the doc blocks
…ean up of properties
After your latest changes, I took it for a spin for some real-world usage and noticed the following things (open for discussion, of course):
A minor bug: trying to extract a catch block with a type hint will put the catch block variable in a parameter of the extracted method: try {
} catch (Exception $e) {
} Regarding the part of the line, I don't really think it will be a problem, but it might be something we can solve: what if you used the end of the selection (i.e. the code to extract) instead of the end of the variable match? Would this generate problems in some situations? About type hinting: you are right, the type there is obviously |
I've fixed the try catch bug, so it should now exclude the exception from the parameters. I've also added the type hints to the parameters. But it's adding the fully qualified namespace as that is what With the doc block descriptions, I think that adding more text fields to the modal is going to make it too big and probably won't fit on some monitors. If we were to add a check box to say whether to generate the description placeholders. Then if the user does we replicate the functionality in atom/snippets where you can tab jump between the different markers [1], like what the docblockr package does. I think this would be best, if you agree then I will build it. Looking at the selection problem again, I remembered that I'm extending their selected range to the start and end column on the start and end rows respectively. The reason I was doing this was so that in case the user didn't select the entire if statement, for example, this would compensate and select the entire line for you. The only kinda of solution I've thought of is having a config option to specify whether to be fuzzy or precise with the selections and then use the end of the selected range when getting variable type. Do you like this solution or is there a better way? [1] https://github.com/atom/snippets/blob/master/lib/snippet-expansion.coffee |
…range but instead the user selected range
Regarding the types, adding a use statement for them might not be a bad idea. However, I'd like to do some investigation on how to best approach this first (i.e. it may be best to leave this for an additional improvement after this is merged) as automatically adding use statements raises the following questions:
As you indicated, this is something that the base package (even the PHP side) could learn to handle properly in the future. Adding a checkbox for the descriptions with tab jumping sounds like a good idea. I'm not sure if this will work, but I noticed the standard atom-snippets package [1] provides a service that contains an I'm also wondering about the automatic selection correction. On one side I like the convenience it offers, but on the other side I feel like the user should clearly indicate what he or she wants to extract (even if it's wrong, there is always the preview window as validation). If we go the automatic correction route (or support it with a configuration option), it should probably also handle situations such as: $var = "
Multiline string.
The selection starts at this line";
$andEnds = 'here'; Perhaps it's easiest to just force the user to properly select the code? Do you happen to know how IDE's handle this? (Not that we need to necessarily match this behavior, but it's always good to compare.) |
…ext in case snippets are disabled
…find the variable type
New
Changed
I found that PHPStorm does some validation before extracting the method on whether it's possible to extract the code and if the code being extracted is valid. Maybe this is something to look at in the future? |
Thanks for taking the time to improve this. I think I've kept you busy long enough, so I'll merge this now ;-). As you said, we can always improve the remaining details later. Thanks! |
Merged the extract method feature from CWDN.
Hi,
I originally made a package called
php-extract-method
, it allows users to select a piece of code and extract it out into another function (idea taken from PHPStorm). This was alright and had basic functionality but there were a few bugs and sometimes the spacing was off. What I've done is take some of that and move it into this package. But I've made many improvements when doing this and completely rewrote the logic for getting the parameters needed.Planning to deprecate my old package if you are happy with this, as this version is much better.
Improvements
list
function in phpThere's still a small feature that I want to add, which is to allow users to set whether they want to pass the parameters in by reference or for it to return the variables like it currently does. But this feature isn't too important so it can be done at a later date.
I'm adding this feature to this package because it seemed to make more sense to me, rather than creating my own package.
Hope this helps and makes sense. If you have any questions please don't hesitate to ask me.
Thanks
Chris