]> git.eshelyaron.com Git - emacs.git/commitdiff
(ruby-ts-add-log-current-function): Fix when between two methods
authorDmitry Gutov <dgutov@yandex.ru>
Tue, 3 Jan 2023 22:37:43 +0000 (00:37 +0200)
committerDmitry Gutov <dgutov@yandex.ru>
Tue, 3 Jan 2023 22:38:01 +0000 (00:38 +0200)
* lisp/progmodes/ruby-ts-mode.el
(ruby-ts-add-log-current-function): Fix the case when point is
between two methods.  'treesit-node-at' returs the 'def' node of
the method after point in such case, so it behaved like point was
inside the method below.

* test/lisp/progmodes/ruby-ts-mode-tests.el
(ruby-ts-add-log-current-method-outside-of-method):
Update the test case.

* test/lisp/progmodes/ruby-mode-tests.el
(ruby-add-log-current-method-outside-of-method):
Mirror that change.

lisp/progmodes/ruby-ts-mode.el
test/lisp/progmodes/ruby-mode-tests.el
test/lisp/progmodes/ruby-ts-mode-tests.el

index c086214a11dd98404d9dfb47b901a5633788a49b..5c173ad24c7a15330699322e6d31a396ee34d687 100644 (file)
@@ -850,7 +850,12 @@ The hash (#) is for instance methods only which are methods
 dot (.) is used.  Double colon (::) is used between classes.  The
 leading double colon is not added."
   (let* ((node (treesit-node-at (point)))
-         (method (treesit-parent-until node (ruby-ts--type-pred ruby-ts--method-regex)))
+         (method-pred
+          (lambda (node)
+            (and (<= (treesit-node-start node) (point))
+                 (>= (treesit-node-end node) (point))
+                 (string-match-p ruby-ts--method-regex (treesit-node-type node)))))
+         (method (treesit-parent-until node method-pred t))
          (class (or method node))
          (result nil)
          (sep "#")
index 9687231dbfae97b960e04a4a1f69d523c107baa1..8a75c83d2c38cd25f9fad1c778db256ebf85494d 100644 (file)
@@ -537,9 +537,12 @@ VALUES-PLIST is a list with alternating index and value elements."
                           |    def foo
                           |    end
                           |    _
+                          |    def bar
+                          |    end
                           |  end
                           |end")
     (search-backward "_")
+    (delete-char 1)
     (should (string= (ruby-add-log-current-method)"M::C"))))
 
 (ert-deftest ruby-add-log-current-method-in-singleton-class ()
index aa1ab1e26050557e21528f8d25035ba112c96a94..b2c990f8e56261ef633f8cd2ea02acfec9792b1a 100644 (file)
@@ -141,9 +141,12 @@ The whitespace before and including \"|\" on each line is removed."
                              |    def foo
                              |    end
                              |    _
+                             |    def bar
+                             |    end
                              |  end
                              |end")
     (search-backward "_")
+    (delete-char 1)
     (should (string= (ruby-ts-add-log-current-function) "M::C"))))
 
 (ert-deftest ruby-ts-add-log-current-method-in-singleton-class ()