[geany/geany] 64f6aa: Move function/variable formatting into tm_parser

Jiří Techet git-noreply at xxxxx
Sun Jan 9 22:32:40 UTC 2022


Branch:      refs/heads/master
Author:      Jiří Techet <techet at gmail.com>
Committer:   Enrico Tröger <enrico.troeger at uvena.de>
Date:        Sun, 09 Jan 2022 22:32:40 UTC
Commit:      64f6aa66e69747adff9fb56bd1a6d63935dfe781
             https://github.com/geany/geany/commit/64f6aa66e69747adff9fb56bd1a6d63935dfe781

Log Message:
-----------
Move function/variable formatting into tm_parser


Modified Paths:
--------------
    src/editor.c
    src/editor.h
    src/symbols.c
    src/tagmanager/tm_parser.c
    src/tagmanager/tm_parser.h

Modified: src/editor.c
66 lines changed, 4 insertions(+), 62 deletions(-)
===================================================================
@@ -1847,53 +1847,6 @@ static gint find_start_bracket(ScintillaObject *sci, gint pos)
 }
 
 
-static gboolean append_calltip(GString *str, const TMTag *tag, GeanyFiletypeID ft_id)
-{
-	if (! tag->arglist)
-		return FALSE;
-
-	if (ft_id != GEANY_FILETYPES_PASCAL && ft_id != GEANY_FILETYPES_GO)
-	{	/* usual calltips: "retval tagname (arglist)" */
-		if (tag->var_type)
-		{
-			guint i;
-
-			g_string_append(str, tag->var_type);
-			for (i = 0; i < tag->pointerOrder; i++)
-			{
-				g_string_append_c(str, '*');
-			}
-			g_string_append_c(str, ' ');
-		}
-		if (tag->scope)
-		{
-			const gchar *cosep = symbols_get_context_separator(ft_id);
-
-			g_string_append(str, tag->scope);
-			g_string_append(str, cosep);
-		}
-		g_string_append(str, tag->name);
-		g_string_append_c(str, ' ');
-		g_string_append(str, tag->arglist);
-	}
-	else
-	{	/* special case Pascal/Go calltips: "tagname (arglist) : retval"
-		 * (with ':' omitted for Go) */
-		g_string_append(str, tag->name);
-		g_string_append_c(str, ' ');
-		g_string_append(str, tag->arglist);
-
-		if (!EMPTY(tag->var_type))
-		{
-			g_string_append(str, ft_id == GEANY_FILETYPES_PASCAL ? " : " : " ");
-			g_string_append(str, tag->var_type);
-		}
-	}
-
-	return TRUE;
-}
-
-
 static gchar *find_calltip(const gchar *word, GeanyFiletype *ft)
 {
 	GPtrArray *tags;
@@ -1964,10 +1917,13 @@ static gchar *find_calltip(const gchar *word, GeanyFiletype *ft)
 
 		if (str == NULL)
 		{
+			gchar *f = tm_parser_format_function(tag->lang, tag->name,
+				tag->arglist, tag->var_type, tag->scope);
 			str = g_string_new(NULL);
 			if (calltip.tag_index > 0)
 				g_string_prepend(str, "\001 ");	/* up arrow */
-			append_calltip(str, tag, FILETYPE_ID(ft));
+			g_string_append(str, f);
+			g_free(f);
 		}
 		else /* add a down arrow */
 		{
@@ -2061,20 +2017,6 @@ gboolean editor_show_calltip(GeanyEditor *editor, gint pos)
 }
 
 
-gchar *editor_get_calltip_text(GeanyEditor *editor, const TMTag *tag)
-{
-	GString *str;
-
-	g_return_val_if_fail(editor != NULL, NULL);
-
-	str = g_string_new(NULL);
-	if (append_calltip(str, tag, editor->document->file_type->id))
-		return g_string_free(str, FALSE);
-	else
-		return g_string_free(str, TRUE);
-}
-
-
 /* Current document & global tags autocompletion */
 static gboolean
 autocomplete_tags(GeanyEditor *editor, GeanyFiletype *ft, const gchar *root, gsize rootlen)


Modified: src/editor.h
2 lines changed, 0 insertions(+), 2 deletions(-)
===================================================================
@@ -325,8 +325,6 @@ void editor_set_indentation_guides(GeanyEditor *editor);
 
 void editor_apply_update_prefs(GeanyEditor *editor);
 
-gchar *editor_get_calltip_text(GeanyEditor *editor, const TMTag *tag);
-
 void editor_toggle_fold(GeanyEditor *editor, gint line, gint modifiers);
 
 #endif /* GEANY_PRIVATE */


Modified: src/symbols.c
11 lines changed, 3 insertions(+), 8 deletions(-)
===================================================================
@@ -946,18 +946,13 @@ static const gchar *get_symbol_name(GeanyDocument *doc, const TMTag *tag, gboole
 
 static gchar *get_symbol_tooltip(GeanyDocument *doc, const TMTag *tag)
 {
-	gchar *utf8_name = editor_get_calltip_text(doc->editor, tag);
+	gchar *utf8_name = tm_parser_format_function(tag->lang, tag->name,
+		tag->arglist, tag->var_type, tag->scope);
 
 	if (!utf8_name && tag->var_type &&
 		tag->type & (tm_tag_field_t | tm_tag_member_t | tm_tag_variable_t | tm_tag_externvar_t))
 	{
-		if (tag->lang != TM_PARSER_PASCAL && tag->lang != TM_PARSER_GO)
-			utf8_name = g_strconcat(tag->var_type, " ", tag->name, NULL);
-		else
-		{
-			const gchar *sep = tag->lang == TM_PARSER_PASCAL ? " : " : " ";
-			utf8_name = g_strconcat(tag->name, sep, tag->var_type, NULL);
-		}
+		utf8_name = tm_parser_format_variable(tag->lang, tag->name, tag->var_type);
 	}
 
 	/* encodings_convert_to_utf8_from_charset() fails with charset "None", so skip conversion


Modified: src/tagmanager/tm_parser.c
70 lines changed, 70 insertions(+), 0 deletions(-)
===================================================================
@@ -882,6 +882,76 @@ gboolean tm_parser_enable_kind(TMParserType lang, gchar kind)
 }
 
 
+gchar *tm_parser_format_variable(TMParserType lang, const gchar *name, const gchar *type)
+{
+	if (!type)
+		return NULL;
+
+	switch (lang)
+	{
+		case TM_PARSER_PASCAL:
+			return g_strconcat(name, " : ", type, NULL);
+		case TM_PARSER_GO:
+			return g_strconcat(name, " ", type, NULL);
+		default:
+			return g_strconcat(type, " ", name, NULL);
+	}
+}
+
+
+gchar *tm_parser_format_function(TMParserType lang, const gchar *fname, const gchar *args,
+	const gchar *retval, const gchar *scope)
+{
+	GString *str;
+
+	if (!args)  /* not a function */
+		return NULL;
+
+	str = g_string_new(NULL);
+
+	if (scope)
+	{
+		g_string_append(str, scope);
+		g_string_append(str, tm_parser_context_separator(lang));
+	}
+	g_string_append(str, fname);
+	g_string_append_c(str, ' ');
+	g_string_append(str, args);
+
+	if (retval)
+	{
+		switch (lang)
+		{
+			case TM_PARSER_PASCAL:
+			case TM_PARSER_GO:
+			{
+				/* retval after function */
+				const gchar *sep;
+				switch (lang)
+				{
+					case TM_PARSER_PASCAL:
+						sep = " : ";
+						break;
+					default:
+						sep = " ";
+						break;
+				}
+				g_string_append(str, sep);
+				g_string_append(str, retval);
+				break;
+			}
+			default:
+				/* retval before function */
+				g_string_prepend_c(str, ' ');
+				g_string_prepend(str, retval);
+				break;
+		}
+	}
+
+	return g_string_free(str, FALSE);
+}
+
+
 const gchar *tm_parser_context_separator(TMParserType lang)
 {
 	switch (lang)


Modified: src/tagmanager/tm_parser.h
5 lines changed, 5 insertions(+), 0 deletions(-)
===================================================================
@@ -130,6 +130,11 @@ gboolean tm_parser_enable_role(TMParserType lang, gchar kind);
 
 gboolean tm_parser_enable_kind(TMParserType lang, gchar kind);
 
+gchar *tm_parser_format_variable(TMParserType lang, const gchar *name, const gchar *type);
+
+gchar *tm_parser_format_function(TMParserType lang, const gchar *fname, const gchar *args,
+	const gchar *retval, const gchar *scope);
+
 const gchar *tm_parser_context_separator(TMParserType lang);
 
 gboolean tm_parser_has_full_context(TMParserType lang);



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