ide: Fixed rare problem of duplicities in autocomplete

This commit is contained in:
Mirek Fidler 2023-10-12 10:40:06 +02:00
parent f440baf14c
commit 87ddd12ec2
3 changed files with 48 additions and 0 deletions

View file

@ -278,12 +278,30 @@ void AssistEditor::SyncAssist()
assist_item_ndx.Clear();
int typei = type.GetCursor() - 1;
Buffer<bool> found(assist_item.GetCount(), false);
VectorMap<String, int> found_name; // to accelerate resolving duplicities
Index<String> cpp;
for(int pass = 0; pass < 2; pass++) {
for(int i = 0; i < assist_item.GetCount(); i++) {
const AssistItem& m = assist_item[i];
if(!found[i] &&
(typei < 0 || m.typei == typei) &&
((pass ? m.uname.StartsWith(uname) : m.name.StartsWith(name)) || m.kind == KIND_ERROR)) {
int q = found_name.Find(m.name);
if(q >= 0) { // resolve duplicities
int& ii = found_name[q];
if(ii >= 0) { // lazy call to CppText
const AssistItem& mm = assist_item[ii];
cpp.FindAdd(CppText(mm.name, mm.pretty));
ii = -1;
}
String g = CppText(m.name, m.pretty);
if(cpp.Find(g) >= 0)
continue;
else
cpp.Add(g);
}
else
found_name.Add(m.name, i);
found[i] = true;
assist_item_ndx.Add(i);
}

View file

@ -117,6 +117,35 @@ int PaintCpp(Draw& w, const Rect& r, int kind, const String& name, const String&
return x;
}
String CppText(const String& name, const String& pretty)
{ // converts pretty to text that is unique wrt PaintCpp - to avoid duplicities in autocomplete
String g;
Vector<ItemTextPart> n = ParsePretty(name, pretty);
for(int i = 0; i < n.GetCount(); i++)
if(findarg(n[i].type, ITEM_NAME, ITEM_OPERATOR) >= 0 || pretty[n[i].pos] == '(') {
for(int j = i; j < n.GetCount(); j++)
g << pretty.Mid(n[j].pos, n[j].len);
while(i) {
const ItemTextPart& p = n[i - 1];
if(p.len == 1 && pretty[p.pos] == ' ')
i--;
else
break;
}
g << '@';
if(i > 2) { // autocomplete sometimes fully qualifies the the name, looks ugly, remove XXX:: from the end
ItemTextPart& p = n[i - 1];
if(p.type == ITEM_CPP && p.len == 2 && pretty[p.pos] == ':' && pretty[p.pos + 1] == ':' &&
n[i - 2].type == ITEM_TEXT)
i -= 2;
}
for(int j = 0; j < i; j++)
g << pretty.Mid(n[j].pos, n[j].len);
break;
}
return TrimBoth(g);
}
void AssistEditor::AssistDisplay::Paint(Draw& w, const Rect& r, const Value& q, Color ink, Color paper, dword style) const
{
int ii = q;

View file

@ -92,6 +92,7 @@ enum AdditionalKinds {
Image CxxIcon(int kind); // TODO: Move here
int PaintCpp(Draw& w, const Rect& r, int kind, const String& name, const String& pretty, Color ink, bool focuscursor, bool retval_last = false);
String SignatureQtf(const String& name, const String& pretty, int pari = INT_MAX);
String CppText(const String& name, const String& pretty);
bool IsStruct(int kind);
bool IsTemplate(int kind);