Move some functions from tm_tag to tm_parser namespace
Those don't actually work on tags, so it makes more sense to have them in the parser namespace.
This commit is contained in:
parent
198a0cf2ba
commit
05fce1a2ee
6
HACKING
6
HACKING
@ -673,9 +673,9 @@ FooKinds to the appropriate TMTagType, and add the corresponding
|
|||||||
MAP_ENTRY(FOO) to parser_map.
|
MAP_ENTRY(FOO) to parser_map.
|
||||||
(You may want to make the symbols.c change before doing this).
|
(You may want to make the symbols.c change before doing this).
|
||||||
|
|
||||||
In src/tagmanager/tm_tag.c:
|
In src/tagmanager/tm_parser.c:
|
||||||
Update tm_tag_context_separator() and tm_tag_has_full_context() to handle the
|
Update tm_parser_context_separator() and tm_parser_has_full_context() to
|
||||||
new parser if applicable, by adding a TM_PARSER_FOO case entry.
|
handle the new parser if applicable, by adding a TM_PARSER_FOO case entry.
|
||||||
|
|
||||||
In filetypes.c, init_builtin_filetypes():
|
In filetypes.c, init_builtin_filetypes():
|
||||||
Set the 2nd argument of the FT_INIT() macro for this filetype to FOO.
|
Set the 2nd argument of the FT_INIT() macro for this filetype to FOO.
|
||||||
|
@ -706,7 +706,7 @@ static gboolean autocomplete_scope(GeanyEditor *editor, const gchar *root, gsize
|
|||||||
gboolean scope_sep_typed = FALSE;
|
gboolean scope_sep_typed = FALSE;
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
const gchar *current_scope;
|
const gchar *current_scope;
|
||||||
const gchar *context_sep = tm_tag_context_separator(ft->lang);
|
const gchar *context_sep = tm_parser_context_separator(ft->lang);
|
||||||
|
|
||||||
if (autocomplete_scope_shown)
|
if (autocomplete_scope_shown)
|
||||||
{
|
{
|
||||||
|
@ -229,7 +229,7 @@ GString *symbols_find_typenames_as_string(TMParserType lang, gboolean global)
|
|||||||
tag = TM_TAG(typedefs->pdata[j]);
|
tag = TM_TAG(typedefs->pdata[j]);
|
||||||
tag_lang = tag->lang;
|
tag_lang = tag->lang;
|
||||||
|
|
||||||
if (tag->name && tm_tag_langs_compatible(lang, tag_lang) &&
|
if (tag->name && tm_parser_langs_compatible(lang, tag_lang) &&
|
||||||
strcmp(tag->name, last_name) != 0)
|
strcmp(tag->name, last_name) != 0)
|
||||||
{
|
{
|
||||||
if (j != 0)
|
if (j != 0)
|
||||||
@ -256,7 +256,7 @@ GString *symbols_find_typenames_as_string(TMParserType lang, gboolean global)
|
|||||||
GEANY_API_SYMBOL
|
GEANY_API_SYMBOL
|
||||||
const gchar *symbols_get_context_separator(gint ft_id)
|
const gchar *symbols_get_context_separator(gint ft_id)
|
||||||
{
|
{
|
||||||
return tm_tag_context_separator(filetypes[ft_id]->lang);
|
return tm_parser_context_separator(filetypes[ft_id]->lang);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1137,7 +1137,7 @@ static void update_parents_table(GHashTable *table, const TMTag *tag, const GtkT
|
|||||||
/* simple case, just use the tag name */
|
/* simple case, just use the tag name */
|
||||||
name = tag->name;
|
name = tag->name;
|
||||||
}
|
}
|
||||||
else if (! tm_tag_has_full_context(tag->lang))
|
else if (! tm_parser_has_full_context(tag->lang))
|
||||||
{
|
{
|
||||||
/* if the parser doesn't use fully qualified scope, use the name alone but
|
/* if the parser doesn't use fully qualified scope, use the name alone but
|
||||||
* prevent Foo::Foo from making parent = child */
|
* prevent Foo::Foo from making parent = child */
|
||||||
@ -1149,7 +1149,7 @@ static void update_parents_table(GHashTable *table, const TMTag *tag, const GtkT
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* build the fully qualified scope as get_parent_name() would return it for a child tag */
|
/* build the fully qualified scope as get_parent_name() would return it for a child tag */
|
||||||
name_free = g_strconcat(tag->scope, tm_tag_context_separator(tag->lang), tag->name, NULL);
|
name_free = g_strconcat(tag->scope, tm_parser_context_separator(tag->lang), tag->name, NULL);
|
||||||
name = name_free;
|
name = name_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1319,7 +1319,7 @@ static void update_tree_tags(GeanyDocument *doc, GList **tags)
|
|||||||
/* Build hash tables holding tags and parents */
|
/* Build hash tables holding tags and parents */
|
||||||
/* parent table is GHashTable<tag_name, GTree<line_num, GtkTreeIter>>
|
/* parent table is GHashTable<tag_name, GTree<line_num, GtkTreeIter>>
|
||||||
* where tag_name might be a fully qualified name (with scope) if the language
|
* where tag_name might be a fully qualified name (with scope) if the language
|
||||||
* parser reports scope properly (see tm_tag_has_full_context()). */
|
* parser reports scope properly (see tm_parser_has_full_context()). */
|
||||||
parents_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, parents_table_value_free);
|
parents_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, parents_table_value_free);
|
||||||
/* tags table is another representation of the @tags list,
|
/* tags table is another representation of the @tags list,
|
||||||
* GHashTable<TMTag, GTree<line_num, GList<GList<TMTag>>>> */
|
* GHashTable<TMTag, GTree<line_num, GList<GList<TMTag>>>> */
|
||||||
|
@ -650,3 +650,91 @@ void tm_parser_verify_type_mappings(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const gchar *tm_parser_context_separator(TMParserType lang)
|
||||||
|
{
|
||||||
|
switch (lang)
|
||||||
|
{
|
||||||
|
case TM_PARSER_C: /* for C++ .h headers or C structs */
|
||||||
|
case TM_PARSER_CPP:
|
||||||
|
case TM_PARSER_GLSL: /* for structs */
|
||||||
|
/*case GEANY_FILETYPES_RUBY:*/ /* not sure what to use atm*/
|
||||||
|
case TM_PARSER_PHP:
|
||||||
|
case TM_PARSER_POWERSHELL:
|
||||||
|
case TM_PARSER_RUST:
|
||||||
|
case TM_PARSER_ZEPHIR:
|
||||||
|
return "::";
|
||||||
|
|
||||||
|
/* avoid confusion with other possible separators in group/section name */
|
||||||
|
case TM_PARSER_CONF:
|
||||||
|
case TM_PARSER_REST:
|
||||||
|
return ":::";
|
||||||
|
|
||||||
|
/* no context separator */
|
||||||
|
case TM_PARSER_ASCIIDOC:
|
||||||
|
case TM_PARSER_TXT2TAGS:
|
||||||
|
return "\x03";
|
||||||
|
|
||||||
|
default:
|
||||||
|
return ".";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
gboolean tm_parser_has_full_context(TMParserType lang)
|
||||||
|
{
|
||||||
|
switch (lang)
|
||||||
|
{
|
||||||
|
/* These parsers include full hierarchy in the tag scope, separated by tm_parser_context_separator() */
|
||||||
|
case TM_PARSER_C:
|
||||||
|
case TM_PARSER_CPP:
|
||||||
|
case TM_PARSER_CSHARP:
|
||||||
|
case TM_PARSER_D:
|
||||||
|
case TM_PARSER_FERITE:
|
||||||
|
case TM_PARSER_GLSL:
|
||||||
|
case TM_PARSER_JAVA:
|
||||||
|
case TM_PARSER_JAVASCRIPT:
|
||||||
|
case TM_PARSER_JSON:
|
||||||
|
case TM_PARSER_PHP:
|
||||||
|
case TM_PARSER_POWERSHELL:
|
||||||
|
case TM_PARSER_PYTHON:
|
||||||
|
case TM_PARSER_RUBY:
|
||||||
|
case TM_PARSER_RUST:
|
||||||
|
case TM_PARSER_SQL:
|
||||||
|
case TM_PARSER_TXT2TAGS:
|
||||||
|
case TM_PARSER_VALA:
|
||||||
|
case TM_PARSER_ZEPHIR:
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
/* These make use of the scope, but don't include nested hierarchy
|
||||||
|
* (either as a parser limitation or a language semantic) */
|
||||||
|
case TM_PARSER_ASCIIDOC:
|
||||||
|
case TM_PARSER_CONF:
|
||||||
|
case TM_PARSER_ERLANG:
|
||||||
|
case TM_PARSER_F77:
|
||||||
|
case TM_PARSER_FORTRAN:
|
||||||
|
case TM_PARSER_GO:
|
||||||
|
case TM_PARSER_OBJC:
|
||||||
|
case TM_PARSER_REST:
|
||||||
|
/* Other parsers don't use scope at all (or should be somewhere above) */
|
||||||
|
default:
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
gboolean tm_parser_langs_compatible(TMParserType lang, TMParserType other)
|
||||||
|
{
|
||||||
|
if (lang == TM_PARSER_NONE || other == TM_PARSER_NONE)
|
||||||
|
return FALSE;
|
||||||
|
if (lang == other)
|
||||||
|
return TRUE;
|
||||||
|
/* Accept CPP tags for C lang and vice versa */
|
||||||
|
else if (lang == TM_PARSER_C && other == TM_PARSER_CPP)
|
||||||
|
return TRUE;
|
||||||
|
else if (lang == TM_PARSER_CPP && other == TM_PARSER_C)
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
@ -119,6 +119,12 @@ TMTagType tm_parser_get_tag_type(gchar kind, TMParserType lang);
|
|||||||
|
|
||||||
gchar tm_parser_get_tag_kind(TMTagType type, TMParserType lang);
|
gchar tm_parser_get_tag_kind(TMTagType type, TMParserType lang);
|
||||||
|
|
||||||
|
const gchar *tm_parser_context_separator(TMParserType lang);
|
||||||
|
|
||||||
|
gboolean tm_parser_has_full_context(TMParserType lang);
|
||||||
|
|
||||||
|
gboolean tm_parser_langs_compatible(TMParserType lang, TMParserType other);
|
||||||
|
|
||||||
#endif /* GEANY_PRIVATE */
|
#endif /* GEANY_PRIVATE */
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
@ -664,76 +664,6 @@ tm_get_current_tag (GPtrArray * file_tags, const gulong line, const TMTagType ta
|
|||||||
return matching_tag;
|
return matching_tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
const gchar *tm_tag_context_separator(TMParserType lang)
|
|
||||||
{
|
|
||||||
switch (lang)
|
|
||||||
{
|
|
||||||
case TM_PARSER_C: /* for C++ .h headers or C structs */
|
|
||||||
case TM_PARSER_CPP:
|
|
||||||
case TM_PARSER_GLSL: /* for structs */
|
|
||||||
/*case GEANY_FILETYPES_RUBY:*/ /* not sure what to use atm*/
|
|
||||||
case TM_PARSER_PHP:
|
|
||||||
case TM_PARSER_POWERSHELL:
|
|
||||||
case TM_PARSER_RUST:
|
|
||||||
case TM_PARSER_ZEPHIR:
|
|
||||||
return "::";
|
|
||||||
|
|
||||||
/* avoid confusion with other possible separators in group/section name */
|
|
||||||
case TM_PARSER_CONF:
|
|
||||||
case TM_PARSER_REST:
|
|
||||||
return ":::";
|
|
||||||
|
|
||||||
/* no context separator */
|
|
||||||
case TM_PARSER_ASCIIDOC:
|
|
||||||
case TM_PARSER_TXT2TAGS:
|
|
||||||
return "\x03";
|
|
||||||
|
|
||||||
default:
|
|
||||||
return ".";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean tm_tag_has_full_context(TMParserType lang)
|
|
||||||
{
|
|
||||||
switch (lang)
|
|
||||||
{
|
|
||||||
/* These parsers include full hierarchy in the tag scope, separated by tm_tag_context_separator() */
|
|
||||||
case TM_PARSER_C:
|
|
||||||
case TM_PARSER_CPP:
|
|
||||||
case TM_PARSER_CSHARP:
|
|
||||||
case TM_PARSER_D:
|
|
||||||
case TM_PARSER_FERITE:
|
|
||||||
case TM_PARSER_GLSL:
|
|
||||||
case TM_PARSER_JAVA:
|
|
||||||
case TM_PARSER_JAVASCRIPT:
|
|
||||||
case TM_PARSER_JSON:
|
|
||||||
case TM_PARSER_PHP:
|
|
||||||
case TM_PARSER_POWERSHELL:
|
|
||||||
case TM_PARSER_PYTHON:
|
|
||||||
case TM_PARSER_RUBY:
|
|
||||||
case TM_PARSER_RUST:
|
|
||||||
case TM_PARSER_SQL:
|
|
||||||
case TM_PARSER_TXT2TAGS:
|
|
||||||
case TM_PARSER_VALA:
|
|
||||||
case TM_PARSER_ZEPHIR:
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
/* These make use of the scope, but don't include nested hierarchy
|
|
||||||
* (either as a parser limitation or a language semantic) */
|
|
||||||
case TM_PARSER_ASCIIDOC:
|
|
||||||
case TM_PARSER_CONF:
|
|
||||||
case TM_PARSER_ERLANG:
|
|
||||||
case TM_PARSER_F77:
|
|
||||||
case TM_PARSER_FORTRAN:
|
|
||||||
case TM_PARSER_GO:
|
|
||||||
case TM_PARSER_OBJC:
|
|
||||||
case TM_PARSER_REST:
|
|
||||||
/* Other parsers don't use scope at all (or should be somewhere above) */
|
|
||||||
default:
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean tm_tag_is_anon(const TMTag *tag)
|
gboolean tm_tag_is_anon(const TMTag *tag)
|
||||||
{
|
{
|
||||||
guint i;
|
guint i;
|
||||||
@ -749,22 +679,6 @@ gboolean tm_tag_is_anon(const TMTag *tag)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
gboolean tm_tag_langs_compatible(TMParserType lang, TMParserType other)
|
|
||||||
{
|
|
||||||
if (lang == TM_PARSER_NONE || other == TM_PARSER_NONE)
|
|
||||||
return FALSE;
|
|
||||||
if (lang == other)
|
|
||||||
return TRUE;
|
|
||||||
/* Accept CPP tags for C lang and vice versa */
|
|
||||||
else if (lang == TM_PARSER_C && other == TM_PARSER_CPP)
|
|
||||||
return TRUE;
|
|
||||||
else if (lang == TM_PARSER_CPP && other == TM_PARSER_C)
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef TM_DEBUG /* various debugging functions */
|
#ifdef TM_DEBUG /* various debugging functions */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -866,7 +780,7 @@ void tm_tags_array_print(GPtrArray *tags, FILE *fp)
|
|||||||
*/
|
*/
|
||||||
gint tm_tag_scope_depth(const TMTag *t)
|
gint tm_tag_scope_depth(const TMTag *t)
|
||||||
{
|
{
|
||||||
const gchar *context_sep = tm_tag_context_separator(t->lang);
|
const gchar *context_sep = tm_parser_context_separator(t->lang);
|
||||||
gint depth;
|
gint depth;
|
||||||
char *s;
|
char *s;
|
||||||
if(!(t && t->scope))
|
if(!(t && t->scope))
|
||||||
|
@ -139,14 +139,8 @@ TMTag *tm_tag_ref(TMTag *tag);
|
|||||||
|
|
||||||
gboolean tm_tags_equal(const TMTag *a, const TMTag *b);
|
gboolean tm_tags_equal(const TMTag *a, const TMTag *b);
|
||||||
|
|
||||||
const gchar *tm_tag_context_separator(TMParserType lang);
|
|
||||||
|
|
||||||
gboolean tm_tag_has_full_context(TMParserType lang);
|
|
||||||
|
|
||||||
gboolean tm_tag_is_anon(const TMTag *tag);
|
gboolean tm_tag_is_anon(const TMTag *tag);
|
||||||
|
|
||||||
gboolean tm_tag_langs_compatible(TMParserType lang, TMParserType other);
|
|
||||||
|
|
||||||
#ifdef TM_DEBUG /* various debugging functions */
|
#ifdef TM_DEBUG /* various debugging functions */
|
||||||
|
|
||||||
const char *tm_tag_type_name(const TMTag *tag);
|
const char *tm_tag_type_name(const TMTag *tag);
|
||||||
|
@ -675,7 +675,7 @@ static void fill_find_tags_array(GPtrArray *dst, const GPtrArray *src,
|
|||||||
for (i = 0; i < num; ++i)
|
for (i = 0; i < num; ++i)
|
||||||
{
|
{
|
||||||
if ((type & (*tag)->type) &&
|
if ((type & (*tag)->type) &&
|
||||||
tm_tag_langs_compatible(lang, (*tag)->lang) &&
|
tm_parser_langs_compatible(lang, (*tag)->lang) &&
|
||||||
(!scope || g_strcmp0((*tag)->scope, scope) == 0))
|
(!scope || g_strcmp0((*tag)->scope, scope) == 0))
|
||||||
{
|
{
|
||||||
g_ptr_array_add(dst, *tag);
|
g_ptr_array_add(dst, *tag);
|
||||||
@ -722,7 +722,7 @@ static void fill_find_tags_array_prefix(GPtrArray *dst, const GPtrArray *src,
|
|||||||
tag = tm_tags_find(src, name, TRUE, &count);
|
tag = tm_tags_find(src, name, TRUE, &count);
|
||||||
for (i = 0; i < count && num < max_num; ++i)
|
for (i = 0; i < count && num < max_num; ++i)
|
||||||
{
|
{
|
||||||
if (tm_tag_langs_compatible(lang, (*tag)->lang) &&
|
if (tm_parser_langs_compatible(lang, (*tag)->lang) &&
|
||||||
!tm_tag_is_anon(*tag) &&
|
!tm_tag_is_anon(*tag) &&
|
||||||
(!last || g_strcmp0(last->name, (*tag)->name) != 0))
|
(!last || g_strcmp0(last->name, (*tag)->name) != 0))
|
||||||
{
|
{
|
||||||
@ -778,7 +778,7 @@ find_scope_members_tags (const GPtrArray *all, TMTag *type_tag, gboolean namespa
|
|||||||
member_types = tm_tag_max_t;
|
member_types = tm_tag_max_t;
|
||||||
|
|
||||||
if (type_tag->scope && *(type_tag->scope))
|
if (type_tag->scope && *(type_tag->scope))
|
||||||
scope = g_strconcat(type_tag->scope, tm_tag_context_separator(type_tag->lang), type_tag->name, NULL);
|
scope = g_strconcat(type_tag->scope, tm_parser_context_separator(type_tag->lang), type_tag->name, NULL);
|
||||||
else
|
else
|
||||||
scope = g_strdup(type_tag->name);
|
scope = g_strdup(type_tag->name);
|
||||||
|
|
||||||
@ -788,7 +788,7 @@ find_scope_members_tags (const GPtrArray *all, TMTag *type_tag, gboolean namespa
|
|||||||
|
|
||||||
if (tag && (tag->type & member_types) &&
|
if (tag && (tag->type & member_types) &&
|
||||||
tag->scope && tag->scope[0] != '\0' &&
|
tag->scope && tag->scope[0] != '\0' &&
|
||||||
tm_tag_langs_compatible(tag->lang, type_tag->lang) &&
|
tm_parser_langs_compatible(tag->lang, type_tag->lang) &&
|
||||||
strcmp(scope, tag->scope) == 0 &&
|
strcmp(scope, tag->scope) == 0 &&
|
||||||
(!namespace || !tm_tag_is_anon(tag)))
|
(!namespace || !tm_tag_is_anon(tag)))
|
||||||
{
|
{
|
||||||
@ -813,7 +813,7 @@ static gchar *strip_type(const gchar *scoped_name, TMParserType lang)
|
|||||||
if (scoped_name != NULL)
|
if (scoped_name != NULL)
|
||||||
{
|
{
|
||||||
/* remove scope prefix */
|
/* remove scope prefix */
|
||||||
const gchar *sep = tm_tag_context_separator(lang);
|
const gchar *sep = tm_parser_context_separator(lang);
|
||||||
const gchar *base = g_strrstr(scoped_name, sep);
|
const gchar *base = g_strrstr(scoped_name, sep);
|
||||||
gchar *name = base ? g_strdup(base + strlen(sep)) : g_strdup(scoped_name);
|
gchar *name = base ? g_strdup(base + strlen(sep)) : g_strdup(scoped_name);
|
||||||
|
|
||||||
@ -909,7 +909,7 @@ find_scope_members (const GPtrArray *tags_array, const gchar *name, TMSourceFile
|
|||||||
static gboolean member_at_method_scope(const GPtrArray *tags, const gchar *method_scope, TMTag *member_tag,
|
static gboolean member_at_method_scope(const GPtrArray *tags, const gchar *method_scope, TMTag *member_tag,
|
||||||
TMParserType lang)
|
TMParserType lang)
|
||||||
{
|
{
|
||||||
const gchar *sep = tm_tag_context_separator(lang);
|
const gchar *sep = tm_parser_context_separator(lang);
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
gchar **comps;
|
gchar **comps;
|
||||||
guint len;
|
guint len;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user