branch: externals/matlab-mode
commit 4f6ae07db091e908bd87c8b6fb97cb7532ba818b
Author: John Ciolfi <[email protected]>
Commit: John Ciolfi <[email protected]>

    matlab-ts-mode: fix classdef doc indent issue, add more tests
---
 matlab-ts-mode.el                                  | 23 ++++----
 tests/t-utils.el                                   | 23 ++++----
 .../indent_cell2.m                                 | 62 ++++++++++++++++++++++
 .../indent_cell2_expected.m                        | 62 ++++++++++++++++++++++
 .../indent_comment_classdef_doc.m                  | 15 ++++++
 .../indent_comment_classdef_doc_expected.m         | 15 ++++++
 .../indent_struct.m                                | 12 +++++
 .../indent_struct_expected.m                       | 12 +++++
 8 files changed, 203 insertions(+), 21 deletions(-)

diff --git a/matlab-ts-mode.el b/matlab-ts-mode.el
index 1e1c04ac8c..baf5cb697e 100644
--- a/matlab-ts-mode.el
+++ b/matlab-ts-mode.el
@@ -476,15 +476,20 @@ help doc comment."
                                       eos)
                                   prev-type)
                   (and (string= prev-type "identifier")           ;; id could 
be a fcn or class id
-                       (let ((prev-sibling (treesit-node-prev-sibling 
prev-node)))
-                         (and prev-sibling
-                              (string-match-p
-                               (rx bos
-                                   (or "function"         ;; fcn without in 
and out args
-                                       "function_output"  ;; fcn w/out args 
and no in args
-                                       "classdef")        ;; base class
-                                   eos)
-                               (treesit-node-type prev-sibling))))))
+                       (let* ((prev-sibling (treesit-node-prev-sibling 
prev-node))
+                              (prev-type (and prev-sibling (treesit-node-type 
prev-sibling))))
+                         (and prev-type
+                              (or
+                               (string-match-p
+                                (rx bos
+                                    (or "function"         ;; fcn without in 
and out args
+                                        "function_output"  ;; fcn w/out args 
and no in args
+                                        "classdef")        ;; base class
+                                    eos)
+                                prev-type)
+                               (and (string= prev-type "attributes")
+                                    (equal (treesit-node-type 
(treesit-node-parent prev-sibling))
+                                           "class_definition")))))))
           comment-node)))))
 
 (defun matlab-ts-mode--is-doc-comment (comment-node parent)
diff --git a/tests/t-utils.el b/tests/t-utils.el
index 5e4d69688a..957bf506ab 100644
--- a/tests/t-utils.el
+++ b/tests/t-utils.el
@@ -1185,8 +1185,7 @@ See `t-utils-test-indent' for LINE-MANIPULATOR."
         ;; result is nil or an error message list of strings
         error-msg))))
 
-(defun t-utils--test-indent-typing-line-by-line (lang-file lang-file-mode
-                                                      expected expected-file)
+(defun t-utils--test-indent-typing-line-by-line (lang-file lang-file-mode 
expected expected-file)
   "Indent LANG-FILE by typing it line-by-line.
 Validate result matches EXPECTED from EXPECTED-FILE.
 
@@ -1396,9 +1395,9 @@ To debug a specific indent test file
           (message "START: %s <indent-using-unindented-contents> %s" test-name 
lang-file)
           (let ((start-time (current-time))
                 (unindented-error-msg (t-utils--test-indent-unindented
-                                   lang-file lang-file-major-mode
-                                   expected expected-file
-                                   line-manipulator)))
+                                       lang-file lang-file-major-mode
+                                       expected expected-file
+                                       line-manipulator)))
             (message "%s: %s <indent-using-unindented-contents> %s %s" 
test-name lang-file
                      (if unindented-error-msg "FAIL" "PASS")
                      (t-utils--took start-time))
@@ -2022,13 +2021,13 @@ each element is a cons pair (NAME . NODE)."
              (end-col (save-excursion
                         (goto-char end-point)
                         (1+ (current-column)))))
-       (push (format "%s node at line %d:%d to %d:%d (point %d to %d)"
-                     (treesit-node-type error-node)
-                     start-line start-col
-                     end-line end-col
-                     start-point
-                     end-point)
-             result-list)))
+        (push (format "%s node at line %d:%d to %d:%d (point %d to %d)"
+                      (treesit-node-type error-node)
+                      start-line start-col
+                      end-line end-col
+                      start-point
+                      end-point)
+              result-list)))
     (reverse result-list)))
 
 (defun t-utils-sweep-test-ts-grammar (test-name
diff --git a/tests/test-matlab-ts-mode-indent-files/indent_cell2.m 
b/tests/test-matlab-ts-mode-indent-files/indent_cell2.m
new file mode 100644
index 0000000000..2dc8805d10
--- /dev/null
+++ b/tests/test-matlab-ts-mode-indent-files/indent_cell2.m
@@ -0,0 +1,62 @@
+% -*- matlab-ts -*-
+
+var_types = {
+              'bool';
+              'int8';
+              'uint8';
+              'int16';
+              'uint16';
+              'int32';
+              'uint32';
+              'int64';
+              'uint64';
+              'int128';
+              'uint128';
+              'single';
+              'double';
+              'matrix(int32,2)';
+              'matrix(bool,2)';
+              'matrix(int32,3)';
+              'matrix(bool,3)';
+              'matrix(int32,100)';
+            };
+
+typesToVerify = {
+                  % numeric, logical, and char scalars
+                  logical(1),
+                  int8(2),
+                  int16(3),
+                  double(2+2j),
+                  'c',
+
+                  % numeric, logical, and char matrix
+                  logical(ones(3,3,3)),
+                  int8(ones(3,3,3)),
+                  uint8(ones(3,3,3)),
+                  double(ones(3,3,3)+2j),
+
+                  % char row vector.
+                  'char',
+
+                  % cell array
+                  { 'c', 'e', 'l', 'l' },
+
+                  % function handle
+                  @() disp('function handle'),
+
+                  % String
+                  string(missing),
+                  "my scalar string",
+                  strings(1,2),
+
+                  % comment here
+                  dictionary("a","b"),
+                  dictionary(0,1),
+                  dictionary
+                };
+
+supportedRhsArgs = ...
+    { ...
+      struct('foo', 1), ...
+      1, ...
+    };
diff --git a/tests/test-matlab-ts-mode-indent-files/indent_cell2_expected.m 
b/tests/test-matlab-ts-mode-indent-files/indent_cell2_expected.m
new file mode 100644
index 0000000000..2dc8805d10
--- /dev/null
+++ b/tests/test-matlab-ts-mode-indent-files/indent_cell2_expected.m
@@ -0,0 +1,62 @@
+% -*- matlab-ts -*-
+
+var_types = {
+              'bool';
+              'int8';
+              'uint8';
+              'int16';
+              'uint16';
+              'int32';
+              'uint32';
+              'int64';
+              'uint64';
+              'int128';
+              'uint128';
+              'single';
+              'double';
+              'matrix(int32,2)';
+              'matrix(bool,2)';
+              'matrix(int32,3)';
+              'matrix(bool,3)';
+              'matrix(int32,100)';
+            };
+
+typesToVerify = {
+                  % numeric, logical, and char scalars
+                  logical(1),
+                  int8(2),
+                  int16(3),
+                  double(2+2j),
+                  'c',
+
+                  % numeric, logical, and char matrix
+                  logical(ones(3,3,3)),
+                  int8(ones(3,3,3)),
+                  uint8(ones(3,3,3)),
+                  double(ones(3,3,3)+2j),
+
+                  % char row vector.
+                  'char',
+
+                  % cell array
+                  { 'c', 'e', 'l', 'l' },
+
+                  % function handle
+                  @() disp('function handle'),
+
+                  % String
+                  string(missing),
+                  "my scalar string",
+                  strings(1,2),
+
+                  % comment here
+                  dictionary("a","b"),
+                  dictionary(0,1),
+                  dictionary
+                };
+
+supportedRhsArgs = ...
+    { ...
+      struct('foo', 1), ...
+      1, ...
+    };
diff --git 
a/tests/test-matlab-ts-mode-indent-files/indent_comment_classdef_doc.m 
b/tests/test-matlab-ts-mode-indent-files/indent_comment_classdef_doc.m
new file mode 100644
index 0000000000..39001e0e53
--- /dev/null
+++ b/tests/test-matlab-ts-mode-indent-files/indent_comment_classdef_doc.m
@@ -0,0 +1,15 @@
+% -*- matlab-ts -*-
+
+% t-utils-test-indent: no-line-by-line-indent - doc comment indent requires 
classdef end
+
+classdef (Hidden) indent_comment_classdef_doc
+% comment
+% comment
+
+% Copyright blah
+
+    methods (Static)
+        function foo
+        end
+    end
+end
diff --git 
a/tests/test-matlab-ts-mode-indent-files/indent_comment_classdef_doc_expected.m 
b/tests/test-matlab-ts-mode-indent-files/indent_comment_classdef_doc_expected.m
new file mode 100644
index 0000000000..39001e0e53
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-indent-files/indent_comment_classdef_doc_expected.m
@@ -0,0 +1,15 @@
+% -*- matlab-ts -*-
+
+% t-utils-test-indent: no-line-by-line-indent - doc comment indent requires 
classdef end
+
+classdef (Hidden) indent_comment_classdef_doc
+% comment
+% comment
+
+% Copyright blah
+
+    methods (Static)
+        function foo
+        end
+    end
+end
diff --git a/tests/test-matlab-ts-mode-indent-files/indent_struct.m 
b/tests/test-matlab-ts-mode-indent-files/indent_struct.m
new file mode 100644
index 0000000000..b5a58df38f
--- /dev/null
+++ b/tests/test-matlab-ts-mode-indent-files/indent_struct.m
@@ -0,0 +1,12 @@
+% -*- matlab-ts -*-
+
+data = struct(...
+    'f', f, ...
+    'm', struct('id', 1, 'other', 'two'), ...
+    't', 'xyz', ...
+    'input', ['[' text ']']);
+
+data = struct('f', f, ...
+              'm', struct('id', 1, 'other', 'two'), ...
+              't', 'xyz', ...
+              'input', ['[' text ']']);
diff --git a/tests/test-matlab-ts-mode-indent-files/indent_struct_expected.m 
b/tests/test-matlab-ts-mode-indent-files/indent_struct_expected.m
new file mode 100644
index 0000000000..b5a58df38f
--- /dev/null
+++ b/tests/test-matlab-ts-mode-indent-files/indent_struct_expected.m
@@ -0,0 +1,12 @@
+% -*- matlab-ts -*-
+
+data = struct(...
+    'f', f, ...
+    'm', struct('id', 1, 'other', 'two'), ...
+    't', 'xyz', ...
+    'input', ['[' text ']']);
+
+data = struct('f', f, ...
+              'm', struct('id', 1, 'other', 'two'), ...
+              't', 'xyz', ...
+              'input', ['[' text ']']);

Reply via email to