branch: externals/matlab-mode
commit d285ad072b5f85a1686c5e024e0c12400ecec07f
Author: John Ciolfi <[email protected]>
Commit: John Ciolfi <[email protected]>
matlab-ts-mode: add test for matlab tree-sitter issue 116
---
matlab-ts-mode.el | 11 ++++++++++-
.../indent_line_cont_in_row_cell.m | 20 ++++++++++++++++++++
.../indent_line_cont_in_row_cell_expected.m | 20 ++++++++++++++++++++
.../indent_line_cont_in_row_cell_expected_msgs.m | 20 ++++++++++++++++++++
.../indent_line_cont_in_row_matrix.m | 20 ++++++++++++++++++++
.../indent_line_cont_in_row_matrix_expected.m | 20 ++++++++++++++++++++
.../indent_line_cont_in_row_matrix_expected_msgs.m | 20 ++++++++++++++++++++
7 files changed, 130 insertions(+), 1 deletion(-)
diff --git a/matlab-ts-mode.el b/matlab-ts-mode.el
index a9adff5981..c60482fbe3 100644
--- a/matlab-ts-mode.el
+++ b/matlab-ts-mode.el
@@ -1219,7 +1219,16 @@ is where we start looking for the error node."
(treesit-node-type check-node))
(goto-char (treesit-node-start check-node))
(if (re-search-backward "[^ \t\n\r]" nil t)
- (setq check-node (treesit-node-at (point)))
+ (let* ((pt (point))
+ (node-at-pt (treesit-node-at pt)))
+ ;; Be robust to node-at-point range not covering pt
+ ;; See:
https://github.com/acristoffers/tree-sitter-matlab/issues/116
+ ;; TODO - do we need to do this elsewhere?
+ (while (and node-at-pt
+ (or (< pt (treesit-node-start node-at-pt))
+ (>= pt (treesit-node-end node-at-pt))))
+ (setq node-at-pt (treesit-node-parent node-at-pt)))
+ (setq check-node node-at-pt))
;; at start of buffer
(setq check-node nil)))
diff --git
a/tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_row_cell.m
b/tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_row_cell.m
new file mode 100644
index 0000000000..405cf77ce2
--- /dev/null
+++ b/tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_row_cell.m
@@ -0,0 +1,20 @@
+% -*- matlab-ts -*-
+
+% See: https://github.com/acristoffers/tree-sitter-matlab/issues/116
+
+fcn1({a() ...
+ newline ...
+ b()});
+
+function fcn1(x)
+ disp(x);
+end
+
+function out = a
+ out = "a string";
+end
+
+function out = b
+ out = "b string";
+end
+
diff --git
a/tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_row_cell_expected.m
b/tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_row_cell_expected.m
new file mode 100644
index 0000000000..405cf77ce2
--- /dev/null
+++
b/tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_row_cell_expected.m
@@ -0,0 +1,20 @@
+% -*- matlab-ts -*-
+
+% See: https://github.com/acristoffers/tree-sitter-matlab/issues/116
+
+fcn1({a() ...
+ newline ...
+ b()});
+
+function fcn1(x)
+ disp(x);
+end
+
+function out = a
+ out = "a string";
+end
+
+function out = b
+ out = "b string";
+end
+
diff --git
a/tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_row_cell_expected_msgs.m
b/tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_row_cell_expected_msgs.m
new file mode 100644
index 0000000000..eb24e610ce
--- /dev/null
+++
b/tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_row_cell_expected_msgs.m
@@ -0,0 +1,20 @@
+% -*- matlab-ts -*- % <{Matched rule: ((lambda (node parent _bol &rest _)
(and node (not (string= (treesit-node-type node) "line_continuation")) (equal
(treesit-node-type parent) "source_file"))) (lambda (_node _parent bol &rest _)
(save-excursion (goto-char bol) (line-beginning-position))) 0)}>
+
+% See: https://github.com/acristoffers/tree-sitter-matlab/issues/116 %
<{Matched rule: ((lambda (node parent _bol &rest _) (and node (not (string=
(treesit-node-type node) "line_continuation")) (equal (treesit-node-type
parent) "source_file"))) (lambda (_node _parent bol &rest _) (save-excursion
(goto-char bol) (line-beginning-position))) 0)}>
+
+fcn1({a() ... % <{Matched rule: ((lambda (node parent _bol &rest _) (and node
(not (string= (treesit-node-type node) "line_continuation")) (equal
(treesit-node-type parent) "source_file"))) (lambda (_node _parent bol &rest _)
(save-excursion (goto-char bol) (line-beginning-position))) 0)}>
+ newline ... % <{No matched rule}>
+ b()}); % <{No matched rule}>
+
+function fcn1(x) % <{Matched rule: ((lambda (node parent _bol &rest _) (and
node (not (string= (treesit-node-type node) "line_continuation")) (equal
(treesit-node-type parent) "source_file"))) (lambda (_node _parent bol &rest _)
(save-excursion (goto-char bol) (line-beginning-position))) 0)}>
+ disp(x); % <{Matched rule: ((parent-is "\\`function_definition\\'")
parent matlab-ts-mode--set-function-indent-level-for-gp)}>
+end % <{Matched rule: ((node-is
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'")
parent 0)}>
+
+function out = a % <{Matched rule: ((lambda (node parent _bol &rest _) (and
node (not (string= (treesit-node-type node) "line_continuation")) (equal
(treesit-node-type parent) "source_file"))) (lambda (_node _parent bol &rest _)
(save-excursion (goto-char bol) (line-beginning-position))) 0)}>
+ out = "a string"; % <{Matched rule: ((parent-is
"\\`function_definition\\'") parent
matlab-ts-mode--set-function-indent-level-for-gp)}>
+end % <{Matched rule: ((node-is
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'")
parent 0)}>
+
+function out = b % <{Matched rule: ((lambda (node parent _bol &rest _) (and
node (not (string= (treesit-node-type node) "line_continuation")) (equal
(treesit-node-type parent) "source_file"))) (lambda (_node _parent bol &rest _)
(save-excursion (goto-char bol) (line-beginning-position))) 0)}>
+ out = "b string"; % <{Matched rule: ((parent-is
"\\`function_definition\\'") parent
matlab-ts-mode--set-function-indent-level-for-gp)}>
+end % <{Matched rule: ((node-is
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'")
parent 0)}>
+
diff --git
a/tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_row_matrix.m
b/tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_row_matrix.m
new file mode 100644
index 0000000000..7c8003a53a
--- /dev/null
+++ b/tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_row_matrix.m
@@ -0,0 +1,20 @@
+% -*- matlab-ts -*-
+
+% See: https://github.com/acristoffers/tree-sitter-matlab/issues/116
+
+fcn1([a() ...
+ newline ...
+ b()]);
+
+function fcn1(x)
+ disp(x);
+end
+
+function out = a
+ out = "a string";
+end
+
+function out = b
+ out = "b string";
+end
+
diff --git
a/tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_row_matrix_expected.m
b/tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_row_matrix_expected.m
new file mode 100644
index 0000000000..7c8003a53a
--- /dev/null
+++
b/tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_row_matrix_expected.m
@@ -0,0 +1,20 @@
+% -*- matlab-ts -*-
+
+% See: https://github.com/acristoffers/tree-sitter-matlab/issues/116
+
+fcn1([a() ...
+ newline ...
+ b()]);
+
+function fcn1(x)
+ disp(x);
+end
+
+function out = a
+ out = "a string";
+end
+
+function out = b
+ out = "b string";
+end
+
diff --git
a/tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_row_matrix_expected_msgs.m
b/tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_row_matrix_expected_msgs.m
new file mode 100644
index 0000000000..ab8c35c81a
--- /dev/null
+++
b/tests/test-matlab-ts-mode-indent-files/indent_line_cont_in_row_matrix_expected_msgs.m
@@ -0,0 +1,20 @@
+% -*- matlab-ts -*- % <{Matched rule: ((lambda (node parent _bol &rest _)
(and node (not (string= (treesit-node-type node) "line_continuation")) (equal
(treesit-node-type parent) "source_file"))) (lambda (_node _parent bol &rest _)
(save-excursion (goto-char bol) (line-beginning-position))) 0)}>
+
+% See: https://github.com/acristoffers/tree-sitter-matlab/issues/116 %
<{Matched rule: ((lambda (node parent _bol &rest _) (and node (not (string=
(treesit-node-type node) "line_continuation")) (equal (treesit-node-type
parent) "source_file"))) (lambda (_node _parent bol &rest _) (save-excursion
(goto-char bol) (line-beginning-position))) 0)}>
+
+fcn1([a() ... % <{Matched rule: ((lambda (node parent _bol &rest _) (and node
(not (string= (treesit-node-type node) "line_continuation")) (equal
(treesit-node-type parent) "source_file"))) (lambda (_node _parent bol &rest _)
(save-excursion (goto-char bol) (line-beginning-position))) 0)}>
+ newline ... % <{No matched rule}>
+ b()]); % <{No matched rule}>
+
+function fcn1(x) % <{Matched rule: ((lambda (node parent _bol &rest _) (and
node (not (string= (treesit-node-type node) "line_continuation")) (equal
(treesit-node-type parent) "source_file"))) (lambda (_node _parent bol &rest _)
(save-excursion (goto-char bol) (line-beginning-position))) 0)}>
+ disp(x); % <{Matched rule: ((parent-is "\\`function_definition\\'")
parent matlab-ts-mode--set-function-indent-level-for-gp)}>
+end % <{Matched rule: ((node-is
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'")
parent 0)}>
+
+function out = a % <{Matched rule: ((lambda (node parent _bol &rest _) (and
node (not (string= (treesit-node-type node) "line_continuation")) (equal
(treesit-node-type parent) "source_file"))) (lambda (_node _parent bol &rest _)
(save-excursion (goto-char bol) (line-beginning-position))) 0)}>
+ out = "a string"; % <{Matched rule: ((parent-is
"\\`function_definition\\'") parent
matlab-ts-mode--set-function-indent-level-for-gp)}>
+end % <{Matched rule: ((node-is
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'")
parent 0)}>
+
+function out = b % <{Matched rule: ((lambda (node parent _bol &rest _) (and
node (not (string= (treesit-node-type node) "line_continuation")) (equal
(treesit-node-type parent) "source_file"))) (lambda (_node _parent bol &rest _)
(save-excursion (goto-char bol) (line-beginning-position))) 0)}>
+ out = "b string"; % <{Matched rule: ((parent-is
"\\`function_definition\\'") parent
matlab-ts-mode--set-function-indent-level-for-gp)}>
+end % <{Matched rule: ((node-is
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'")
parent 0)}>
+