Branch: refs/heads/master Author: Jiří Techet techet@gmail.com Committer: Jiří Techet techet@gmail.com Date: Fri, 26 Feb 2016 00:09:59 UTC Commit: 77f6e98de8e50d0b9e270c113c8ba3b2828bbe19 https://github.com/geany/geany/commit/77f6e98de8e50d0b9e270c113c8ba3b2828bbe...
Log Message: ----------- Add scope completion for namespaces
Pop up scope completion dialog for namespaces too; e.g. for
boost::
show all symbols defined in the namespace. Determine whether the namespace scope completion should be used based on whether user typed a scope separator. If so, perform completion for namespaces before normal scope completion - this seems to work better e.g. for Scintilla where
Scintilla::
would otherwise pop up the varible sci instead of showing everything in the namespace (might be more questionable for languages where the scope separator is identical to the dereference operator like Java's "." but we have to make some choice anyway).
The performance seems to be reasonable - for the completion all tags have to be walked but after testing with big C++ projects like boost and Mozilla, the completion takes only something like 0.2s which is acceptable as the delay happens only on typing the scope completion separator and feels kind of expected.
Also tested with linux kernel sources which normally lack any scope information by hacking TM a bit and injecting 10-character scope for each tag - then the completion takes something over 0.5s.
Modified Paths: -------------- src/editor.c tagmanager/src/tm_workspace.c tagmanager/src/tm_workspace.h
Modified: src/editor.c 12 lines changed, 8 insertions(+), 4 deletions(-) =================================================================== @@ -711,6 +711,7 @@ static gboolean autocomplete_scope(GeanyEditor *editor, const gchar *root, gsize GPtrArray *tags; gboolean function = FALSE; gboolean member; + gboolean scope_sep_typed = FALSE; gboolean ret = FALSE; const gchar *current_scope; const gchar *context_sep = tm_tag_context_separator(ft->lang); @@ -729,10 +730,13 @@ static gboolean autocomplete_scope(GeanyEditor *editor, const gchar *root, gsize }
/* make sure to keep in sync with similar checks below */ - if (typed == '.') - pos -= 1; - else if (match_last_chars(sci, pos, context_sep)) + if (match_last_chars(sci, pos, context_sep)) + { pos -= strlen(context_sep); + scope_sep_typed = TRUE; + } + else if (typed == '.') + pos -= 1; else if ((ft->id == GEANY_FILETYPES_C || ft->id == GEANY_FILETYPES_CPP) && match_last_chars(sci, pos, "->")) pos -= 2; @@ -777,7 +781,7 @@ static gboolean autocomplete_scope(GeanyEditor *editor, const gchar *root, gsize if (symbols_get_current_scope(editor->document, ¤t_scope) == -1) current_scope = ""; tags = tm_workspace_find_scope_members(editor->document->tm_file, name, function, - member, current_scope); + member, current_scope, scope_sep_typed); if (tags) { GPtrArray *filtered = g_ptr_array_new();
Modified: tagmanager/src/tm_workspace.c 65 lines changed, 48 insertions(+), 17 deletions(-) =================================================================== @@ -1039,6 +1039,22 @@ find_scope_members_all(const GPtrArray *tags, const GPtrArray *searched_array, l }
+static GPtrArray *find_namespace_members_all(const GPtrArray *tags, const GPtrArray *searched_array, langType lang) +{ + GPtrArray *member_tags = NULL; + guint i; + + for (i = 0; i < tags->len && !member_tags; i++) + { + TMTag *tag = TM_TAG(tags->pdata[i]); + + member_tags = find_scope_members_tags(searched_array, tag, TRUE); + } + + return member_tags; +} + + /* Returns all member tags of a struct/union/class if the provided name is a variable of such a type or the name of the type. @param source_file TMSourceFile of the edited source file or NULL if not available @@ -1046,10 +1062,11 @@ find_scope_members_all(const GPtrArray *tags, const GPtrArray *searched_array, l @param function TRUE if the name is a name of a function @param member TRUE if invoked on class/struct member (e.g. after the last dot in foo.bar.) @param current_scope The current scope in the editor + @param search_namespace Whether to search the contents of namespace (e.g. after MyNamespace::) @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, - gboolean function, gboolean member, const gchar *current_scope) + gboolean function, gboolean member, const gchar *current_scope, gboolean search_namespace) { langType lang = source_file ? source_file->lang : -1; GPtrArray *tags, *member_tags = NULL; @@ -1059,26 +1076,40 @@ tm_workspace_find_scope_members (TMSourceFile *source_file, const char *name, ~(function_types | tm_tag_enumerator_t | tm_tag_namespace_t | tm_tag_package_t); TMTagAttrType sort_attr[] = {tm_tag_attr_name_t, 0};
- if (function) - tag_type = function_types; + if (search_namespace) + { + tags = tm_workspace_find(name, NULL, tm_tag_namespace_t, NULL, lang);
- /* tags corresponding to the variable/type name */ - tags = tm_workspace_find(name, NULL, tag_type, NULL, lang); + member_tags = find_namespace_members_all(tags, theWorkspace->tags_array, lang); + if (!member_tags) + member_tags = find_namespace_members_all(tags, theWorkspace->global_tags, lang); + + g_ptr_array_free(tags, TRUE); + }
- /* 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 - * file in case there are more of them. */ - if (source_file) - member_tags = find_scope_members_all(tags, source_file->tags_array, - lang, member, current_scope); - if (!member_tags) - member_tags = find_scope_members_all(tags, theWorkspace->tags_array, lang, - member, current_scope); if (!member_tags) - member_tags = find_scope_members_all(tags, theWorkspace->global_tags, lang, - member, current_scope); + { + if (function) + tag_type = function_types; + + /* tags corresponding to the variable/type name */ + tags = tm_workspace_find(name, NULL, tag_type, NULL, 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 + * file in case there are more of them. */ + if (source_file) + member_tags = find_scope_members_all(tags, source_file->tags_array, + lang, member, current_scope); + if (!member_tags) + member_tags = find_scope_members_all(tags, theWorkspace->tags_array, lang, + member, current_scope); + if (!member_tags) + member_tags = find_scope_members_all(tags, theWorkspace->global_tags, lang, + member, current_scope);
- g_ptr_array_free(tags, TRUE); + g_ptr_array_free(tags, TRUE); + }
tm_tags_dedup(member_tags, sort_attr, FALSE);
Modified: tagmanager/src/tm_workspace.h 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -61,7 +61,7 @@ GPtrArray *tm_workspace_find(const char *name, const char *scope, TMTagType type GPtrArray *tm_workspace_find_prefix(const char *prefix, langType 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 function, gboolean member, const gchar *current_scope, gboolean search_namespace);
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).