phpstorm keeps suggesting something that I never use as first autocomplete option
With phpstorm the first place in autocomplete is usually the one I'm looking for. But when I try to autocomplete intval (intv->ctrl-space) I always get intltz_get_tz_data_version as first option. I always select intval, but it doesn't move to first position like in other cases autocomplete usually works. Can I reset rankings or is there any other way to move intval to first place.
PhpStorm 2017.2 EAP
Build #PS-172.2465.7, built on May 24, 2017
PhpStorm EAP User
Expiration date: June 23, 2017
JRE: 1.8.0_152-release-855-b1 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 7 6.1
Please sign in to leave a comment.
When sorting a completion list the element's type has higher priority than the statistic. The reason for that is that the element which is chosen more often doesn't necessarily suit better to the current context. In the case of a concatenation, we assume that elements of the type "string" are supposed to be chosen more likely than any other elements. If you disagree with this assumption, feel free to elaborate on why completion should act differently.
Hi there,
1) Please try "File | Invalidate Caches..." and restart IDE if you have not tried it yet
2) Try with all custom plugins disabled (those that are not bundled by default)
But in general: if you do that "intv->ctrl-space" and then choose "intval" in completion window 2-3 times .. it should set it as "preferred" option anyway.
Invalidate/restart didn't fix it. I doubt the plugins have something to do with it - I don't use any plugins that would auto complete, except maybe .gitignore, but it only works on .gitignore files.
I forgot to mention that intval returns integer, but I most often use it with string - database query (because it's faster than database's own escape functions):
$id = _GET['id'];
"SELECT * FROM <table> WHERE id = ".intval($id);
>I doubt the plugins have something to do with it - I don't use any plugins that would auto complete,
I've seen weird things .. so it's always better to ensure that custom-plugin-less setup works properly.
Anything interesting in idea.log BTW (Help | Show Log in...)?
>I forgot to mention that intval returns integer, but I most often use it with string - database query (because it's faster than database's own escape functions):
Better use (int)$id -- it's faster.
But then ... you then instantly convert it to string anyway (because of concatenation)...
If you need safety - better use placeholders and prepared statements -- better/safer than escaping routines.
(int)$id has to be enclosed in another pair of brackets when it's in the middle of the string. And yes it's string->int->string conversion. I really haven't tested the speed, but since I'm using mysql_real_escape and charset is most often utf8 it should be quite slow. And even if its not intval($id) seams nicer to read than $db->escape($id);
Prepared statements are safe, but not as simple to use. For example if you have big query it's not easily readable. I would use prepared statements if placeholders were named. If you need to put 5 variables in a query and you switch the places of 2 of them you won't really notice. Sometimes I switch the order by just editing the query - change the order of joins. remove something from where clause, add something else, forget to update the variables ... I like to see the query in a sequence.
What happens if you press Ctrl+Space once again for completion? Does list remain the same?
Yes, nothing changes - still second
What sorting do you have there? Could you please attach a similar screenshot?
It's only when I concatenate intval to string. Intval by itself works fine:
May I ask you to reproduce the same situation as on the screenshot, then press Ctrl+Alt+Shift+W when the completion window is open and post here an output from the idea.log file. It should look something like this:
selected: func_get_arg
prefix: fun_get
weights:
func_get_arg frozen=true, sorter=1, liftShorter=true, stats=0, proximity=[openedInEditor=false, phpScope=0, phpNamespace=10, phpSameFile=false, sameDirectory=false, sameLogicalRoot=false, sameModule=0, inResolveScope=false, sdkOrLibrary=false]
func_get_args frozen=true, sorter=1, liftShorter=false, stats=0, proximity=[openedInEditor=false, phpScope=0, phpNamespace=10, phpSameFile=false, sameDirectory=false, sameLogicalRoot=false, sameModule=0, inResolveScope=false, sdkOrLibrary=false]
prefix: intv
weights:
intltz_get_tz_data_version frozen=true, sorter=1, middleMatching=false, phpReceiverType=INTERSECTS, prefix=-1043, stats=9056, proximity=[openedInEditor=false, phpScope=0, phpNamespace=10, phpSameFile=false, sameDirectory=false, sameLogicalRoot=false, sameModule=0, inResolveScope=false, sdkOrLibrary=false]
intval frozen=true, sorter=1, middleMatching=false, phpReceiverType=CONVERTIBLE, prefix=-1113, stats=9301, proximity=[openedInEditor=false, phpScope=0, phpNamespace=10, phpSameFile=false, sameDirectory=false, sameLogicalRoot=false, sameModule=0, inResolveScope=false, sdkOrLibrary=false]
intlcal_get_keyword_values_for_locale frozen=true, sorter=1, middleMatching=false, phpReceiverType=CONVERTIBLE, prefix=-1063, stats=0, proximity=[openedInEditor=false, phpScope=0, phpNamespace=10, phpSameFile=false, sameDirectory=false, sameLogicalRoot=false, sameModule=0, inResolveScope=false, sdkOrLibrary=false]
gmp_intval frozen=true, sorter=1, middleMatching=true, phpReceiverType=CONVERTIBLE, prefix=-963, stats=0, proximity=[openedInEditor=false, phpScope=0, phpNamespace=10, phpSameFile=false, sameDirectory=false, sameLogicalRoot=false, sameModule=0, inResolveScope=false, sdkOrLibrary=false]
This keeps happening:
I never used ExampleTag and I don't think I'll ever use in this project. Why is it stuck on top. And why is it "frozen". I clicked it once by mistake and no matter how much I click on "$extension" it doesn't go to the top.
You'll say that I'm trying to type variable without the $. Well that's the whole point of speeding up the process of typing - not having to use shift. It's the same as trying to access something without capital letter. I start typing and the think I click the most goes to the top - simple. This used to work better few years ago and I'm complaining about it for years and it doesn't get fixed.
STDOUT - weights:
2020-06-10 11:16:22,858 [83321737] INFO - STDOUT - ExampleTag frozen=true, sorter=1, middleMatching=false, liftShorter=false, phpPreferImportedClasses=false, prefix=-1001, phpDispreferNonApplicable=false, phpDispreferNonBundledExtension=false, stats=0, phpDispreferDeprecatedOrInternal=false, proximity=[openedInEditor=true, phpScope=3, phpNamespace=400, phpSameFile=false, sameDirectory=true, sameLogicalRoot=true, sameModule=2, inResolveScope=true, directoryType=3, sdkOrLibrary=false], ml_rank=NONE
2020-06-10 11:16:22,858 [83321737] INFO - STDOUT - extension frozen=true, sorter=1, middleMatching=false, liftShorter=false, phpPreferImportedClasses=true, prefix=-1152, phpDispreferNonApplicable=false, phpDispreferNonBundledExtension=false, stats=10000, phpDispreferDeprecatedOrInternal=false, proximity=[openedInEditor=true, phpScope=3, phpNamespace=400, phpSameFile=false, sameDirectory=true, sameLogicalRoot=true, sameModule=2, inResolveScope=true, directoryType=3, sdkOrLibrary=false], ml_rank=NONE
2020-06-10 11:16:22,859 [83321738] INFO - STDOUT - extension frozen=true, sorter=1, middleMatching=false, liftShorter=false, phpPreferImportedClasses=true, prefix=-1152, phpDispreferNonApplicable=false, phpDispreferNonBundledExtension=false, stats=10000, phpDispreferDeprecatedOrInternal=false, proximity=[openedInEditor=false, phpScope=0, phpNamespace=8, phpSameFile=false, sameDirectory=false, sameLogicalRoot=true, sameModule=2, inResolveScope=true, directoryType=3, sdkOrLibrary=false], ml_rank=NONE
2020-06-10 11:16:22,859 [83321738] INFO - STDOUT - export frozen=true, sorter=1, middleMatching=false, liftShorter=false, phpPreferImportedClasses=true, prefix=-1152, phpDispreferNonApplicable=false, phpDispreferNonBundledExtension=false, stats=9267, phpDispreferDeprecatedOrInternal=false, proximity=[openedInEditor=false, phpScope=0, phpNamespace=8, phpSameFile=false, sameDirectory=false, sameLogicalRoot=true, sameModule=2, inResolveScope=true, directoryType=3, sdkOrLibrary=false], ml_rank=NONE
... cut because there are few screens of text
Please try enabling "Editor | General | Code Completion > Rank completion suggestions based on Machine Learning" option.
Honestly, I doubt that it will _significantly_ change everything as this is just an experimental feature by now, but I think it worth a shot.
I activated it. We'll see.
I found out why exactly this class - it went into 'use':
But still most of the time I use classes only once or twice per file and variables all the time.