[geany/geany] 116c74: ruby: Report singleton type inside anonymous classes at a class level

Colomban Wendling git-noreply at xxxxx
Mon Mar 14 18:27:22 UTC 2016


Branch:      refs/heads/master
Author:      Colomban Wendling <ban at herbesfolles.org>
Committer:   Colomban Wendling <ban at herbesfolles.org>
Date:        Mon, 14 Mar 2016 18:27:22 UTC
Commit:      116c749cd941b64c884d5f2d6a1adb8c135aa329
             https://github.com/geany/geany/commit/116c749cd941b64c884d5f2d6a1adb8c135aa329

Log Message:
-----------
ruby: Report singleton type inside anonymous classes at a class level

New test case contributed by @masatake in universal-ctags/ctags#456.

Closes universal-ctags/ctags#455 and universal-ctags/ctags#456.


Modified Paths:
--------------
    tagmanager/ctags/ruby.c
    tests/ctags/ruby-class-method-in-lt-lt-self.rb
    tests/ctags/ruby-class-method-in-lt-lt-self.rb.tags
    tests/ctags/ruby-scope-after-anonymous-class.rb.tags

Modified: tagmanager/ctags/ruby.c
19 lines changed, 18 insertions(+), 1 deletions(-)
===================================================================
@@ -455,7 +455,24 @@ static void findRubyTags (void)
 		}
 		else if (canMatchKeyword (&cp, "def"))
 		{
-			readAndEmitTag (&cp, K_METHOD);
+			rubyKind kind = K_METHOD;
+			NestingLevel *nl = nestingLevelsGetCurrent (nesting);
+
+			/* if the def is inside an unnamed scope at the class level, assume
+			 * it's from a singleton from a construct like this:
+			 *
+			 * class C
+			 *   class << self
+			 *     def singleton
+			 *       ...
+			 *     end
+			 *   end
+			 * end
+			 */
+			if (nl && nl->type == K_CLASS && vStringLength (nl->name) == 0)
+				kind = K_SINGLETON;
+
+			readAndEmitTag (&cp, kind);
 		}
 		else if (canMatchKeyword (&cp, "describe"))
 		{


Modified: tests/ctags/ruby-class-method-in-lt-lt-self.rb
6 lines changed, 6 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,6 @@
+# (Taken from #455 opened by @mislav).
+class C
+  class << self
+    def foo() end
+  end
+end


Modified: tests/ctags/ruby-class-method-in-lt-lt-self.rb.tags
2 lines changed, 2 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,2 @@
+C	input.rb	/^class C$/;"	c
+foo	input.rb	/^    def foo() end$/;"	F	class:C


Modified: tests/ctags/ruby-scope-after-anonymous-class.rb.tags
2 lines changed, 1 insertions(+), 1 deletions(-)
===================================================================
@@ -1,4 +1,4 @@
 # format=tagmanager
 C�1�0
 bar�128�C�0
-foo�128�C�0
+foo�64�C�0



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list