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

    matlab-ts-mode: update indent assert to not fire when there's ERROR nodes
---
 matlab-ts-mode.el                                           | 13 ++++++++-----
 .../indent_fcn_with_error_no_rule.m                         |  7 +++++++
 .../indent_fcn_with_error_no_rule_expected.m                |  7 +++++++
 .../indent_fcn_with_error_no_rule_expected_msgs.m           |  7 +++++++
 4 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/matlab-ts-mode.el b/matlab-ts-mode.el
index 9b6592a051..9975176c98 100644
--- a/matlab-ts-mode.el
+++ b/matlab-ts-mode.el
@@ -1520,11 +1520,14 @@ For optional _NODE, PARENT, and _BOL see 
`treesit-simple-indent-rules'."
 (defun matlab-ts-mode--indent-assert-no-rule (node parent bol &rest _)
   "Report no indent rule for NODE PARENT BOL."
   (when matlab-ts-mode--indent-assert
-    (error "Assert: no indent rule for: N:%S P:%S BOL:%S GP:%S NPS:%S BUF:%S"
-           node parent bol
-           (treesit-node-parent parent)
-           (treesit-node-prev-sibling node)
-           (buffer-name))))
+    ;; Bad syntax errors shouldn't cause and assert because no rule matching 
means no indent will
+    ;; occur and that's okay.
+    (when (not (treesit-parent-until (or node parent) (rx bos "ERROR" eos)))
+      (error "Assert: no indent rule for: N:%S P:%S BOL:%S GP:%S NPS:%S BUF:%S"
+             node parent bol
+             (treesit-node-parent parent)
+             (treesit-node-prev-sibling node)
+             (buffer-name)))))
 
 (defvar matlab-ts-mode--i-error-switch-matcher-pair)
 
diff --git 
a/tests/test-matlab-ts-mode-indent-files/indent_fcn_with_error_no_rule.m 
b/tests/test-matlab-ts-mode-indent-files/indent_fcn_with_error_no_rule.m
new file mode 100644
index 0000000000..ff27921bfb
--- /dev/null
+++ b/tests/test-matlab-ts-mode-indent-files/indent_fcn_with_error_no_rule.m
@@ -0,0 +1,7 @@
+% -*- matlab-ts -*-
+
+% Following is invalid syntax (e.g. when people make a template) and which 
results in ERROR nodes
+% that don't have an indent rule.
+
+function out = {functionName}(x,y)
+end
diff --git 
a/tests/test-matlab-ts-mode-indent-files/indent_fcn_with_error_no_rule_expected.m
 
b/tests/test-matlab-ts-mode-indent-files/indent_fcn_with_error_no_rule_expected.m
new file mode 100644
index 0000000000..ff27921bfb
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-indent-files/indent_fcn_with_error_no_rule_expected.m
@@ -0,0 +1,7 @@
+% -*- matlab-ts -*-
+
+% Following is invalid syntax (e.g. when people make a template) and which 
results in ERROR nodes
+% that don't have an indent rule.
+
+function out = {functionName}(x,y)
+end
diff --git 
a/tests/test-matlab-ts-mode-indent-files/indent_fcn_with_error_no_rule_expected_msgs.m
 
b/tests/test-matlab-ts-mode-indent-files/indent_fcn_with_error_no_rule_expected_msgs.m
new file mode 100644
index 0000000000..7b657f91a6
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-indent-files/indent_fcn_with_error_no_rule_expected_msgs.m
@@ -0,0 +1,7 @@
+% -*- matlab-ts -*- %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
+
+% Following is invalid syntax (e.g. when people make a template) and which 
results in ERROR nodes %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
+% that don't have an indent rule. %  <{Matched rule: 
(matlab-ts-mode--i-block-comment-end-matcher 
matlab-ts-mode--i-block-comment-end-anchor 0)}>
+
+function out = {functionName}(x,y) %  <{Matched rule: 
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
+end %  <{No matched rule}>

Reply via email to