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 ret = FALSE;
const gchar *current_scope;
const gchar *context_sep = tm_tag_context_separator(ft->lang);
if (autocomplete_scope_shown)
{
@ -727,13 +728,11 @@ static gboolean autocomplete_scope(GeanyEditor *editor, const gchar *root, gsize
typed = sci_get_char_at(sci, pos - 1);
}
/* make sure to keep in sync with similar checks below */
if (typed == '.')
pos -= 1;
else if (ft->id == GEANY_FILETYPES_C || ft->id == GEANY_FILETYPES_CPP ||
ft->id == GEANY_FILETYPES_PHP || ft->id == GEANY_FILETYPES_RUST)
{
if (match_last_chars(sci, pos, "::"))
pos-=2;
else if (match_last_chars(sci, pos, context_sep))
pos -= strlen(context_sep);
else if ((ft->id == GEANY_FILETYPES_C || ft->id == GEANY_FILETYPES_CPP) &&
match_last_chars(sci, pos, "->"))
pos -= 2;
@ -741,9 +740,6 @@ static gboolean autocomplete_scope(GeanyEditor *editor, const gchar *root, gsize
pos -= 3;
else
return FALSE;
}
else
return FALSE;
/* allow for a space between word and operator */
while (pos > 0 && isspace(sci_get_char_at(sci, pos - 1)))
@ -774,7 +770,8 @@ static gboolean autocomplete_scope(GeanyEditor *editor, const gchar *root, gsize
pos -= strlen(name);
while (pos > 0 && isspace(sci_get_char_at(sci, pos - 1)))
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, "->*");
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)
{
const gchar *context_sep = tm_tag_context_separator(t->lang);
gint depth;
char *s;
if(!(t && t->scope))
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;
++ s;