Gert-dev / php-ide-serenata

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

Autocomplete does not automatically show suggestions due to prefix override workaround #501

Closed machitgarha closed 3 years ago

machitgarha commented 4 years ago

Hi. First of all, thanks for this cool package in Atom. Everything works fine, except the auto-completion.

Desciption

When I type characters like $, :: or ->, the suggestions will be shown in a great way, but when I enter another character to limit the suggestions, all Serenata suggestions will be disappeared (yes, the default snippets are shown). However, all of expected suggestions will be re-shown when I enter Ctrl+Space.

Example

To be clarified, in the following example, minimumWordLength equals 3 (in the settings of autocomplete-plus package):

Input Actual Result Expected Result
$this-> Expected Result => Showing all methods of current class
$this->d Expected Result => Only snippets starting with d, like debug and do
$this->de Expected Result => Only snippets starting with de, like debug and def
$this->de + Ctrl+Space Expected Result => Showing methods starting with de
$this->deb (Problem) Only snippets starting with deb, like debug Showing methods starting with deb
$this->deb + Ctrl+Space Expected Result => Showing methods starting with deb

Steps to Reproduce

Do steps in Example section above.

Platform Information

What should I do now?

Gert-dev commented 4 years ago

Hello.

Do you have minimumWordLength in the autocomplete-plus settings set to a non-zero value?

machitgarha commented 4 years ago

Yes, it's 3, the default one.

Gert-dev commented 4 years ago

Do the words your typing happen to be less than three characters when this doesn't work :smile: ? IIUC, this setting causes nothing to be autocompleted unless you've typed at least three characters. If this is indeed causing the problem, you can try setting it to 0 and see if that has any effect.

machitgarha commented 4 years ago

No. Sorry. Neither typing more than minimumWordLength help anything nor decreasing its value.

However, when I set it to 0, it works, but strange and somehow wrong (e.g. especially for class methods and variables). Furthermore, pressing enter for inclusion of the suggestion inserts it after what I typed, not replacing it. For example, when I type replace and I press enter when the autocomplete is active on str_replace(), then the result will be replacestr_replace(), not as expected.

BTW, I don't want minimumWordLength to be 0.

Gert-dev commented 4 years ago

Okay, I think I may be able to clear up some confusion: autocompletion triggers on characters such as $, :: and -> because these are so-called "trigger characters", meaning Atom will always try to show suggestions when these are typed.

If you type something after them, you fall back to "standard" autocompletion, which also happens when you start typing on a new line. If you have minimumWordLength set to 3, this means (IIUC), that Atom will not try to do any additional autocompletion anymore when you type b or be, because you have fewer than 3 characters (Atom stops counting at word boundaries).

In short, this probably happens:

  1. Type self::.
  2. Atom asks Serenata for autocompletion because :: is a trigger character.
  3. Autocompletion is shown, same as if you pressed Ctrl+Space.
  4. You type g, turning the code into self::g.
  5. Atom needs to ask the server for autocompletion suggestions again, because the input or "prefix" changed. The minimumWordLength is 3, which is larger than 1, so Atom shrugs and gives up.

I would expect this to start working when you typed 3 or more characters, then, though :smile:.

machitgarha commented 4 years ago

@Gert-dev For clarification, I've updated the issue and added more precise details on the problem (in the Example section).

Gert-dev commented 4 years ago

Hmm, I understand. This does somehow appear to be linked to that minimumWordCount option. If I set it to 0 here, everything works, if I set it to the default (3), I get even different results from you and never get autocompletion unless I press ctrl-space.

The strange thing is that, on exactly the third character, even the snippets disappear. As if Atom knows there should now be other suggestions, but none are shown. If I press ctrl-space, they suddenly pop up.

I'm wondering if this is related to this fix I did. Could you perhaps try commenting it out to see if that fixes anything?

(I can say for sure that it's not a server problem, since in other clients and the server output the appropriate suggestions appear to be returned.)

machitgarha commented 4 years ago

@Gert-dev Oh! Good to hear it does not only happen for me. And about the fix, what should I do to get the fix? Only updating to the latest version or not?

rhuijts commented 4 years ago

Commenting out that line in ~/.atom/packages/php-ide-serenata/lib/SerenataClient.js fixed it for me, with the autocomplete-plus still on the minimumWordCount default of 3. It also fixed issue #489 for me, so the suggestion is no longer appended to what I already typed. It does bring back issue #487, so I will have @@inheritDoc, but that is still better than @inhe@inheritDoc.

machitgarha commented 4 years ago

@rhuijts Thanks for your help.

@Gert-dev Yes, commenting the mentioned line as a temporary fix worked for me too. However, I'm waiting for a permanent fix (maybe removing that line causes other issues?).

Gert-dev commented 4 years ago

Hello.

Nice to hear you found a workaround.

Indeed, I could remove the line, but it will break sorting and filtering the list, as indicated by the comment above it. Atom seems to insist on doing its own reordering and filtering client-side, whilst the autocompletion results by Serenata are already filtered and sorted server-side. This causes less relevant results to be shown or the sorting to be different than intended by the server. The only fix I've found for that so far is this line, but it seems like an upstream bug.

Seeing as removing this line fixes it, I'll update the title of this ticket to reflect that and leave it open so it's not forgotten in the future.

claytonrcarter commented 4 years ago

Commenting out that line in ~/.atom/packages/php-ide-serenata/lib/SerenataClient.js also fixed this for me. Thanks!

yanggs07 commented 3 years ago

is this bug still exists with current 5.4.0?

machitgarha commented 3 years ago

@yanggs07 Still exists. As @Gert-dev has said, it seems to be an upstream bug.

yanggs07 commented 3 years ago

@yanggs07 Still exists. As @Gert-dev has said, it seems to be an upstream bug.

emmmm so i still use v4.5.3 with osx 10.15.2, atom

UziTech commented 3 years ago

This may be fixed in atom-languageclient v1.0.0 if it is not please open an issue on the new repo https://github.com/atom-ide-community/atom-languageclient

machitgarha commented 2 years ago

@Gert-dev Could you please release a new version (probably 5.4.1) for this change? Maybe it's late, but I think it was an effective and impactful change.

Gert-dev commented 2 years ago

Done - in the spirit of leaving the package in a somewhat stable state (due to #522).

machitgarha commented 2 years ago

@Gert-dev Great! Thanks. And yes, the package is in a really good shape (and sorry, I'm personally interested in, but unable to being a maintainer).

nelson6e65 commented 2 years ago

For $this->myA is successfully autocompleted to $this->myAwesomeMethod(). ✅

But for local variables, it still adds an extra $ as prefix. $thi -> $$this. 🐛

Seems like $ character is not taken in count as prefix, only 'thi' instead of $thi.

machitgarha commented 2 years ago

@nelson6e65, as you might already know, that's a separated issue being tracked in #487.

nelson6e65 commented 2 years ago

Oh, sorry. I didn't remember it. 😅