[geany/geany] e01225: Perform scope autocompletion based on function return types
Jiří Techet
git-noreply at xxxxx
Thu Feb 11 14:35:55 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:36:08 UTC
Commit: e0122592d95f8cd5347729c3d15c05c40094edcd
https://github.com/geany/geany/commit/e0122592d95f8cd5347729c3d15c05c40094edcd
Log Message:
-----------
Perform scope autocompletion based on function return types
We just need to skip the (...) and perform autocompletion as before.
Shift pos by 1 in the whole function so we don't have to look 2 characters
back (makes the function easier to read).
Functions contain pointers in their return values - remove them before
searching for the type.
Also restrict the searched variable/function/type tags a bit only to
types which make sense for the search.
Modified Paths:
--------------
src/editor.c
tagmanager/src/tm_workspace.c
tagmanager/src/tm_workspace.h
Modified: src/editor.c
38 lines changed, 29 insertions(+), 9 deletions(-)
===================================================================
@@ -707,31 +707,51 @@ static void autocomplete_scope(GeanyEditor *editor)
gchar *name;
GeanyFiletype *ft = editor->document->file_type;
GPtrArray *tags;
+ gboolean function = FALSE;
- if (ft->id == GEANY_FILETYPES_C || ft->id == GEANY_FILETYPES_CPP ||
+ if (typed == '.')
+ pos -= 1;
+ else if (ft->id == GEANY_FILETYPES_C || ft->id == GEANY_FILETYPES_CPP ||
ft->id == GEANY_FILETYPES_PHP || ft->id == GEANY_FILETYPES_RUST)
{
if (match_last_chars(sci, pos, "::"))
- pos--;
+ pos-=2;
else if ((ft->id == GEANY_FILETYPES_C || ft->id == GEANY_FILETYPES_CPP) &&
match_last_chars(sci, pos, "->"))
- pos--;
- else if (ft->id == GEANY_FILETYPES_CPP && match_last_chars(sci, pos, "->*"))
pos-=2;
- else if (typed != '.')
+ else if (ft->id == GEANY_FILETYPES_CPP && match_last_chars(sci, pos, "->*"))
+ pos-=3;
+ else
return;
}
- else if (typed != '.')
+ else
return;
/* allow for a space between word and operator */
- while (pos >= 2 && isspace(sci_get_char_at(sci, pos - 2)))
+ while (pos > 0 && isspace(sci_get_char_at(sci, pos - 1)))
pos--;
- name = editor_get_word_at_pos(editor, pos - 1, NULL);
+
+ /* if function, skip to matching brace */
+ if (pos > 0 && sci_get_char_at(sci, pos - 1) == ')')
+ {
+ gint brace_pos = sci_find_matching_brace(sci, pos - 1);
+
+ if (brace_pos != -1)
+ {
+ pos = brace_pos;
+ function = TRUE;
+ }
+
+ /* allow for a space between opening brace and function name */
+ while (pos > 0 && isspace(sci_get_char_at(sci, pos - 1)))
+ pos--;
+ }
+
+ name = editor_get_word_at_pos(editor, pos, NULL);
if (!name)
return;
- tags = tm_workspace_find_scope_members(editor->document->tm_file, name);
+ tags = tm_workspace_find_scope_members(editor->document->tm_file, name, function);
if (tags)
{
show_tags_list(editor, tags, 0);
Modified: tagmanager/src/tm_workspace.c
22 lines changed, 19 insertions(+), 3 deletions(-)
===================================================================
@@ -895,7 +895,15 @@ find_scope_members_all(const GPtrArray *tags, const GPtrArray *searched_array, l
if (tag->type & types) /* type: namespace search */
member_tags = find_scope_members(searched_array, tag->name, lang, TRUE);
else if (tag->var_type) /* variable: scope search */
- member_tags = find_scope_members(searched_array, tag->var_type, lang, FALSE);
+ {
+ gchar *tag_type = g_strdup(tag->var_type);
+
+ /* remove pointers in case the type contains them */
+ g_strdelimit(tag_type, "*^", ' ');
+ g_strstrip(tag_type);
+ member_tags = find_scope_members(searched_array, tag_type, lang, FALSE);
+ g_free(tag_type);
+ }
}
return member_tags;
@@ -906,15 +914,23 @@ find_scope_members_all(const GPtrArray *tags, const GPtrArray *searched_array, l
of such a type or the name of the type.
@param source_file TMSourceFile of the edited source file or NULL if not available
@param name Name of the variable/type whose members are searched
+ @param function TRUE if the name is a name of a function
@return A GPtrArray of TMTag pointers to struct/union/class members or NULL when not found */
GPtrArray *
-tm_workspace_find_scope_members (TMSourceFile *source_file, const char *name)
+tm_workspace_find_scope_members (TMSourceFile *source_file, const char *name, gboolean function)
{
langType lang = source_file ? source_file->lang : -1;
GPtrArray *tags, *member_tags = NULL;
+ TMTagType tag_type = tm_tag_max_t &
+ ~(tm_tag_enumerator_t | tm_tag_namespace_t | tm_tag_package_t |
+ tm_tag_macro_t | tm_tag_macro_with_arg_t |
+ tm_tag_function_t | tm_tag_method_t);
+
+ if (function)
+ tag_type = tm_tag_function_t | tm_tag_method_t;
/* tags corresponding to the variable/type name */
- tags = tm_workspace_find(name, NULL, tm_tag_max_t, NULL, FALSE, lang);
+ tags = tm_workspace_find(name, NULL, tag_type, NULL, FALSE, lang);
/* Start searching inside the source file, continue with workspace tags and
* end with global tags. This way we find the "closest" tag to the current
Modified: tagmanager/src/tm_workspace.h
3 lines changed, 2 insertions(+), 1 deletions(-)
===================================================================
@@ -58,7 +58,8 @@ 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, gboolean partial, langType lang);
-GPtrArray *tm_workspace_find_scope_members (TMSourceFile *source_file, const char *name);
+GPtrArray *tm_workspace_find_scope_members (TMSourceFile *source_file, const char *name,
+ gboolean function);
void tm_workspace_add_source_file_noupdate(TMSourceFile *source_file);
--------------
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