diff options
| author | Dmitry Gutov | 2023-01-04 00:37:43 +0200 |
|---|---|---|
| committer | Dmitry Gutov | 2023-01-04 00:38:01 +0200 |
| commit | 0d98fac6bbc19c7728d42d6196adf4d392ba3132 (patch) | |
| tree | b12fa30c6fbd3fc646ec73227502f8a640966f6c | |
| parent | da69f116bfc37d28942ca6d35eaff978e6805bac (diff) | |
| download | emacs-0d98fac6bbc19c7728d42d6196adf4d392ba3132.tar.gz emacs-0d98fac6bbc19c7728d42d6196adf4d392ba3132.zip | |
(ruby-ts-add-log-current-function): Fix when between two methods
* 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.
| -rw-r--r-- | lisp/progmodes/ruby-ts-mode.el | 7 | ||||
| -rw-r--r-- | test/lisp/progmodes/ruby-mode-tests.el | 3 | ||||
| -rw-r--r-- | test/lisp/progmodes/ruby-ts-mode-tests.el | 3 |
3 files changed, 12 insertions, 1 deletions
diff --git a/lisp/progmodes/ruby-ts-mode.el b/lisp/progmodes/ruby-ts-mode.el index c086214a11d..5c173ad24c7 100644 --- a/lisp/progmodes/ruby-ts-mode.el +++ b/lisp/progmodes/ruby-ts-mode.el | |||
| @@ -850,7 +850,12 @@ The hash (#) is for instance methods only which are methods | |||
| 850 | dot (.) is used. Double colon (::) is used between classes. The | 850 | dot (.) is used. Double colon (::) is used between classes. The |
| 851 | leading double colon is not added." | 851 | leading double colon is not added." |
| 852 | (let* ((node (treesit-node-at (point))) | 852 | (let* ((node (treesit-node-at (point))) |
| 853 | (method (treesit-parent-until node (ruby-ts--type-pred ruby-ts--method-regex))) | 853 | (method-pred |
| 854 | (lambda (node) | ||
| 855 | (and (<= (treesit-node-start node) (point)) | ||
| 856 | (>= (treesit-node-end node) (point)) | ||
| 857 | (string-match-p ruby-ts--method-regex (treesit-node-type node))))) | ||
| 858 | (method (treesit-parent-until node method-pred t)) | ||
| 854 | (class (or method node)) | 859 | (class (or method node)) |
| 855 | (result nil) | 860 | (result nil) |
| 856 | (sep "#") | 861 | (sep "#") |
diff --git a/test/lisp/progmodes/ruby-mode-tests.el b/test/lisp/progmodes/ruby-mode-tests.el index 9687231dbfa..8a75c83d2c3 100644 --- a/test/lisp/progmodes/ruby-mode-tests.el +++ b/test/lisp/progmodes/ruby-mode-tests.el | |||
| @@ -537,9 +537,12 @@ VALUES-PLIST is a list with alternating index and value elements." | |||
| 537 | | def foo | 537 | | def foo |
| 538 | | end | 538 | | end |
| 539 | | _ | 539 | | _ |
| 540 | | def bar | ||
| 541 | | end | ||
| 540 | | end | 542 | | end |
| 541 | |end") | 543 | |end") |
| 542 | (search-backward "_") | 544 | (search-backward "_") |
| 545 | (delete-char 1) | ||
| 543 | (should (string= (ruby-add-log-current-method)"M::C")))) | 546 | (should (string= (ruby-add-log-current-method)"M::C")))) |
| 544 | 547 | ||
| 545 | (ert-deftest ruby-add-log-current-method-in-singleton-class () | 548 | (ert-deftest ruby-add-log-current-method-in-singleton-class () |
diff --git a/test/lisp/progmodes/ruby-ts-mode-tests.el b/test/lisp/progmodes/ruby-ts-mode-tests.el index aa1ab1e2605..b2c990f8e56 100644 --- a/test/lisp/progmodes/ruby-ts-mode-tests.el +++ b/test/lisp/progmodes/ruby-ts-mode-tests.el | |||
| @@ -141,9 +141,12 @@ The whitespace before and including \"|\" on each line is removed." | |||
| 141 | | def foo | 141 | | def foo |
| 142 | | end | 142 | | end |
| 143 | | _ | 143 | | _ |
| 144 | | def bar | ||
| 145 | | end | ||
| 144 | | end | 146 | | end |
| 145 | |end") | 147 | |end") |
| 146 | (search-backward "_") | 148 | (search-backward "_") |
| 149 | (delete-char 1) | ||
| 147 | (should (string= (ruby-ts-add-log-current-function) "M::C")))) | 150 | (should (string= (ruby-ts-add-log-current-function) "M::C")))) |
| 148 | 151 | ||
| 149 | (ert-deftest ruby-ts-add-log-current-method-in-singleton-class () | 152 | (ert-deftest ruby-ts-add-log-current-method-in-singleton-class () |