From 5acdfaf4e028cdd9f4ac4af508bc3271955f594b Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Wed, 20 May 2009 15:38:04 +0000 Subject: [PATCH] Parse Python calltips. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@3809 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 2 ++ TODO | 8 ++++---- src/editor.c | 3 ++- tagmanager/python.c | 33 +++++++++++++++++++++++++++++++-- 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4f956b77..035642ee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,8 @@ Fix multiline indent when selection covers text on the last line. * src/notebook.c: Show current document in bold in tab popup menu. + * src/editor.c, tagmanager/python.c, TODO: + Parse Python calltips. 2009-05-19 Enrico Tröger diff --git a/TODO b/TODO index 59cd2962..b04ee47a 100644 --- a/TODO +++ b/TODO @@ -20,10 +20,6 @@ Note: features included in brackets have lower priority. o (better search & replace regex support - use SCI_GETCHARACTERPOINTER and GNU regex?) o (parsing tags from a memory buffer instead of a file on disk) - o (calltip support for non-C-like languages that use - function_name(arguments) syntax) - o (better tags support for popular languages? - this is a moving - target...) o (tango-like icons for the symbol list) o (show autocompletion symbol icons - see SCI_REGISTERIMAGE) @@ -40,6 +36,10 @@ Wishlist -------- Note: these items might not get worked on. + o (calltip support for non-C-like languages that use + function_name(arguments) syntax - see python.c:parseArglist()) + o (better tags support for popular languages? - this is a moving + target...) o Some kind of support for CTags tags files o Scope resolution for object members o Python plugin interface (different concept from Lua scripting) diff --git a/src/editor.c b/src/editor.c index 4fe8ff70..5341eeb3 100644 --- a/src/editor.c +++ b/src/editor.c @@ -1377,7 +1377,8 @@ static gchar *find_calltip(const gchar *word, GeanyFiletype *ft) g_return_val_if_fail(ft && word && *word, NULL); - tags = tm_workspace_find(word, arg_types | tm_tag_class_t, attrs, FALSE, ft->lang); + /* use all types in case language uses wrong tag type e.g. python "members" instead of "methods" */ + tags = tm_workspace_find(word, tm_tag_max_t, attrs, FALSE, ft->lang); if (tags->len == 0) return NULL; diff --git a/tagmanager/python.c b/tagmanager/python.c index 352dc3a7..7432602a 100644 --- a/tagmanager/python.c +++ b/tagmanager/python.c @@ -61,13 +61,14 @@ static boolean isIdentifierCharacter (int c) * extract all relevant information and create a tag. */ static void makeFunctionTag (vString *const function, - vString *const parent, int is_class_parent) + vString *const parent, int is_class_parent, const char *arglist) { tagEntryInfo tag; initTagEntry (&tag, vStringValue (function)); tag.kindName = "function"; tag.kind = 'f'; + tag.extensionFields.arglist = arglist; if (vStringLength (parent) > 0) { @@ -291,11 +292,39 @@ static void parseImports (const char *cp) vStringDelete (name_next); } +/* modified from get.c getArglistFromStr(). + * warning: terminates rest of string past arglist! + * note: does not ignore brackets inside strings! */ +static char *parseArglist(const char *buf) +{ + char *start, *end; + int level; + if (NULL == buf) + return NULL; + if (NULL == (start = strchr(buf, '('))) + return NULL; + for (level = 1, end = start + 1; level > 0; ++end) + { + if ('\0' == *end) + break; + else if ('(' == *end) + ++ level; + else if (')' == *end) + -- level; + } + *end = '\0'; + return strdup(start); +} + static void parseFunction (const char *cp, vString *const def, vString *const parent, int is_class_parent) { + char *arglist; + cp = parseIdentifier (cp, def); - makeFunctionTag (def, parent, is_class_parent); + arglist = parseArglist (cp); + makeFunctionTag (def, parent, is_class_parent, arglist); + eFree (arglist); } /* Get the combined name of a nested symbol. Classes are separated with ".",