phptools-docs icon indicating copy to clipboard operation
phptools-docs copied to clipboard

Autocomplete often randomly fails to suggest obvious suggestions

Open php4fan opened this issue 1 year ago • 3 comments

This is just one particular case of something that happens all the time: the autocomplete failing to show expected suggestions.

Here: image

I'm in the process of typing this call:

    return $this->redirect($urlGenerator->generate("something"));

Before I start typing at all, the entire code in the whole file I'm editing (and the whole project for that matter) is correct. Then I start typing up to this:

    return $this->redirect(

and here the opening parenthesis gets autoclosed, and the cursor is inside the parentheses.

Naturally, I start typing the name of the variable:

    return $this->redirect($urlGe)

and I don't get the expected autocomplete suggestion for the variable $urlGenerator which is an input parameter of the function I'm in.

I get that the code now has a syntax error, because the ; at the end of the current line is missing. And indeed, if I go ahead and add it, and then come back inside the parentheses and try again, autocomplete will work.

But it would be totally ridiculous to expect me to do that when naturally typing code. One doesn't write a method call, go to the end and add the ;, and then go back to fill in the arguments.

Autocomplete's job is to autocomplete while you're typing. If it can't handle a temporary incorrectness of the code as a whole due to the very fact that you're not finished typing, it's utterly useless.

I'm not sure if adding the ; automatically when autocolosing the parentheses would be a solution. Certainly it would solve the issue in this particular case and it would be better than the current situation, and the fact that you may want to continue after the closed parenthesis and before the ; doesn't seem like an issue (eventually, you'll have to end with a ;), but I'm not sure I'm considering all possible scenarios.

A separate issue (but I can't avoid mentioning it in this context) is the useless, misleading, "tautological suggestion" of

(local variable) $whateverIveTypedSoFar

That misleads me into thinking that the partial variable name I've already typed is already an existing variable. Even when I learn to not get misled by that, what purpose is it supposedly serving, by systematically proposing to complete whatever I type by adding nothing?

Actually, I now see that doesn't always happen. When I got in as in the situation above (as shown in the screenshot) , I tested it by typing $ljsndljnsdljd and it kept showing up, but now I'm testing again and it doesn't happen, so I don't know what triggers it.

php4fan avatar Mar 10 '24 11:03 php4fan

I wonder if this is another case of the same issue:

image

Here, I played a bit with the code to test variations of it, I added and deleted stuff, and at some point I had the exact same code as above but I did get the expected autocomplete suggestions (including both $_post and $_POST).

This happens very often: that it fails to show obvious autocomplete suggestions, or to highlight obvious errors and warnings, and then, after editing the code (only the current file) and editing it back to the exact same, it will behave as expected. This is very frustrating. The output should reliably be a function solely of the current code, and not depend apparently randomly on the edit history.

php4fan avatar Mar 19 '24 15:03 php4fan

Thank you.

This happens when the code has syntax errors so we don't read it properly. We'll be working on more tolerant parser in the future.

This is related to https://community.devsense.com/d/1949-autocomplete-not-working-properly-while-error-in-code

jakubmisek avatar Mar 29 '24 17:03 jakubmisek

We'll be working on more tolerant parser in the future.

I don't know whether this is extremely difficult to achieve or if you are underestimating the importance of the issue.

Forgive me for insisting on this point:

This happens very often: that it fails to show obvious autocomplete suggestions, or to highlight obvious errors and warnings, and then, after editing the code (only the current file) and editing it back to the exact same, it will behave as expected.

Here it is: before: image

after: image

Note also the "tautological suggestion" again in the first screenshot. That always seems to happen together with this issue, and it seems to not happen when the main issue doesn't happen.

Maybe it's not just a matter of being tolerant to syntax errors, as clearly you already achieve that, but only sometimes (with the exact same syntax errors). Maybe it's something more trivial.

php4fan avatar Jul 29 '24 19:07 php4fan