@kugel- requested changes on this pull request.

I might have overlooked, but is there something that prevents this logic to be applied to header files (if such avoidance even wanted)?

I can imagine a header file foo.h that include a identically-named file, either using #include_next <foo.h> or with include path trickery.

Actually thinking about it, it might even make sense to sort tags of the corresponding source file earlier, when editing a header file. For example when I want to create a declaration in a header file it's likely to be a function that might be already implemented in the corresponding source file.


In src/tagmanager/tm_workspace.c:

> @@ -742,9 +797,54 @@ static void fill_find_tags_array_prefix(GPtrArray *dst, const char *name,
 }
 
 
+/* fill 'includes' with the included files except the header corresponding
+ * to the current file which is returned in 'header' */
+static void fill_includes(TMSourceFile *source, TMSourceFile **header, GHashTable *includes)

I would find it idiomatic to make this get_includes() that returns the included files list.

Also, I find it strange that the corresponding header is excluded from the included files list. I think it wouldn't hurt because sort_found_tags() is special-casing the corresponding header anyway and might make this function be useful in other situations as well.


In src/tagmanager/tm_workspace.c:

> +
+	for (i = 0; i < headers->len; i++)
+	{
+		TMTag *hdr_tag = headers->pdata[i];
+		gchar *hdr_name = g_path_get_basename(hdr_tag->name);
+		GPtrArray *tm_files = g_hash_table_lookup(theWorkspace->source_file_map, hdr_name);
+
+		if (tm_files && tm_files->len > 0)
+		{
+			TMSourceFile *hdr = tm_files->pdata[0];
+			gchar **hdr_comps = g_strsplit(hdr->short_name, ".", 2);
+
+			if (*header == NULL && g_strcmp0(hdr_comps[0], src_comps[0]) == 0)
+				*header = hdr;
+			else
+				g_hash_table_add(includes, hdr);

I'm missing hash collision detection. The ptr array source_file_map might contain TMSourceFiles with different basenames that have the same hash value. So here you'd need to check if the TMSourceFile matches with the header tag.


In src/tagmanager/tm_workspace.c:

> @@ -768,6 +871,16 @@ static gint sort_found_tags(gconstpointer a, gconstpointer b, gpointer user_data
 		return -1;
 	else if (t2->file == info->file && t1->file != info->file)
 		return 1;
+	else if (info->header_file &&
+			 t1->file == info->header_file && t2->file != info->header_file)

Err, if t1 is the corresponding header, t2 can't be (can it?). The && t2->file ... part confuses me and could be left out, right?

Same below.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <geany/geany/pull/3269/review/1101466250@github.com>