[geany/geany] c84c41: Don't show the goto popup for typedef synonyms

Jiří Techet git-noreply at xxxxx
Sat Mar 5 10:10:38 UTC 2016


Branch:      refs/heads/master
Author:      Jiří Techet <techet at gmail.com>
Committer:   Jiří Techet <techet at gmail.com>
Date:        Sat, 05 Mar 2016 10:10:38 UTC
Commit:      c84c41e44a69727a51abebf58936b65bd80659c6
             https://github.com/geany/geany/commit/c84c41e44a69727a51abebf58936b65bd80659c6

Log Message:
-----------
Don't show the goto popup for typedef synonyms

For instance when performing goto tag for Foo and Foo is defined as

typedef struct Foo {} Foo;

go immediately to the struct location without showing the goto popup with
both the struct name and typedef. When there are more occurrences of the
name, filter the list and don't show the synonyms in the popup.

In addition, if the cursor is on the same line as the typedef, go to
the struct and vice versa.

Note the missing

g_strcmp0(second->var_type, first->name) == 0

in the check - in this particular case we won't get the type to which the
typedef refers inside var_type because at the time the typedef tag is
generated in c.c the struct tag doesn't exist yet. On the other hand
there's no second->var_type == NULL either because this behaviour seems
to be rather implementation-specific and might easily change in the
future. The existing checks are probably sufficient for the real-world
code.


Modified Paths:
--------------
    src/symbols.c

Modified: src/symbols.c
31 lines changed, 27 insertions(+), 4 deletions(-)
===================================================================
@@ -2075,12 +2075,13 @@ static gboolean goto_tag(const gchar *name, gboolean definition)
 {
 	const TMTagType forward_types = tm_tag_prototype_t | tm_tag_externvar_t;
 	TMTagType type;
-	TMTag *tmtag = NULL;
+	TMTag *tmtag, *last_tag;
 	GeanyDocument *old_doc = document_get_current();
 	gboolean found = FALSE;
 	const GPtrArray *all_tags;
-	GPtrArray *workspace_tags;
+	GPtrArray *workspace_tags, *filtered_tags;
 	guint i;
+	guint current_line = sci_get_current_line(old_doc->editor->sci) + 1;
 
 	/* goto tag definition: all except prototypes / forward declarations / externs */
 	type = (definition) ? tm_tag_max_t - forward_types : forward_types;
@@ -2094,6 +2095,29 @@ static gboolean goto_tag(const gchar *name, gboolean definition)
 			g_ptr_array_add(workspace_tags, tmtag);
 	}
 
+	/* If there are typedefs of e.g. a struct such as "typedef struct Foo {} Foo;",
+	 * keep just one of the names in the list - when the cursor is on the struct
+	 * name, keep the typename, otherwise keep the struct name. */
+	last_tag = NULL;
+	filtered_tags = g_ptr_array_new();
+	foreach_ptr_array(tmtag, i, workspace_tags)
+	{
+		if (last_tag != NULL && last_tag->file == tmtag->file &&
+			last_tag->type != tm_tag_typedef_t && tmtag->type == tm_tag_typedef_t)
+		{
+			if (last_tag->line == current_line && filtered_tags->len > 0)
+				/* if cursor on struct, replace struct with the typedef */
+				filtered_tags->pdata[filtered_tags->len-1] = tmtag;
+			/* if cursor anywhere else, use struct (already added) and discard typedef */
+		}
+		else
+			g_ptr_array_add(filtered_tags, tmtag);
+
+		last_tag = tmtag;
+	}
+	g_ptr_array_free(workspace_tags, TRUE);
+	workspace_tags = filtered_tags;
+
 	if (workspace_tags->len == 1)
 	{
 		GeanyDocument *new_doc;
@@ -2105,8 +2129,7 @@ static gboolean goto_tag(const gchar *name, gboolean definition)
 		if (new_doc)
 		{
 			/* If we are already on the tag line, swap definition/declaration */
-			if (new_doc == old_doc &&
-				tmtag->line == (guint)sci_get_current_line(old_doc->editor->sci) + 1)
+			if (new_doc == old_doc && tmtag->line == current_line)
 			{
 				if (goto_tag(name, !definition))
 					found = TRUE;



--------------
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