GNOME Bugzilla – Bug 761446
ctags: completion results should not include duplicated names
Last modified: 2016-02-21 23:15:12 UTC
We currently are too liberal in showing duplicated entries in the ctags completion provider. If the word is the same with other completion entries, we should only show duplicate entries if they are of a different type (in case the type icon is useful). Right now, I think we are showing duplicates if they come from different files. It results in *many* "properties" entries, for example. This should be patched in the ctags completion provider, where we try to reduce the sorted set of completions. Our filtering in plugins/ctags/ide-ctags-completion-provider.c:238 sort of expects that the duplicated items would be in the same ctags file. This is not the case, since we often have 10 or more ctags indexes. We need to instead check a global hash table to see if an item exists. Likely solution: - Create a hashtable outside the index search loop (outer loop) - Inside the inner loop, hash the name and check if it exists in the hashtable - If so, skip the entry - Cleanup the hashtable after the search loop Implementation details: - You don't need to copy anything in the hashtable, keep it fast and light - g_hash_table_new(g_str_hash, g_str_equal) - The index keys will always be valid in this function, no need to track pointers to items either. use g_hash_table_contains() instead.
Created attachment 321096 [details] [review] patch to eliminate duplicates in ctags completions Hashtable is used to store completions .Duplicates in completions are avoided by checking keys for existence in that hashtable.
Review of attachment 321096 [details] [review]: Solution looks good, but needs some formatting cleanup ::: plugins/ctags/ide-ctags-completion-provider.c @@ -204,2 +205,3 @@ self->results = ide_completion_results_new (self->current_word); + completions = g_hash_table_new(g_str_hash, g_str_equal); We use a single space before opening parens in a function call @@ -236,3 +238,3 @@ IdeCtagsCompletionItem *item; - if (ide_str_equal0 (entry->name, last_name)) + if(g_hash_table_contains(completions,entry->name)) And after "if " @@ -237,3 +239,3 @@ - if (ide_str_equal0 (entry->name, last_name)) - continue; + if(g_hash_table_contains(completions,entry->name)) + continue; Looks like a spurious hard tab got in, 2 space tabs please @@ +243,1 @@ + g_hash_table_add(completions,entry->name); alignment here too
Created attachment 321115 [details] [review] patch to eliminate duplicates in ctags completions (modified) Attachment "patch to eliminate duplicates in ctags completions" is formatted.
Review of attachment 321115 [details] [review]: ::: plugins/ctags/ide-ctags-completion-provider.c @@ -175,2 +175,3 @@ guint i; guint j; + GHashTable *completions; It looks like the hash table is being leaked. Maybe use g_autoptr(GHashTable) completions = NULL;
Created attachment 321741 [details] [review] GHashtable memory leak is rectified.
Thanks! Pushed with followup commit to fix passing a const to g_hash_table_add().