Use language-specific context separator instead of hard-coded "::"

This makes it possible to popup scope completion dialog for more languages.
This commit is contained in:
Jiří Techet 2016-01-10 17:42:53 +01:00
parent f38068f04e
commit cd1a58f0a5
2 changed files with 13 additions and 15 deletions

View File

@ -713,6 +713,7 @@ static gboolean autocomplete_scope(GeanyEditor *editor, const gchar *root, gsize
gboolean member; gboolean member;
gboolean ret = FALSE; gboolean ret = FALSE;
const gchar *current_scope; const gchar *current_scope;
const gchar *context_sep = tm_tag_context_separator(ft->lang);
if (autocomplete_scope_shown) if (autocomplete_scope_shown)
{ {
@ -727,21 +728,16 @@ static gboolean autocomplete_scope(GeanyEditor *editor, const gchar *root, gsize
typed = sci_get_char_at(sci, pos - 1); typed = sci_get_char_at(sci, pos - 1);
} }
/* make sure to keep in sync with similar checks below */
if (typed == '.') if (typed == '.')
pos -= 1; pos -= 1;
else if (ft->id == GEANY_FILETYPES_C || ft->id == GEANY_FILETYPES_CPP || else if (match_last_chars(sci, pos, context_sep))
ft->id == GEANY_FILETYPES_PHP || ft->id == GEANY_FILETYPES_RUST) pos -= strlen(context_sep);
{ else if ((ft->id == GEANY_FILETYPES_C || ft->id == GEANY_FILETYPES_CPP) &&
if (match_last_chars(sci, pos, "::")) match_last_chars(sci, pos, "->"))
pos-=2; pos -= 2;
else if ((ft->id == GEANY_FILETYPES_C || ft->id == GEANY_FILETYPES_CPP) && else if (ft->id == GEANY_FILETYPES_CPP && match_last_chars(sci, pos, "->*"))
match_last_chars(sci, pos, "->")) pos -= 3;
pos-=2;
else if (ft->id == GEANY_FILETYPES_CPP && match_last_chars(sci, pos, "->*"))
pos-=3;
else
return FALSE;
}
else else
return FALSE; return FALSE;
@ -774,7 +770,8 @@ static gboolean autocomplete_scope(GeanyEditor *editor, const gchar *root, gsize
pos -= strlen(name); pos -= strlen(name);
while (pos > 0 && isspace(sci_get_char_at(sci, pos - 1))) while (pos > 0 && isspace(sci_get_char_at(sci, pos - 1)))
pos--; pos--;
member = match_last_chars(sci, pos, ".") || match_last_chars(sci, pos, "::") || /* make sure to keep in sync with similar checks above */
member = match_last_chars(sci, pos, ".") || match_last_chars(sci, pos, context_sep) ||
match_last_chars(sci, pos, "->") || match_last_chars(sci, pos, "->*"); match_last_chars(sci, pos, "->") || match_last_chars(sci, pos, "->*");
if (symbols_get_current_scope(editor->document, &current_scope) == -1) if (symbols_get_current_scope(editor->document, &current_scope) == -1)

View File

@ -1368,11 +1368,12 @@ 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);
gint depth; gint depth;
char *s; char *s;
if(!(t && t->scope)) if(!(t && t->scope))
return 0; return 0;
for (s = t->scope, depth = 0; s; s = strstr(s, "::")) for (s = t->scope, depth = 0; s; s = strstr(s, context_sep))
{ {
++ depth; ++ depth;
++ s; ++ s;