Gert-dev / php-ide-serenata

Atom IDE package that integrates the Serenata server to provide PHP code assistance
https://serenata.gitlab.io/
Other
274 stars 19 forks source link

Move cursor at end of inserted method name/function if the method/function has no arguments #434

Closed hultberg closed 6 years ago

hultberg commented 6 years ago

Currently, when confirming a selection from the autocomplete, the cursor is moved inside the parentheses of the function/method:

$myClas->getSomeText(/* HERE */);

However, I would love for the autocompletion to move the cursor at the end when the function/method has no arguments as there is nothing to write at that position. I was looking forward to make an PR, but found as I'm not familiar with how the autocompletion work, I don't know if this is something serenata is doing or if its atom. @Gert-dev, can you point me in the right direction? :-)

Gert-dev commented 6 years ago

Hi @hultberg

This originally was the case before autocompletion was implemented in the Serenata server. It was dropped as I was trying to follow the LSP specification as closely as possible and, at the time, there was no way for a server to indicate where the cursor should go in an autocompletion suggestion. Though when I was almost finished, I noticed a newer version of the specification was released that allows adding a marker to the insertion text to indicate where the cursor should go (or rather: to indicate the tab stops, the same way as you can do in Atom snippets).

If you take a look the FunctionAutocompletionProvider in Serenata, you'll see that there is a $0 between the parantheses here. The client (Atom) will then pick that up and place the cursor there. So in theory, all you would need to do is use the passed $function array to see if the function has any (required) parameters and, if not, use ()$0 instead of ($0). This would also need to be updated for the NonStaticMethodAutocompletionProvider and the StaticMethodAutocompletionProvider in the same way as well as some new tests would be necessary for that corner case.

In any case, thanks for considering to contribute :-).

hultberg commented 6 years ago

Closing as this was implemented with https://gitlab.com/Serenata/Serenata/merge_requests/76

Gert-dev commented 6 years ago

Yes, thanks for the PR! I've just updated both the server and this package and it should now be live for everyone.