[geany/geany] 140a7b: When extracting members, get them from single file only

Jiří Techet git-noreply at xxxxx
Thu Feb 11 14:35:50 UTC 2016


Branch:      refs/heads/master
Author:      Jiří Techet <techet at gmail.com>
Committer:   Jiří Techet <techet at gmail.com>
Date:        Sun, 10 Jan 2016 11:31:46 UTC
Commit:      140a7b6617e89dfcb31d876364d62b3902af0d3c
             https://github.com/geany/geany/commit/140a7b6617e89dfcb31d876364d62b3902af0d3c

Log Message:
-----------
When extracting members, get them from single file only

The previous commit fixed the situation when e.g. anon_struct_0 was in the
current file by checking the current file first.

In the case the struct type definition isn't found in the current file,
at the moment we get all members from all anon_struct_0 which can be a
really long list. This list isn't very helpful to users because all the
members from all the structs are mixed. Moreover, not all possible members
are in the list because there are e.g. just members from anon_struct_0 but
not from anon_struct_1 etc. which from the point of view of this function
is a different type.

Instead, restrict the returned members to just a single file (anonymous
structs have unique name per file so it means there will be just one
from the file). Of course the picked file can be wrong and the returned
members might be from a different struct the user wanted but at least
the list will make more sense to users.


Modified Paths:
--------------
    tagmanager/src/tm_workspace.c

Modified: tagmanager/src/tm_workspace.c
23 lines changed, 21 insertions(+), 2 deletions(-)
===================================================================
@@ -761,6 +761,25 @@ GPtrArray *tm_workspace_find(const char *name, const char *scope, TMTagType type
 }
 
 
+static void add_member(GPtrArray * tags, TMTag *tag)
+{
+	gboolean add = TRUE;
+
+	if (tags->len > 0)
+	{
+		TMTag *last_tag = TM_TAG(tags->pdata[tags->len-1]);
+		/* add only if it's from the same file - this prevents mixing tags from
+		 * structs with identical name (typically the anonymous ones) so we
+		 * only get members from a single one. For workspace tags it adds
+		 * all members because there's no file associated. */
+		add = last_tag->file == tag->file;
+	}
+	if (add)
+		/* the first file name "wins" */
+		g_ptr_array_add (tags, tag);
+}
+
+
 static int
 find_scope_members_tags (const GPtrArray * all, GPtrArray * tags,
 						 const char *name, langType lang)
@@ -795,7 +814,7 @@ find_scope_members_tags (const GPtrArray * all, GPtrArray * tags,
 			scope = tag->scope;
 			if (scope && 0 == strcmp (name, scope))
 			{
-				g_ptr_array_add (tags, tag);
+				add_member (tags, tag);
 				continue;
 			}
 			s_backup = NULL;
@@ -862,7 +881,7 @@ find_scope_members_tags (const GPtrArray * all, GPtrArray * tags,
 			}
 			if (j == local->len)
 			{
-				g_ptr_array_add (tags, tag);
+				add_member (tags, tag);
 			}
 		}
 	}



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list