deakjahn / vscode-php-allfactor

Comprehensive PHP refactoring (Visual Studio Code)
https://marketplace.visualstudio.com/items?itemName=tramontana.php-allfactor
1 stars 0 forks source link

Not able to get string interpolation conversion to work #10

Open zacksmash opened 5 months ago

zacksmash commented 5 months ago

I'm not sure where to find the command to do this. It doesn't seem to show up in the context menu or the shortcut for refactoring. Not sure what I'm missing.

Also, I wanted to see what your plans are for this plugin. This is honestly the best plugin to bridge the gap for VS Code to compete with other IDE's, so if there's anything I can offer to help, I'm game!

zacksmash commented 5 months ago

Nevermind, I figured out that the cursor has to be right on the . in order for the context menu item to show up. Would be nice if it was anywhere in the interpolated area.

// It would be nice if my cursor could be anywhere in this line
$output = $string . " Text";
deakjahn commented 5 months ago

@zacksmash To tell you frankly, I don't know, either. PHP development is only a smaller part of my activities these days, I spend most of my time in mobile development now (not that it doesn't sometimes include a server part as well, of course) but I enjoy it myself when I do PHP in VC (and yes, I came to VC from PhpStorm, as you probably, too).

As you can see from the readme, the original idea was to make it into a freemium version if it takes off but, although those who contacted me were positive about it, the uptake is, well, far from enough to warrant even thinking about it now. :-)

Yes, I can see your point, it's a side effect of how the analysis works. It's basically straightforward—at least, once you have a syntactic analysis in place—to determine the exact token you're on and in quite a few cases, I need to check not only for the immediate token but to see what neighborhood it is in. But some checks are simpler than others. If you consider the opposite, to break up an interpolated string into concatenation, that's easier because the analysis can show you that you're inside such an interpolated string. In the direction you mention, you should analyze all expressions of any complexity to see if it's such a concatenated string at all. Your example is simple but actually, your $string could be not just a string but an arbitrarily complex function call returning anything that PHP can convert to a string, too.

And don't forget that we have many dozens of similar checks made at the same time, practically after every keystroke you make when typing your code (or move your cursor), also including that several plugins might do the same in parallel, each for their own purposes.

zacksmash commented 5 months ago

@deakjahn Definitely understand! It's a large undertaking, but I feel like with a few tweaks and some polish this could be a major extension for all PHP devs using VSCode. You're just a few tweets or reddit posts away from large adoption, for sure! Again, happy to help if you're looking for collaborators!