Branch: refs/heads/master Author: Jiří Techet techet@gmail.com Committer: Jiří Techet techet@gmail.com Date: Thu, 28 May 2015 14:27:23 UTC Commit: 206379a272ebce073910a49dbcb15b21909b3d3a https://github.com/geany/geany/commit/206379a272ebce073910a49dbcb15b21909b3d...
Log Message: ----------- Parse return value of go functions
Unfortunately varType is Geany-only so this patch cannot be ported to ctags.
The removal of the extra { read is not the most elegant thing but making skipType() aware of the argList collection complicates things too much.
Modified Paths: -------------- tagmanager/ctags/go.c tests/ctags/Makefile.am tests/ctags/return-types.go tests/ctags/return-types.go.tags tests/ctags/test.go.tags
Modified: tagmanager/ctags/go.c 43 lines changed, 28 insertions(+), 15 deletions(-) =================================================================== @@ -528,7 +528,7 @@ static boolean skipType (tokenInfo *const token)
static void makeTag (tokenInfo *const token, const goKind kind, tokenInfo *const parent_token, const goKind parent_kind, - const char *argList) + const char *argList, const char *varType) { const char *const name = vStringValue (token->string);
@@ -544,6 +544,8 @@ static void makeTag (tokenInfo *const token, const goKind kind, e.kind = GoKinds [kind].letter; if (argList) e.extensionFields.arglist = argList; + if (varType) + e.extensionFields.varType = varType;
if (parent_kind != GOTAG_UNDEFINED && parent_token != NULL) { @@ -569,7 +571,7 @@ static void parsePackage (tokenInfo *const token) readToken (token); if (isType (token, TOKEN_IDENTIFIER)) { - makeTag (token, GOTAG_PACKAGE, NULL, GOTAG_UNDEFINED, NULL); + makeTag (token, GOTAG_PACKAGE, NULL, GOTAG_UNDEFINED, NULL, NULL); if (!scope && Option.include.qualifiedTags) { scope = vStringNew (); @@ -594,6 +596,7 @@ static void parseFunctionOrMethod (tokenInfo *const token)
if (isType (token, TOKEN_IDENTIFIER)) { + vString *argList; tokenInfo *functionToken = copyToken (token);
// Start recording signature @@ -605,18 +608,28 @@ static void parseFunctionOrMethod (tokenInfo *const token)
vStringStripLeading (signature); vStringStripTrailing (signature); - makeTag (functionToken, GOTAG_FUNCTION, NULL, GOTAG_UNDEFINED, signature->buffer); - deleteToken (functionToken); - vStringDelete(signature); - - // Stop recording signature - signature = NULL; + argList = signature; + signature = vStringNew ();
readToken (token);
// Skip over result. skipType (token);
+ // Remove the extra { we have just read + vStringStripTrailing (signature); + vStringChop (signature); + + vStringStripLeading (signature); + vStringStripTrailing (signature); + makeTag (functionToken, GOTAG_FUNCTION, NULL, GOTAG_UNDEFINED, argList->buffer, signature->buffer); + deleteToken (functionToken); + vStringDelete(signature); + vStringDelete(argList); + + // Stop recording signature + signature = NULL; + // Skip over function body. if (isType (token, TOKEN_OPEN_CURLY)) skipToMatched (token); @@ -655,11 +668,11 @@ static void parseStructMembers (tokenInfo *const token, tokenInfo *const parent_ if (memberCandidate) { // if we are here, there was a comma and memberCandidate isn't an anonymous field - makeTag (memberCandidate, GOTAG_MEMBER, parent_token, GOTAG_STRUCT, NULL); + makeTag (memberCandidate, GOTAG_MEMBER, parent_token, GOTAG_STRUCT, NULL, NULL); deleteToken (memberCandidate); memberCandidate = NULL; } - makeTag (token, GOTAG_MEMBER, parent_token, GOTAG_STRUCT, NULL); + makeTag (token, GOTAG_MEMBER, parent_token, GOTAG_STRUCT, NULL, NULL); } readToken (token); } @@ -672,7 +685,7 @@ static void parseStructMembers (tokenInfo *const token, tokenInfo *const parent_ // type into memberCandidate and skipType() should return FALSE so no tag should // be generated in this case. if (skipType (token) && memberCandidate) - makeTag (memberCandidate, GOTAG_MEMBER, parent_token, GOTAG_STRUCT, NULL); + makeTag (memberCandidate, GOTAG_MEMBER, parent_token, GOTAG_STRUCT, NULL, NULL);
if (memberCandidate) deleteToken (memberCandidate); @@ -725,15 +738,15 @@ static void parseConstTypeVar (tokenInfo *const token, goKind kind) typeToken = copyToken (token); readToken (token); if (isKeyword (token, KEYWORD_struct)) - makeTag (typeToken, GOTAG_STRUCT, NULL, GOTAG_UNDEFINED, NULL); + makeTag (typeToken, GOTAG_STRUCT, NULL, GOTAG_UNDEFINED, NULL, NULL); else if (isKeyword (token, KEYWORD_interface)) - makeTag (typeToken, GOTAG_INTERFACE, NULL, GOTAG_UNDEFINED, NULL); + makeTag (typeToken, GOTAG_INTERFACE, NULL, GOTAG_UNDEFINED, NULL, NULL); else - makeTag (typeToken, kind, NULL, GOTAG_UNDEFINED, NULL); + makeTag (typeToken, kind, NULL, GOTAG_UNDEFINED, NULL, NULL); break; } else - makeTag (token, kind, NULL, GOTAG_UNDEFINED, NULL); + makeTag (token, kind, NULL, GOTAG_UNDEFINED, NULL, NULL); readToken (token); } if (!isType (token, TOKEN_COMMA))
Modified: tests/ctags/Makefile.am 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -243,6 +243,7 @@ test_sources = \ refcurs.sql \ regexp.js \ return-hint.zep \ + return-types.go \ rules.t2t \ sample.t2t \ secondary_fcn_name.js \
Modified: tests/ctags/return-types.go 16 lines changed, 16 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,16 @@ +package main + +func foo() *struct {a int; b func()} { + return nil +} + +func bar() (a int, b func(a int), c interface{}, d string) { + return 0, nil, nil, "" +} + +func baz() *[20*3+1]map[chan<- /* map[int]int */<-chan int]map[interface{}]*string { + return nil +} + +func main() { +} \ No newline at end of file
Modified: tests/ctags/return-types.go.tags 6 lines changed, 6 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,6 @@ +# format=tagmanager +bar�16�()�0�(a int, b func(a int), c interface{}, d string) +baz�16�()�0�*[20*3+1]map[chan<- <-chan int]map[interface{}]*string +foo�16�()�0�*struct {a int; b func()} +main�16�()�0� +main�256�0
Modified: tests/ctags/test.go.tags 12 lines changed, 6 insertions(+), 6 deletions(-) =================================================================== @@ -28,12 +28,12 @@ c d�16384�0 e�16384�0 f�16384�0 -f1�16�()�0 -f2�16�()�0 -f3�16�()�0 -f4�16�(a func () func ())�0 -f5�16�()�0 +f1�16�()�0� +f2�16�()�0� +f3�16�()�0�(a, b int) +f4�16�(a func () func ())�0�(func (), int) +f5�16�()�0� g�16384�0 h�16384�0 -main�16�()�0 +main�16�()�0� main�256�0
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).