Use the langs_compatible() function when passing typenames to scintilla

This requires making the function public and tm_tag.c seems to be a better
place for the function than tm_workspace so move there and add the prefix.
This commit is contained in:
Jiří Techet 2016-02-13 01:52:53 +01:00
parent 5030f7f3da
commit cb307e5b92
4 changed files with 22 additions and 24 deletions

View File

@ -293,11 +293,7 @@ GString *symbols_find_typenames_as_string(gint lang, gboolean global)
tag = TM_TAG(typedefs->pdata[j]);
tag_lang = tag->lang;
/* the check for tag_lang == lang is necessary to avoid wrong type colouring of
* e.g. PHP classes in C++ files
* lang = TM_PARSER_NONE disables the check */
if (tag->name && (tag_lang == lang || lang == TM_PARSER_NONE ||
(lang == TM_PARSER_CPP && tag_lang == TM_PARSER_C)))
if (tag->name && tm_tag_langs_compatible(lang, tag_lang))
{
if (j != 0)
g_string_append_c(s, ' ');

View File

@ -1226,6 +1226,22 @@ gboolean tm_tag_is_anon(const TMTag *tag)
}
gboolean tm_tag_langs_compatible(langType lang, langType 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 */
/*

View File

@ -195,6 +195,8 @@ const gchar *tm_tag_context_separator(langType lang);
gboolean tm_tag_is_anon(const TMTag *tag);
gboolean tm_tag_langs_compatible(langType lang, langType other);
#ifdef TM_DEBUG /* various debugging functions */
const char *tm_tag_type_name(const TMTag *tag);

View File

@ -685,22 +685,6 @@ gboolean tm_workspace_create_global_tags(const char *pre_process, const char **i
}
static gboolean langs_compatible(langType lang, langType 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;
}
static void fill_find_tags_array(GPtrArray *dst, const GPtrArray *src,
const char *name, const char *scope, TMTagType type, langType lang)
{
@ -714,7 +698,7 @@ static void fill_find_tags_array(GPtrArray *dst, const GPtrArray *src,
for (i = 0; i < num; ++i)
{
if ((type & (*tag)->type) &&
langs_compatible(lang, (*tag)->lang) &&
tm_tag_langs_compatible(lang, (*tag)->lang) &&
(!scope || g_strcmp0((*tag)->scope, scope) == 0))
{
g_ptr_array_add(dst, *tag);
@ -761,7 +745,7 @@ static void fill_find_tags_array_prefix(GPtrArray *dst, const GPtrArray *src,
tag = tm_tags_find(src, name, TRUE, &count);
for (i = 0; i < count && num < max_num; ++i)
{
if (langs_compatible(lang, (*tag)->lang) &&
if (tm_tag_langs_compatible(lang, (*tag)->lang) &&
!tm_tag_is_anon(*tag) &&
(!last || g_strcmp0(last->name, (*tag)->name) != 0))
{
@ -827,7 +811,7 @@ find_scope_members_tags (const GPtrArray *all, TMTag *type_tag, gboolean namespa
if (tag && (tag->type & member_types) &&
tag->scope && tag->scope[0] != '\0' &&
langs_compatible(tag->lang, type_tag->lang) &&
tm_tag_langs_compatible(tag->lang, type_tag->lang) &&
strcmp(scope, tag->scope) == 0 &&
(!namespace || !tm_tag_is_anon(tag)))
{