A critical thing to notice is that the completion filtering is NOT based on the input being a string prefix of the completion (but that works too). The input needs to be a subsequence match of a completion. This is a fancy way of saying that any input characters need to be present in a completion string in the order in which they appear in the input. So abc is a subsequence of xaybgc, but not of xbyxaxxc. After the filter, a complicated sorting system ranks the completion strings so that the most relevant ones rise to the top of the menu (so you usually need to press TAB just once).
How much of an issue is the sorting? [...]It is not really an issue; only that a sort function would need to be written.
m_FilteredTokens.erase(remove_if(m_FilteredTokens.begin(), m_FilteredTokens.end(), Matcher), m_FilteredTokens.end());
std::sort(m_FilteredTokens.begin(), m_FilteredTokens.end(), MyFancySort); // add sorting here
PS: Seems to be small bug with placement of doc string window. Sometimes it places on left when there clearly isn't room for the whole window.Well, that was supposed to be a feature (https://github.com/alpha0010/codeblocks_sf/commit/9d177affc9bb4965d703a44db8ae2640a969e713). Does it act unexpectedly?
It is not really an issue; only that a sort function would need to be written.Probably it would be better to use some ranking function, converting the string to some integer and then using normal integer sorting.
PS: Seems to be small bug with placement of doc string window. Sometimes it places on left when there clearly isn't room for the whole window.Well, that was supposed to be a feature (https://github.com/alpha0010/codeblocks_sf/commit/9d177affc9bb4965d703a44db8ae2640a969e713). Does it act unexpectedly?
It is not really an issue; only that a sort function would need to be written.Probably it would be better to use some ranking function, converting the string to some integer and then using normal integer sorting.
Probably YouCompleteMe dev won't mind if you use theirs way of sorting.... :)
++hack;
Confirmed. (And also confirmed that it is the fault of this hack interacting with another component of CCManager.)It gets cut off when being displayed on the left side. Maybe the same would have happened on the right side too, but I didn't think so (if that's the case, then maybe the window just needs to be resized). I was using a 1080p display on a dual monitor setup. The 1080p monitor is on the left, the other monitor is something less than 1080p.PS: Seems to be small bug with placement of doc string window. Sometimes it places on left when there clearly isn't room for the whole window.Well, that was supposed to be a feature (https://github.com/alpha0010/codeblocks_sf/commit/9d177affc9bb4965d703a44db8ae2640a969e713). Does it act unexpectedly?
Code: see attached++hack;
Confirmed. (And also confirmed that it is the fault of this hack interacting with another component of CCManager.)It gets cut off when being displayed on the left side. Maybe the same would have happened on the right side too, but I didn't think so (if that's the case, then maybe the window just needs to be resized). I was using a 1080p display on a dual monitor setup. The 1080p monitor is on the left, the other monitor is something less than 1080p.PS: Seems to be small bug with placement of doc string window. Sometimes it places on left when there clearly isn't room for the whole window.Well, that was supposed to be a feature (https://github.com/alpha0010/codeblocks_sf/commit/9d177affc9bb4965d703a44db8ae2640a969e713). Does it act unexpectedly?
a very nice hack indeed. Works beautifully.Until you try to complete wxString. With my clang plugin, it does not even show up until I have typed the full name, and even then, it is the fifth item. ???
One more issue: in python cc, I think I need to be able to do async docstring calls. otherwise the gui can freeze for quite a while.I have been attempting to work on that for a while (with cbThreadPool), however, I apparently do not understand threading nearly as well as I had thought; each of my tries immediately crashed while updating the GUI from a cbEVT_THREADTASK_ALLDONE handler. Looks like more reading for me.
Nice catch re wxString, just need to sort alphabetically for equal priority items?The problem is, CalcValue() (which is tries to nearly replicate/quantify the algorithm YCM designed) gives wxString a worse value because its word boundary string is only "ws" (whereas wxSTRING_REVERSE_ITERATOR for example is "wsri", more closely matching the input). (Items with equal priority *should* already be in alphabetical order, assuming my implementation works the way I think it does.)
Re threads, need to be careful about passing data that is constructed in the worker thread being deleted before it gets handled on the main thread. There are some posts about certain events being unsafe by (i think) ollydbg.Thanks, I will look for those.
Unfortunately, re-balancing the weighting algorithm would probably cause it to lose the benefit it gives in most other cases. (I am tempted to hardcode a small score boost for wxString, because it is rather common in wxWidgets based code... but that could get even uglier if other similar problem tokens show up.)No hardcoding, please, it is ugly and unprofessional:)
Have you tried to make the docstring API to be consisted of two steps/calls?One more issue: in python cc, I think I need to be able to do async docstring calls. otherwise the gui can freeze for quite a while.I have been attempting to work on that for a while (with cbThreadPool), however, I apparently do not understand threading nearly as well as I had thought; each of my tries immediately crashed while updating the GUI from a cbEVT_THREADTASK_ALLDONE handler. Looks like more reading for me.
Nice catch re wxString, just need to sort alphabetically for equal priority items?The problem is, CalcValue() (which is tries to nearly replicate/quantify the algorithm YCM designed) gives wxString a worse value because its word boundary string is only "ws" (whereas wxSTRING_REVERSE_ITERATOR for example is "wsri", more closely matching the input). (Items with equal priority *should* already be in alphabetical order, assuming my implementation works the way I think it does.)
Unfortunately, re-balancing the weighting algorithm would probably cause it to lose the benefit it gives in most other cases. (I am tempted to hardcode a small score boost for wxString, because it is rather common in wxWidgets based code... but that could get even uglier if other similar problem tokens show up.)
Have you tried to make the docstring API to be consisted of two steps/calls?Although that would work, I would be hesitant to use it as I have so far designed the interface such that individual CC plugins do not need to know that CCManager exists, nor to talk with it. They only have to return data when requested.
For example:
1. CCManager calls a plugin to to start gathering the data. No ui is shown to the user or empty UI is shown, so he can have a chance to cancel it.
2. The CC plugin has gathered the data and then calls CCManager to show the UI or fill the UI.
1 and 2 happen in the main thread. This way you leave the task of threading to the plugin.
[...] How about doing Acronym matching as a separate, alternative calculation that only gets used if it would create a higher score?Hmm, I will experimenting with that...
Although that would work, I would be hesitant to use it as I have so far designed the interface such that individual CC plugins do not need to know that CCManager exists, nor to talk with it. They only have to return data when requested.OK you can make a custom event cbEVT_CC_DOC_STRING_READY or something like that...
OK you can make a custom event cbEVT_CC_DOC_STRING_READY or something like that...I think that would be a reasonable solution. (I was quite literally just typing that same thought, when I saw you had posted.)
Any progress with this feature? Would like to see a finished version merged into trunk too.Unfortunately in the busyness of my life, I have not yet had time to work further on it. Hopefully I will soon though...
(Improvements to stability/usability are in progress...)Updated patch (attached) is fully functional, and
Also included in this patch is a potential solution to this. CCManager records each time you select (hit enter/double click to complete and insert the result) an item that took "too long" to come up in the autocomplete listing. These entries (stored in a small buffer, to allow older, no longer used, entries to expire) are given a score bonus, so they float to the top faster the next time the same query comes up.a very nice hack indeed. Works beautifully.Until you try to complete wxString. With my clang plugin, it does not even show up until I have typed the full name, and even then, it is the fifth item. ???
[...]Probably working now ::)... (patch attached)stable (as far as I can tell)edit: discovered a crash to work out.
What is the issue with implementing the algorithm I proposed above?Mostly it was that this "adaption" algorithm was much faster for me to get to a working state. (To implement your algorithm, I would need to spend some trial-error time, testing different constants.)
This seems to work reasonably... (I will need to do more testing though.)What is the issue with implementing the algorithm I proposed above?[...] To implement your algorithm, I would need to spend some trial-error time, testing different constants.
static int CalcPrefixValue(wxString query, wxString token)
{
if (query.IsEmpty() || token.IsEmpty())
return 0;
int val = 0;
int shift = sizeof(val) * 8 - 2;
if (!token.Lower().StartsWith(query.Lower()))
val += (1 << shift);
--shift;
if (!token.StartsWith(query))
val += (1 << shift);
--shift;
int idx = token.Lower().Find(query.Lower());
if (idx == wxNOT_FOUND)
val += (1 << shift);
--shift;
if (idx > 6)
val += (1 << shift);
--shift;
if (idx > 3)
val += (1 << shift);
--shift;
idx = token.Find(query);
if (idx == wxNOT_FOUND)
val += (1 << shift);
--shift;
if (idx > 6)
val += (1 << shift);
--shift;
if (idx > 3)
val += (1 << shift);
--shift;
val += (1 << shift);
val *= std::max<int>(1, 4 - query.Length());
return val; // lower is better
}
int find(const wxString &str, const wxString &substr)
{
int pos = str.Find(substr);
return pos == wxNOT_FOUND? str.Len() : pos;
}
wxString acronym(const wxString &str)
{
wxString s = str.Mid(0,1);
for (i=1;i<str.Len();++i)
{
n = str.Mid(i,1);
bool underscore = false;
while (n == _T("_"))
{
underscore=true;
++i;
n = str.Mid(i,1);
}
if (n==wxEmptyString)
break;
if (underscore || n == n.upper())
s<<n;
}
return s;
}
int min(int x, int y)
{
return x<y? x:y;
}
int score(const wxString &a,const wxString &value)
{
wxString al = a.Lower();
wxString aa = acronym(a);
wxString aal = aa.Lower();
int pos_a = find(a, value)*4;
int pos_al = find(al, value.Lower())*4+1;
int pos_aa = find(aa, value)*4+2;
int pos_aal = find(aal, value.Lower())*4+3;
return min(min(pos_a,pos_al),min(pos_aa,pos_aal));
}
Another thought: the adaption mechanism can be made more deterministic running it in 'learning mode' for a session. Afterwards (in subsequent sessions), use the results as static data to run the heuristics.
Seems to mostly work, but in python, with completion on "os." then type "mod" I get: "mknod, chmod, fchmod, removedirs" in that order [...]"mod" matches all of them because "mknod" and "removedirs". "mknod" is first, because it starts with the same character that you first typed; "chmod" and "fchmod" are next because the contain an exact match of "mod". This the (current) behaviour of the prioritization.
Also, with the disappointing lack of useful namespace usage in C++, I can see why you would want the "adaption" algorithm, but at least for python it seems less of a necessity. It would be good to cleanly decouple that functionality from the basic functionality, so that it can be easily switched off. (I haven't read your code closely so maybe that's already done.) Another approach would be to give priority to tokens that are used in the local file, but I'm guessing that would be quite a bit trickier to implement.Not exactly clean :) , but the two easiest ways to disable are either comment out the line that searches the cache, or disable the function that adds items to the cache (or both).
Another thing that occurrs to me is that we only use the YCM style filtering to limit the already created list of items that match the typed prefix before CC opens, not what is actually add to the list in the first place. This is probably for the best?Sort of; CCManager sends the plugins a "fake" context, that is at most one character long. That seemed to provide an acceptable balance showing applicable results, and cost of building/filtering a large list.
Seems like if you would use it at all that it may as well be always running. Over time your coding evolves... Maybe just need a way of limiting the size of the dictionary, or a way of making sure that stuff that hasn't been used in a while get de-prioritized?Currently, the dictionary is not saved on close. However, when making it persistent, I think saving only the 64 (or some other magic constant) most recently (or perhaps frequently?) used entries to the config file, would be a good option.
"mod" matches all of them because "mknod" and "removedirs". "mknod" is first, because it starts with the same character that you first typed; "chmod" and "fchmod" are next because the contain an exact match of "mod". This the (current) behaviour of the prioritization.
What about, for example: clanccgcext -> clang_codeCompleteGetContexts() (from libClang)? Imperfect matches allow typing a longer name by (mentally) skipping through, typing only the parts where it differentiates from the other items listed.
I find my typing habit often is: type a prefix (to bring up autocomp), enter acronym for the remaining parts, (if choice is still "far") enter suffix.
(I still am trying to get used to this; it is a completely different way of thinking.)