Branch: refs/heads/master Author: Jiří Techet techet@gmail.com Committer: Enrico Tröger enrico.troeger@uvena.de Date: Sun, 09 Jan 2022 22:32:40 UTC Commit: b814cf666bc9f7c769839417eed267aa56bf6518 https://github.com/geany/geany/commit/b814cf666bc9f7c769839417eed267aa56bf65...
Log Message: ----------- Move language-specific part of constructor calltip lookup to tm_parser
Modified Paths: -------------- src/editor.c src/tagmanager/tm_parser.c src/tagmanager/tm_parser.h
Modified: src/editor.c 11 lines changed, 5 insertions(+), 6 deletions(-) =================================================================== @@ -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) {
Modified: src/tagmanager/tm_parser.c 17 lines changed, 17 insertions(+), 0 deletions(-) =================================================================== @@ -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))
Modified: src/tagmanager/tm_parser.h 2 lines changed, 2 insertions(+), 0 deletions(-) =================================================================== @@ -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);
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).