[geany/geany] 1e74c1: Add keywords to the autocompletion list

Jiří Techet git-noreply at xxxxx
Fri Jul 22 17:41:31 UTC 2016


Branch:      refs/heads/keyword_complete
Author:      Jiří Techet <techet at gmail.com>
Committer:   Jiří Techet <techet at gmail.com>
Date:        Fri, 22 Jul 2016 17:41:31 UTC
Commit:      1e74c11aca41274d690d8da0b6e59b1247fbb222
             https://github.com/geany/geany/commit/1e74c11aca41274d690d8da0b6e59b1247fbb222

Log Message:
-----------
Add keywords to the autocompletion list

Construct a dummy TMTag array containing keywords, filter them similarly
to workspace and global tags and show them together with normal tags
in the autocomplete popup.

Could probably be optimized by not doing all the stuff all the time but
the CPU time spent on this is probably just a noise compared to all the
TM stuff.


Modified Paths:
--------------
    src/editor.c
    src/highlighting.c
    src/highlighting.h
    tagmanager/src/tm_workspace.c
    tagmanager/src/tm_workspace.h

Modified: src/editor.c
24 lines changed, 23 insertions(+), 1 deletions(-)
===================================================================
@@ -2082,14 +2082,36 @@ autocomplete_tags(GeanyEditor *editor, GeanyFiletype *ft, const gchar *root, gsi
 {
 	GPtrArray *tags;
 	gboolean found;
+	gchar **keywords;
+	gchar **keyword;
+	GPtrArray *keyword_array;
 
 	g_return_val_if_fail(editor, FALSE);
 
-	tags = tm_workspace_find_prefix(root, ft->lang, editor_prefs.autocompletion_max_entries);
+	/* Get keywords and create a dummy TMTag array from them. These tags are
+	 * then also searched when searching workspace */
+	keywords = highlighting_get_keywords(ft->id);
+	keyword_array = g_ptr_array_new_full(100, (GDestroyNotify)tm_tag_unref);
+	foreach_strv(keyword, keywords)
+	{
+		if (**keyword != '\0')
+		{
+			TMTag *tag = tm_tag_new();
+
+			tag->name = g_strdup(*keyword);
+			tag->lang = ft->lang;
+			g_ptr_array_add(keyword_array, tag);
+		}
+	}
+
+	tags = tm_workspace_find_prefix(root, keyword_array, ft->lang, editor_prefs.autocompletion_max_entries);
 	found = tags->len > 0;
 	if (found)
 		show_tags_list(editor, tags, rootlen);
+
 	g_ptr_array_free(tags, TRUE);
+	g_ptr_array_free(keyword_array, TRUE);
+	g_strfreev(keywords);
 
 	return found;
 }


Modified: src/highlighting.c
20 lines changed, 20 insertions(+), 0 deletions(-)
===================================================================
@@ -1776,3 +1776,23 @@ gboolean highlighting_is_code_style(gint lexer, gint style)
 	return !(highlighting_is_comment_style(lexer, style) ||
 		highlighting_is_string_style(lexer, style));
 }
+
+
+gchar **highlighting_get_keywords(GeanyFiletypeID filetype_id)
+{
+	GString *str = g_string_sized_new(1000);
+	gchar **keywords;
+	gchar **keyword_str;
+
+	foreach_strv(keyword_str, style_sets[filetype_id].keywords)
+	{
+		g_string_append(str, *keyword_str);
+		g_string_append_c(str, ' ');
+	}
+
+	keywords = g_strsplit(str->str, " ", -1);
+
+	g_string_free(str, TRUE);
+
+	return keywords;
+}


Modified: src/highlighting.h
2 lines changed, 2 insertions(+), 0 deletions(-)
===================================================================
@@ -63,6 +63,8 @@ void highlighting_free_styles(void);
 
 void highlighting_show_color_scheme_dialog(void);
 
+gchar **highlighting_get_keywords(GeanyFiletypeID filetype_id);
+
 #endif /* GEANY_PRIVATE */
 
 G_END_DECLS


Modified: tagmanager/src/tm_workspace.c
6 lines changed, 5 insertions(+), 1 deletions(-)
===================================================================
@@ -738,19 +738,23 @@ static void fill_find_tags_array_prefix(GPtrArray *dst, const GPtrArray *src,
 /* Returns tags with the specified prefix sorted by name. If there are several
  tags with the same name, only one of them appears in the resulting array.
  @param prefix The prefix of the tag to find.
+ @param additional_tags Additional unsorted tag array whose elements are also searched.
  @param lang Specifies the language(see the table in parsers.h) of the tags to be found,
              -1 for all.
  @param max_num The maximum number of tags to return.
  @return Array of matching tags sorted by their name.
 */
-GPtrArray *tm_workspace_find_prefix(const char *prefix, TMParserType lang, guint max_num)
+GPtrArray *tm_workspace_find_prefix(const char *prefix, GPtrArray *additional_tags, TMParserType lang, guint max_num)
 {
 	TMTagAttrType attrs[] = { tm_tag_attr_name_t, 0 };
 	GPtrArray *tags = g_ptr_array_new();
 
 	fill_find_tags_array_prefix(tags, theWorkspace->tags_array, prefix, lang, max_num);
 	fill_find_tags_array_prefix(tags, theWorkspace->global_tags, prefix, lang, max_num);
 
+	tm_tags_sort(additional_tags, attrs, FALSE, FALSE);
+	fill_find_tags_array_prefix(tags, additional_tags, prefix, lang, max_num);
+
 	tm_tags_sort(tags, attrs, TRUE, FALSE);
 	if (tags->len > max_num)
 		tags->len = max_num;


Modified: tagmanager/src/tm_workspace.h
2 lines changed, 1 insertions(+), 1 deletions(-)
===================================================================
@@ -55,7 +55,7 @@ gboolean tm_workspace_create_global_tags(const char *pre_process, const char **i
 GPtrArray *tm_workspace_find(const char *name, const char *scope, TMTagType type,
 	TMTagAttrType *attrs, TMParserType lang);
 
-GPtrArray *tm_workspace_find_prefix(const char *prefix, TMParserType lang, guint max_num);
+GPtrArray *tm_workspace_find_prefix(const char *prefix, GPtrArray *keyword_array, TMParserType lang, guint max_num);
 
 GPtrArray *tm_workspace_find_scope_members (TMSourceFile *source_file, const char *name,
 	gboolean function, gboolean member, const gchar *current_scope, gboolean search_namespace);



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