[geany/geany] ee3eee: Merge tm_workspace_find() and tm_workspace_find_scoped()
Jiří Techet
git-noreply at xxxxx
Thu Feb 11 14:35:47 UTC 2016
Branch: refs/heads/master
Author: Jiří Techet <techet at gmail.com>
Committer: Jiří Techet <techet at gmail.com>
Date: Tue, 14 Jul 2015 07:44:33 UTC
Commit: ee3eeeb758ff6519db5d82d4ed01a7e0ea45e9bd
https://github.com/geany/geany/commit/ee3eeeb758ff6519db5d82d4ed01a7e0ea45e9bd
Log Message:
-----------
Merge tm_workspace_find() and tm_workspace_find_scoped()
They are basically identical except:
1. _scoped() compares scope in addition
2. _scoped() is missing the C/CPP tag compatibility part
3. _scoped() allows returning just single result (unused)
4. _scoped() allows not searching in global tags (unused)
Since we now always put lang also under tag->lang, the match_langs()
function is not necessary.
Extend the add_filtered_tags() (and rename it to fill_find_tags_array()) to
perform the tm_tags_find(), compare the scope and add scope
as parameter of tm_workspace_find() and eliminate tm_workspace_find_scoped()
completely.
Modified Paths:
--------------
src/editor.c
tagmanager/src/tm_workspace.c
tagmanager/src/tm_workspace.h
Modified: src/editor.c
10 lines changed, 5 insertions(+), 5 deletions(-)
===================================================================
@@ -726,7 +726,7 @@ static void autocomplete_scope(GeanyEditor *editor)
if (!name)
return;
- tags = tm_workspace_find(name, tm_tag_max_t, NULL, FALSE, ft->lang);
+ tags = tm_workspace_find(name, NULL, tm_tag_max_t, NULL, FALSE, ft->lang);
g_free(name);
if (!tags || tags->len == 0)
return;
@@ -1849,7 +1849,7 @@ static gchar *find_calltip(const gchar *word, GeanyFiletype *ft)
g_return_val_if_fail(ft && word && *word, NULL);
/* use all types in case language uses wrong tag type e.g. python "members" instead of "methods" */
- tags = tm_workspace_find(word, tm_tag_max_t, attrs, FALSE, ft->lang);
+ tags = tm_workspace_find(word, NULL, tm_tag_max_t, attrs, FALSE, ft->lang);
if (tags->len == 0)
return NULL;
@@ -1859,8 +1859,8 @@ static gchar *find_calltip(const gchar *word, GeanyFiletype *ft)
(tag->type == tm_tag_class_t || tag->type == tm_tag_struct_t))
{
/* user typed e.g. 'new Classname(' so lookup D constructor Classname::this() */
- tags = tm_workspace_find_scoped("this", tag->name,
- arg_types, attrs, FALSE, ft->lang, TRUE);
+ tags = tm_workspace_find("this", tag->name,
+ arg_types, attrs, FALSE, ft->lang);
if (tags->len == 0)
return NULL;
}
@@ -2041,7 +2041,7 @@ autocomplete_tags(GeanyEditor *editor, const gchar *root, gsize rootlen)
doc = editor->document;
- tags = tm_workspace_find(root, tm_tag_max_t, attrs, TRUE, doc->file_type->lang);
+ tags = tm_workspace_find(root, NULL, tm_tag_max_t, attrs, TRUE, doc->file_type->lang);
if (tags)
{
show_tags_list(editor, tags, rootlen);
Modified: tagmanager/src/tm_workspace.c
123 lines changed, 20 insertions(+), 103 deletions(-)
===================================================================
@@ -672,11 +672,17 @@ gboolean tm_workspace_create_global_tags(const char *pre_process, const char **i
}
-static void add_filtered_tags(GPtrArray *tags, TMTag **matches, guint tagCount,
- TMTagType type, langType lang)
+static guint fill_find_tags_array(GPtrArray *dst, const GPtrArray *src,
+ const char *name, const char *scope, TMTagType type, gboolean partial, langType lang)
{
+ TMTag **matches;
guint tagIter;
+ guint tagCount;
+
+ if (!src || !dst || !name || !*name)
+ return 0;
+ matches = tm_tags_find(src, name, partial, TRUE, &tagCount);
for (tagIter = 0; tagIter < tagCount; ++tagIter)
{
gint tag_lang = (*matches)->lang;
@@ -689,16 +695,20 @@ static void add_filtered_tags(GPtrArray *tags, TMTag **matches, guint tagCount,
tag_lang_alt = TM_PARSER_C;
if ((type & (*matches)->type) &&
- (lang == -1 || tag_lang == lang || tag_lang_alt == lang))
- g_ptr_array_add(tags, *matches);
+ (lang == -1 || tag_lang == lang || tag_lang_alt == lang) &&
+ (!scope || g_strcmp0((*matches)->scope, scope) == 0))
+ g_ptr_array_add(dst, *matches);
matches++;
}
+
+ return dst->len;
}
/* Returns all matching tags found in the workspace.
@param name The name of the tag to find.
+ @param scope The scope name of the tag to find, or NULL.
@param type The tag types to return (TMTagType). Can be a bitmask.
@param attrs The attributes to sort and dedup on (0 terminated integer array).
@param partial Whether partial match is allowed.
@@ -706,25 +716,18 @@ static void add_filtered_tags(GPtrArray *tags, TMTag **matches, guint tagCount,
-1 for all
@return Array of matching tags. Do not free() it since it is a static member.
*/
-const GPtrArray *tm_workspace_find(const char *name, TMTagType type, TMTagAttrType *attrs,
- gboolean partial, langType lang)
+const GPtrArray *tm_workspace_find(const char *name, const char *scope, TMTagType type,
+ TMTagAttrType *attrs, gboolean partial, langType lang)
{
static GPtrArray *tags = NULL;
- TMTag **matches;
- guint tagCount;
-
- if (!name || !*name)
- return NULL;
if (tags)
g_ptr_array_set_size(tags, 0);
else
tags = g_ptr_array_new();
- matches = tm_tags_find(theWorkspace->tags_array, name, partial, TRUE, &tagCount);
- add_filtered_tags(tags, matches, tagCount, type, lang);
- matches = tm_tags_find(theWorkspace->global_tags, name, partial, TRUE, &tagCount);
- add_filtered_tags(tags, matches, tagCount, type, lang);
+ fill_find_tags_array(tags, theWorkspace->tags_array, name, scope, type, partial, lang);
+ fill_find_tags_array(tags, theWorkspace->global_tags, name, scope, type, partial, lang);
if (attrs)
tm_tags_sort(tags, attrs, TRUE, FALSE);
@@ -733,92 +736,6 @@ const GPtrArray *tm_workspace_find(const char *name, TMTagType type, TMTagAttrTy
}
-static gboolean match_langs(gint lang, const TMTag *tag)
-{
- if (tag->file)
- { /* workspace tag */
- if (lang == tag->file->lang)
- return TRUE;
- }
- else
- { /* global tag */
- if (lang == tag->lang)
- return TRUE;
- }
- return FALSE;
-}
-
-
-/* scope can be NULL.
- * lang can be -1 */
-static guint
-fill_find_tags_array (GPtrArray *dst, const GPtrArray *src,
- const char *name, const char *scope, TMTagType type, gboolean partial,
- gint lang, gboolean first)
-{
- TMTag **match;
- guint tagIter, count;
-
- if ((!src) || (!dst) || (!name) || (!*name))
- return 0;
-
- match = tm_tags_find (src, name, partial, TRUE, &count);
- if (count && match && *match)
- {
- for (tagIter = 0; tagIter < count; ++tagIter)
- {
- if (! scope || (match[tagIter]->scope &&
- 0 == strcmp(match[tagIter]->scope, scope)))
- {
- if (type & match[tagIter]->type)
- if (lang == -1 || match_langs(lang, match[tagIter]))
- {
- g_ptr_array_add (dst, match[tagIter]);
- if (first)
- break;
- }
- }
- }
- }
- return dst->len;
-}
-
-
-/* Returns all matching tags found in the workspace. Adapted from tm_workspace_find, Anjuta 2.02
- @param name The name of the tag to find.
- @param scope The scope name of the tag to find, or NULL.
- @param type The tag types to return (TMTagType). Can be a bitmask.
- @param attrs The attributes to sort and dedup on (0 terminated integer array).
- @param partial Whether partial match is allowed.
- @param lang Specifies the language(see the table in parsers.h) of the tags to be found,
- -1 for all
- @return Array of matching tags. Do not free() it since it is a static member.
-*/
-const GPtrArray *
-tm_workspace_find_scoped (const char *name, const char *scope, TMTagType type,
- TMTagAttrType *attrs, gboolean partial, langType lang, gboolean global_search)
-{
- static GPtrArray *tags = NULL;
-
- if (tags)
- g_ptr_array_set_size (tags, 0);
- else
- tags = g_ptr_array_new ();
-
- fill_find_tags_array (tags, theWorkspace->tags_array,
- name, scope, type, partial, lang, FALSE);
- if (global_search)
- {
- /* for a scoped tag, I think we always want the same language */
- fill_find_tags_array (tags, theWorkspace->global_tags,
- name, scope, type, partial, lang, FALSE);
- }
- if (attrs)
- tm_tags_sort (tags, attrs, TRUE, FALSE);
- return tags;
-}
-
-
static int
find_scope_members_tags (const GPtrArray * all, GPtrArray * tags,
const langType langJava, const char *name,
@@ -971,7 +888,7 @@ tm_workspace_find_scope_members (const GPtrArray * file_tags, const char *name,
{
g_ptr_array_set_size (tags, 0);
got = fill_find_tags_array (tags, file_tags,
- new_name, NULL, types, FALSE, -1, FALSE);
+ new_name, NULL, types, FALSE, -1);
}
if (got)
{
@@ -983,7 +900,7 @@ tm_workspace_find_scope_members (const GPtrArray * file_tags, const char *name,
tm_tag_attr_name_t, tm_tag_attr_type_t,
tm_tag_attr_none_t
};
- tags2 = tm_workspace_find (new_name, types, attrs, FALSE, -1);
+ tags2 = tm_workspace_find (new_name, NULL, types, attrs, FALSE, -1);
}
if ((tags2) && (tags2->len == 1) && (tag = TM_TAG (tags2->pdata[0])))
Modified: tagmanager/src/tm_workspace.h
8 lines changed, 2 insertions(+), 6 deletions(-)
===================================================================
@@ -54,12 +54,8 @@ gboolean tm_workspace_load_global_tags(const char *tags_file, gint mode);
gboolean tm_workspace_create_global_tags(const char *pre_process, const char **includes,
int includes_count, const char *tags_file, int lang);
-const GPtrArray *tm_workspace_find(const char *name, TMTagType type, TMTagAttrType *attrs,
- gboolean partial, langType lang);
-
-const GPtrArray *
-tm_workspace_find_scoped (const char *name, const char *scope, TMTagType type,
- TMTagAttrType *attrs, gboolean partial, langType lang, gboolean global_search);
+const GPtrArray *tm_workspace_find(const char *name, const char *scope, TMTagType type,
+ TMTagAttrType *attrs, gboolean partial, langType lang);
const GPtrArray *tm_workspace_find_scope_members(const GPtrArray *file_tags,
const char *scope_name,
--------------
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