From 63e22d343489387dda3cf11959a92b7faa6056d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= Date: Mon, 13 Dec 2021 18:48:36 +0100 Subject: [PATCH 1/6] Move function/variable formatting into tm_parser --- src/editor.c | 66 +++-------------------------------- src/editor.h | 2 -- src/symbols.c | 11 ++---- src/tagmanager/tm_parser.c | 70 ++++++++++++++++++++++++++++++++++++++ src/tagmanager/tm_parser.h | 5 +++ 5 files changed, 82 insertions(+), 72 deletions(-) diff --git a/src/editor.c b/src/editor.c index 44892f4322..0cd9de7b26 100644 --- a/src/editor.c +++ b/src/editor.c @@ -1847,53 +1847,6 @@ static gint find_start_bracket(ScintillaObject *sci, gint pos) } -static gboolean append_calltip(GString *str, const TMTag *tag, GeanyFiletypeID ft_id) -{ - if (! tag->arglist) - return FALSE; - - if (ft_id != GEANY_FILETYPES_PASCAL && ft_id != GEANY_FILETYPES_GO) - { /* usual calltips: "retval tagname (arglist)" */ - if (tag->var_type) - { - guint i; - - g_string_append(str, tag->var_type); - for (i = 0; i < tag->pointerOrder; i++) - { - g_string_append_c(str, '*'); - } - g_string_append_c(str, ' '); - } - if (tag->scope) - { - const gchar *cosep = symbols_get_context_separator(ft_id); - - g_string_append(str, tag->scope); - g_string_append(str, cosep); - } - g_string_append(str, tag->name); - g_string_append_c(str, ' '); - g_string_append(str, tag->arglist); - } - else - { /* special case Pascal/Go calltips: "tagname (arglist) : retval" - * (with ':' omitted for Go) */ - g_string_append(str, tag->name); - g_string_append_c(str, ' '); - g_string_append(str, tag->arglist); - - if (!EMPTY(tag->var_type)) - { - g_string_append(str, ft_id == GEANY_FILETYPES_PASCAL ? " : " : " "); - g_string_append(str, tag->var_type); - } - } - - return TRUE; -} - - static gchar *find_calltip(const gchar *word, GeanyFiletype *ft) { GPtrArray *tags; @@ -1964,10 +1917,13 @@ static gchar *find_calltip(const gchar *word, GeanyFiletype *ft) if (str == NULL) { + gchar *f = tm_parser_format_function(tag->lang, tag->name, + tag->arglist, tag->var_type, tag->scope); str = g_string_new(NULL); if (calltip.tag_index > 0) g_string_prepend(str, "\001 "); /* up arrow */ - append_calltip(str, tag, FILETYPE_ID(ft)); + g_string_append(str, f); + g_free(f); } else /* add a down arrow */ { @@ -2061,20 +2017,6 @@ gboolean editor_show_calltip(GeanyEditor *editor, gint pos) } -gchar *editor_get_calltip_text(GeanyEditor *editor, const TMTag *tag) -{ - GString *str; - - g_return_val_if_fail(editor != NULL, NULL); - - str = g_string_new(NULL); - if (append_calltip(str, tag, editor->document->file_type->id)) - return g_string_free(str, FALSE); - else - return g_string_free(str, TRUE); -} - - /* Current document & global tags autocompletion */ static gboolean autocomplete_tags(GeanyEditor *editor, GeanyFiletype *ft, const gchar *root, gsize rootlen) diff --git a/src/editor.h b/src/editor.h index 305b229424..82c650a0ac 100644 --- a/src/editor.h +++ b/src/editor.h @@ -325,8 +325,6 @@ void editor_set_indentation_guides(GeanyEditor *editor); void editor_apply_update_prefs(GeanyEditor *editor); -gchar *editor_get_calltip_text(GeanyEditor *editor, const TMTag *tag); - void editor_toggle_fold(GeanyEditor *editor, gint line, gint modifiers); #endif /* GEANY_PRIVATE */ diff --git a/src/symbols.c b/src/symbols.c index 311d668d71..3fa54c7737 100644 --- a/src/symbols.c +++ b/src/symbols.c @@ -946,18 +946,13 @@ static const gchar *get_symbol_name(GeanyDocument *doc, const TMTag *tag, gboole static gchar *get_symbol_tooltip(GeanyDocument *doc, const TMTag *tag) { - gchar *utf8_name = editor_get_calltip_text(doc->editor, tag); + gchar *utf8_name = tm_parser_format_function(tag->lang, tag->name, + tag->arglist, tag->var_type, tag->scope); if (!utf8_name && tag->var_type && tag->type & (tm_tag_field_t | tm_tag_member_t | tm_tag_variable_t | tm_tag_externvar_t)) { - if (tag->lang != TM_PARSER_PASCAL && tag->lang != TM_PARSER_GO) - utf8_name = g_strconcat(tag->var_type, " ", tag->name, NULL); - else - { - const gchar *sep = tag->lang == TM_PARSER_PASCAL ? " : " : " "; - utf8_name = g_strconcat(tag->name, sep, tag->var_type, NULL); - } + utf8_name = tm_parser_format_variable(tag->lang, tag->name, tag->var_type); } /* encodings_convert_to_utf8_from_charset() fails with charset "None", so skip conversion diff --git a/src/tagmanager/tm_parser.c b/src/tagmanager/tm_parser.c index af5ed8113c..166956cf8b 100644 --- a/src/tagmanager/tm_parser.c +++ b/src/tagmanager/tm_parser.c @@ -882,6 +882,76 @@ gboolean tm_parser_enable_kind(TMParserType lang, gchar kind) } +gchar *tm_parser_format_variable(TMParserType lang, const gchar *name, const gchar *type) +{ + if (!type) + return NULL; + + switch (lang) + { + case TM_PARSER_PASCAL: + return g_strconcat(name, " : ", type, NULL); + case TM_PARSER_GO: + return g_strconcat(name, " ", type, NULL); + default: + return g_strconcat(type, " ", name, NULL); + } +} + + +gchar *tm_parser_format_function(TMParserType lang, const gchar *fname, const gchar *args, + const gchar *retval, const gchar *scope) +{ + GString *str; + + if (!args) /* not a function */ + return NULL; + + str = g_string_new(NULL); + + if (scope) + { + g_string_append(str, scope); + g_string_append(str, tm_parser_context_separator(lang)); + } + g_string_append(str, fname); + g_string_append_c(str, ' '); + g_string_append(str, args); + + if (retval) + { + switch (lang) + { + case TM_PARSER_PASCAL: + case TM_PARSER_GO: + { + /* retval after function */ + const gchar *sep; + switch (lang) + { + case TM_PARSER_PASCAL: + sep = " : "; + break; + default: + sep = " "; + break; + } + g_string_append(str, sep); + g_string_append(str, retval); + break; + } + default: + /* retval before function */ + g_string_prepend_c(str, ' '); + g_string_prepend(str, retval); + break; + } + } + + return g_string_free(str, FALSE); +} + + const gchar *tm_parser_context_separator(TMParserType lang) { switch (lang) diff --git a/src/tagmanager/tm_parser.h b/src/tagmanager/tm_parser.h index 703c02ec7c..884ea6fd5a 100644 --- a/src/tagmanager/tm_parser.h +++ b/src/tagmanager/tm_parser.h @@ -130,6 +130,11 @@ gboolean tm_parser_enable_role(TMParserType lang, gchar kind); gboolean tm_parser_enable_kind(TMParserType lang, gchar kind); +gchar *tm_parser_format_variable(TMParserType lang, const gchar *name, const gchar *type); + +gchar *tm_parser_format_function(TMParserType lang, const gchar *fname, const gchar *args, + const gchar *retval, const gchar *scope); + const gchar *tm_parser_context_separator(TMParserType lang); gboolean tm_parser_has_full_context(TMParserType lang); From 6cef665d36fbadb4af700ea37134b0455dd3290a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= Date: Mon, 13 Dec 2021 22:58:59 +0100 Subject: [PATCH 2/6] Handle calltips of Python constructors like D constructors There were two different ways of how __init__() (or this() in D) constructor calltips were attached to classes so when typing 'MyClass(' the parameters from the constructor were taken: 1. For Python, the arglist of __init__() was attached to the class and when invoking the class, the arglist was shown. The disadvantage of this approach was that it allowed attaching arglist of only one constructor but not multiple ones. 2. For D the query for the calltip was done at the runtime, searching for the constructor inside the corresponding class, allowing multiple constructor tooltips to be shown. Since (2) allows multiple constructors, it is a better approach and can be used for Python too. In addition, this patch creates full scope of the searched constructor so it works also for deeply nested classes. --- src/editor.c | 17 +++++++---- src/tagmanager/tm_ctags.c | 33 ---------------------- tests/ctags/cython_sample.pyx.tags | 2 +- tests/ctags/py_constructor_arglist.py.tags | 2 +- tests/ctags/simple.py.tags | 2 +- 5 files changed, 15 insertions(+), 41 deletions(-) diff --git a/src/editor.c b/src/editor.c index 0cd9de7b26..2c86b52f96 100644 --- a/src/editor.c +++ b/src/editor.c @@ -1850,8 +1850,6 @@ static gint find_start_bracket(ScintillaObject *sci, gint pos) static gchar *find_calltip(const gchar *word, GeanyFiletype *ft) { GPtrArray *tags; - const TMTagType arg_types = tm_tag_function_t | tm_tag_prototype_t | - tm_tag_method_t | tm_tag_macro_with_arg_t; TMTag *tag; GString *str = NULL; guint i; @@ -1868,12 +1866,21 @@ static gchar *find_calltip(const gchar *word, GeanyFiletype *ft) tag = TM_TAG(tags->pdata[0]); - if (ft->id == GEANY_FILETYPES_D && + if ((ft->id == GEANY_FILETYPES_D || ft->id == GEANY_FILETYPES_PYTHON) && (tag->type == tm_tag_class_t || tag->type == tm_tag_struct_t)) { + const TMTagType arg_types = tm_tag_function_t | tm_tag_prototype_t | + tm_tag_method_t | tm_tag_macro_with_arg_t; + const gchar *scope_sep = tm_parser_context_separator(ft->lang); + gchar *scope = EMPTY(tag->scope) ? g_strdup(tag->name) : + g_strjoin(scope_sep, tag->scope, tag->name, NULL); + g_ptr_array_free(tags, TRUE); - /* user typed e.g. 'new Classname(' so lookup D constructor Classname::this() */ - tags = tm_workspace_find("this", tag->name, arg_types, NULL, ft->lang); + /* user typed e.g. 'new Classname(' so lookup D constructor Classname::this() + * same for Python __init__() */ + tags = tm_workspace_find(ft->id == GEANY_FILETYPES_D ? "this" : "__init__", + scope, arg_types, NULL, ft->lang); + g_free(scope); if (tags->len == 0) { g_ptr_array_free(tags, TRUE); diff --git a/src/tagmanager/tm_ctags.c b/src/tagmanager/tm_ctags.c index fc3735aed8..b2b1e227f8 100644 --- a/src/tagmanager/tm_ctags.c +++ b/src/tagmanager/tm_ctags.c @@ -154,36 +154,6 @@ static gboolean init_tag(TMTag *tag, TMSourceFile *file, const tagEntryInfo *tag } -/* add argument list of __init__() Python methods to the class tag */ -static void update_python_arglist(const TMTag *tag, TMSourceFile *source_file) -{ - guint i; - const gchar *parent_tag_name; - - if (tag->type != tm_tag_method_t || tag->scope == NULL || - g_strcmp0(tag->name, "__init__") != 0) - return; - - parent_tag_name = strrchr(tag->scope, '.'); - if (parent_tag_name) - parent_tag_name++; - else - parent_tag_name = tag->scope; - - /* going in reverse order because the tag was added recently */ - for (i = source_file->tags_array->len; i > 0; i--) - { - TMTag *prev_tag = (TMTag *) source_file->tags_array->pdata[i - 1]; - if (g_strcmp0(prev_tag->name, parent_tag_name) == 0) - { - g_free(prev_tag->arglist); - prev_tag->arglist = g_strdup(tag->arglist); - break; - } - } -} - - static gint write_entry(tagWriter *writer, MIO * mio, const tagEntryInfo *const tag, void *user_data) { TMSourceFile *source_file = user_data; @@ -197,9 +167,6 @@ static gint write_entry(tagWriter *writer, MIO * mio, const tagEntryInfo *const return 0; } - if (tm_tag->lang == TM_PARSER_PYTHON) - update_python_arglist(tm_tag, source_file); - g_ptr_array_add(source_file->tags_array, tm_tag); /* output length - we don't write anything to the MIO */ diff --git a/tests/ctags/cython_sample.pyx.tags b/tests/ctags/cython_sample.pyx.tags index 6418a31500..33efd3e991 100644 --- a/tests/ctags/cython_sample.pyx.tags +++ b/tests/ctags/cython_sample.pyx.tags @@ -1,5 +1,5 @@ # format=tagmanager -CDefClassÌ1Í(self)Ö0 +CDefClassÌ1Ö0 StdClassÌ1Ö0 __init__Ì128Í(self)ÎCDefClassÖ0 c_methodÌ128Í(self,int i)ÎCDefClassÖ0 diff --git a/tests/ctags/py_constructor_arglist.py.tags b/tests/ctags/py_constructor_arglist.py.tags index ab0e5f1d2b..5c4f942623 100644 --- a/tests/ctags/py_constructor_arglist.py.tags +++ b/tests/ctags/py_constructor_arglist.py.tags @@ -3,7 +3,7 @@ HttpResponse HttpResponseBadRequestÌ32768Ö0 InterfaceDataValidationErrorÌ32768Ö0 RequestContextÌ32768Ö0 -SomeClassÌ1Í(self, filename, pathsep='', treegap=64)Ö0 +SomeClassÌ1Ö0 __init__Ì128Í(self, filename, pathsep='', treegap=64)ÎSomeClassÖ0 btopenÌ32768Ö0 csrf_exemptÌ32768Ö0 diff --git a/tests/ctags/simple.py.tags b/tests/ctags/simple.py.tags index d7fb0ea445..4917780195 100644 --- a/tests/ctags/simple.py.tags +++ b/tests/ctags/simple.py.tags @@ -14,7 +14,7 @@ even_more fooÌ16Í(Ö0 ignored_functionÌ16Í()Î_testÖ0 more_nestingÌ16Í()Î_test.ignored_functionÖ0 -oneÌ1Í(self, filename, pathsep='', treegap=64)Ö0 +oneÌ1Ö0 onlyÌ128Í(arg)ÎtwoÖ0 public_functionÌ128Í(self, key)ÎoneÖ0 so_is_thisÌ1ÎoneÖ0 From eb5aff941c992766ef302e2333360c42747a1ea1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= Date: Tue, 14 Dec 2021 13:59:39 +0100 Subject: [PATCH 3/6] Move language-specific part of constructor calltip lookup to tm_parser --- src/editor.c | 11 +++++------ src/tagmanager/tm_parser.c | 17 +++++++++++++++++ src/tagmanager/tm_parser.h | 2 ++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/editor.c b/src/editor.c index 2c86b52f96..4715d1ddad 100644 --- a/src/editor.c +++ b/src/editor.c @@ -1849,6 +1849,7 @@ static gint find_start_bracket(ScintillaObject *sci, gint pos) static gchar *find_calltip(const gchar *word, GeanyFiletype *ft) { + const gchar *constructor_method; GPtrArray *tags; TMTag *tag; GString *str = NULL; @@ -1866,8 +1867,9 @@ static gchar *find_calltip(const gchar *word, GeanyFiletype *ft) tag = TM_TAG(tags->pdata[0]); - if ((ft->id == GEANY_FILETYPES_D || ft->id == GEANY_FILETYPES_PYTHON) && - (tag->type == tm_tag_class_t || tag->type == tm_tag_struct_t)) + /* user typed e.g. 'a = Classname(' in Python so lookup __init__() arguments */ + constructor_method = tm_parser_get_constructor_method(tag->lang); + if (constructor_method && (tag->type == tm_tag_class_t || tag->type == tm_tag_struct_t)) { const TMTagType arg_types = tm_tag_function_t | tm_tag_prototype_t | tm_tag_method_t | tm_tag_macro_with_arg_t; @@ -1876,10 +1878,7 @@ static gchar *find_calltip(const gchar *word, GeanyFiletype *ft) g_strjoin(scope_sep, tag->scope, tag->name, NULL); g_ptr_array_free(tags, TRUE); - /* user typed e.g. 'new Classname(' so lookup D constructor Classname::this() - * same for Python __init__() */ - tags = tm_workspace_find(ft->id == GEANY_FILETYPES_D ? "this" : "__init__", - scope, arg_types, NULL, ft->lang); + tags = tm_workspace_find(constructor_method, scope, arg_types, NULL, ft->lang); g_free(scope); if (tags->len == 0) { diff --git a/src/tagmanager/tm_parser.c b/src/tagmanager/tm_parser.c index 166956cf8b..109ffd05ba 100644 --- a/src/tagmanager/tm_parser.c +++ b/src/tagmanager/tm_parser.c @@ -818,6 +818,23 @@ void tm_parser_verify_type_mappings(void) } +/* Get the name of constructor method. Arguments of this method will be used + * for calltips when creating an object using the class name + * (e.g. after the opening brace in 'c = MyClass()' in Python) */ +const gchar *tm_parser_get_constructor_method(TMParserType lang) +{ + switch (lang) + { + case TM_PARSER_D: + return "this"; + case TM_PARSER_PYTHON: + return "__init__"; + default: + return NULL; + } +} + + static gchar *replace_string_if_present(gchar *haystack, gchar *needle, gchar *subst) { if (strstr(haystack, needle)) diff --git a/src/tagmanager/tm_parser.h b/src/tagmanager/tm_parser.h index 884ea6fd5a..36bfdf7966 100644 --- a/src/tagmanager/tm_parser.h +++ b/src/tagmanager/tm_parser.h @@ -124,6 +124,8 @@ gchar tm_parser_get_tag_kind(TMTagType type, TMParserType lang); TMTagType tm_parser_get_subparser_type(TMParserType lang, TMParserType sublang, TMTagType type); +const gchar *tm_parser_get_constructor_method(TMParserType lang); + gchar *tm_parser_update_scope(TMParserType lang, gchar *scope); gboolean tm_parser_enable_role(TMParserType lang, gchar kind); From 3a0e4a4fd567bbc74dc88b9e2f6d39690efdff4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= Date: Tue, 14 Dec 2021 17:58:39 +0100 Subject: [PATCH 4/6] Move language-specific parts of whether to trigger scope autocompletion to tm_parser --- src/editor.c | 47 ++++++++++++++++---------------------- src/tagmanager/tm_parser.c | 27 ++++++++++++++++++++++ src/tagmanager/tm_parser.h | 2 ++ 3 files changed, 49 insertions(+), 27 deletions(-) diff --git a/src/editor.c b/src/editor.c index 4715d1ddad..18c8f0b581 100644 --- a/src/editor.c +++ b/src/editor.c @@ -642,20 +642,23 @@ static void show_tags_list(GeanyEditor *editor, const GPtrArray *tags, gsize roo } -/* do not use with long strings */ -static gboolean match_last_chars(ScintillaObject *sci, gint pos, const gchar *str) +static gint scope_autocomplete_suffix(ScintillaObject *sci, TMParserType lang, + gint pos, gboolean *scope_sep) { - gsize len = strlen(str); + const gchar *sep = tm_parser_context_separator(lang); + const gsize max_len = 3; + gboolean is_scope_sep; gchar *buf; - g_return_val_if_fail(len < 100, FALSE); + buf = g_alloca(max_len + 1); + sci_get_text_range(sci, pos - max_len, pos, buf); - if ((gint)len > pos) - return FALSE; - - buf = g_alloca(len + 1); - sci_get_text_range(sci, pos - len, pos, buf); - return strcmp(str, buf) == 0; + is_scope_sep = g_str_has_suffix(buf, sep); + if (scope_sep) + *scope_sep = is_scope_sep; + if (is_scope_sep) + return strlen(sep); + return tm_parser_scope_autocomplete_suffix(lang, buf); } @@ -706,6 +709,7 @@ static gboolean autocomplete_scope(GeanyEditor *editor, const gchar *root, gsize gboolean ret = FALSE; const gchar *current_scope; const gchar *context_sep = tm_parser_context_separator(ft->lang); + gint autocomplete_suffix_len; if (autocomplete_scope_shown) { @@ -720,22 +724,13 @@ 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 (match_last_chars(sci, pos, context_sep)) - { - pos -= strlen(context_sep); - scope_sep_typed = TRUE; - } - else if (typed == '.') - pos -= 1; - else if ((ft->id == GEANY_FILETYPES_C || ft->id == GEANY_FILETYPES_CPP) && - match_last_chars(sci, pos, "->")) - pos -= 2; - else if (ft->id == GEANY_FILETYPES_CPP && match_last_chars(sci, pos, "->*")) - pos -= 3; - else + autocomplete_suffix_len = scope_autocomplete_suffix(sci, ft->lang, pos, + &scope_sep_typed); + if (autocomplete_suffix_len == 0) return FALSE; + pos -= autocomplete_suffix_len; + /* allow for a space between word and operator */ while (pos > 0 && isspace(sci_get_char_at(sci, pos - 1))) pos--; @@ -765,9 +760,7 @@ 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--; - /* 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, "->*"); + member = scope_autocomplete_suffix(sci, ft->lang, pos, NULL) > 0; if (symbols_get_current_scope(editor->document, ¤t_scope) == -1) current_scope = ""; diff --git a/src/tagmanager/tm_parser.c b/src/tagmanager/tm_parser.c index 109ffd05ba..5673642963 100644 --- a/src/tagmanager/tm_parser.c +++ b/src/tagmanager/tm_parser.c @@ -818,6 +818,33 @@ void tm_parser_verify_type_mappings(void) } +/* When the suffix of 'str' is an operator that should trigger scope + * autocompletion, this function should return the length of the operator, + * zero otherwise. */ +gint tm_parser_scope_autocomplete_suffix(TMParserType lang, const gchar *str) +{ + const gchar *sep = tm_parser_context_separator(lang); + + if (g_str_has_suffix(str, sep)) + return strlen(sep); + + switch (lang) + { + case TM_PARSER_C: + case TM_PARSER_CPP: + if (g_str_has_suffix(str, ".")) + return 1; + else if (g_str_has_suffix(str, "->")) + return 2; + else if (lang == TM_PARSER_CPP && g_str_has_suffix(str, "->*")) + return 3; + default: + break; + } + return 0; +} + + /* Get the name of constructor method. Arguments of this method will be used * for calltips when creating an object using the class name * (e.g. after the opening brace in 'c = MyClass()' in Python) */ diff --git a/src/tagmanager/tm_parser.h b/src/tagmanager/tm_parser.h index 36bfdf7966..27edf34e16 100644 --- a/src/tagmanager/tm_parser.h +++ b/src/tagmanager/tm_parser.h @@ -124,6 +124,8 @@ gchar tm_parser_get_tag_kind(TMTagType type, TMParserType lang); TMTagType tm_parser_get_subparser_type(TMParserType lang, TMParserType sublang, TMTagType type); +gint tm_parser_scope_autocomplete_suffix(TMParserType lang, const gchar *str); + const gchar *tm_parser_get_constructor_method(TMParserType lang); gchar *tm_parser_update_scope(TMParserType lang, gchar *scope); From 2ed3d5c3c26150854bfc55b4d22a1005e55e1c0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= Date: Tue, 14 Dec 2021 18:40:54 +0100 Subject: [PATCH 5/6] Remove invalid python-specific code The code in the comment maybe used to be true some time ago but now no kind maps to namespace for Python. --- src/symbols.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/symbols.c b/src/symbols.c index 3fa54c7737..951d567813 100644 --- a/src/symbols.c +++ b/src/symbols.c @@ -2511,11 +2511,7 @@ gint symbols_get_current_function(GeanyDocument *doc, const gchar **tagname) gint symbols_get_current_scope(GeanyDocument *doc, const gchar **tagname) { TMTagType tag_types = (tm_tag_function_t | tm_tag_method_t | tm_tag_class_t | - tm_tag_struct_t | tm_tag_enum_t | tm_tag_union_t); - - /* Python parser reports imports as namespaces which confuses the scope detection */ - if (doc && doc->file_type->lang != filetypes[GEANY_FILETYPES_PYTHON]->lang) - tag_types |= tm_tag_namespace_t; + tm_tag_struct_t | tm_tag_enum_t | tm_tag_union_t | tm_tag_namespace_t); return get_current_tag_name_cached(doc, tagname, tag_types); } From b3e99ce1edacf6ec3e4b1e50547b729bb549efed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= Date: Fri, 17 Dec 2021 22:08:51 +0100 Subject: [PATCH 6/6] Display python type annotations correctly formatted --- src/tagmanager/tm_parser.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/tagmanager/tm_parser.c b/src/tagmanager/tm_parser.c index 5673642963..f4360f9e79 100644 --- a/src/tagmanager/tm_parser.c +++ b/src/tagmanager/tm_parser.c @@ -933,10 +933,11 @@ gchar *tm_parser_format_variable(TMParserType lang, const gchar *name, const gch switch (lang) { - case TM_PARSER_PASCAL: - return g_strconcat(name, " : ", type, NULL); case TM_PARSER_GO: return g_strconcat(name, " ", type, NULL); + case TM_PARSER_PASCAL: + case TM_PARSER_PYTHON: + return g_strconcat(name, ": ", type, NULL); default: return g_strconcat(type, " ", name, NULL); } @@ -966,15 +967,19 @@ gchar *tm_parser_format_function(TMParserType lang, const gchar *fname, const gc { switch (lang) { - case TM_PARSER_PASCAL: case TM_PARSER_GO: + case TM_PARSER_PASCAL: + case TM_PARSER_PYTHON: { /* retval after function */ const gchar *sep; switch (lang) { case TM_PARSER_PASCAL: - sep = " : "; + sep = ": "; + break; + case TM_PARSER_PYTHON: + sep = " -> "; break; default: sep = " ";