branch: externals/matlab-mode
commit 6d61c66ea6528058a3279fa3387b4beb4cb2ac3d
Author: John Ciolfi <[email protected]>
Commit: John Ciolfi <[email protected]>
matlab-ts-mode--ei: handle ts-matlab issue 148 in assert logic
---
matlab-ts-mode--ei.el | 27 +++++++++++++++++-----
.../electric_indent_catch_exception_issue148.m | 8 +++++++
...tric_indent_catch_exception_issue148_expected.m | 8 +++++++
...indent_catch_exception_issue148_expected_msgs.m | 8 +++++++
.../electric_indent_catch_exception_issue148.m | 8 +++++++
...ic_indent_catch_exception_issue148_expected.txt | 10 ++++++++
6 files changed, 63 insertions(+), 6 deletions(-)
diff --git a/matlab-ts-mode--ei.el b/matlab-ts-mode--ei.el
index 7c92eda8fc..a3b4df75b9 100644
--- a/matlab-ts-mode--ei.el
+++ b/matlab-ts-mode--ei.el
@@ -1331,6 +1331,24 @@ TAB> x = 123 ./1 + 567
(defvar-local matlab-ts-mode--ei-orig-line-node-types-alist nil)
+(cl-defun matlab-ts-mode--ei-assert-nodes-types-match (curr-line-node-types
+ orig-line-node-types
+ linenum)
+ "Validate CURR-LINE-NODE-TYPES eq ORIG-LINE-NODE-TYPES for LINENUM."
+
+ (when (not (string= curr-line-node-types orig-line-node-types))
+
+ ;; See https://github.com/acristoffers/tree-sitter-matlab/issues/148
+ (when (and (string= curr-line-node-types "catch command_name comment")
+ (string= orig-line-node-types "catch identifier comment"))
+ (cl-return-from matlab-ts-mode--ei-assert-nodes-types-match))
+
+ (error "Assert: line-node-types mismatch new: \"%s\" !EQ orig: \"%s\" at
line %d in %s"
+ curr-line-node-types
+ orig-line-node-types
+ linenum
+ (buffer-name))))
+
(defun matlab-ts-mode--ei-assert-line-nodes-match (start-linenum end-linenum)
"Assert that original line node types match modified line node types.
We examine lines between START-LINENUM and END-LINENUM inclusive."
@@ -1362,12 +1380,9 @@ We examine lines between START-LINENUM and END-LINENUM
inclusive."
(goto-char node-end)
(goto-char eol-pt)))))
- (when (not (string= curr-line-node-types orig-line-node-types))
- (error "Assert: line-node-types mismatch new: \"%s\" !EQ orig:
\"%s\" at line %d in %s"
- curr-line-node-types
- orig-line-node-types
- linenum
- (buffer-name)))))
+ (matlab-ts-mode--ei-assert-nodes-types-match curr-line-node-types
+ orig-line-node-types
+ linenum)))
(forward-line)))))
(cl-defun matlab-ts-mode--ei-indent-elements-in-line (&optional
is-indent-region start-pt-offset)
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_catch_exception_issue148.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_catch_exception_issue148.m
new file mode 100644
index 0000000000..4ca2c3d590
--- /dev/null
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_catch_exception_issue148.m
@@ -0,0 +1,8 @@
+% -*- matlab-ts -*-
+
+% t-utils-test-indent: no-line-by-line-indent - line-by-line typing results in
error nodes
+
+try
+foo()
+catch err%comment
+end
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_catch_exception_issue148_expected.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_catch_exception_issue148_expected.m
new file mode 100644
index 0000000000..dc0233ea00
--- /dev/null
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_catch_exception_issue148_expected.m
@@ -0,0 +1,8 @@
+% -*- matlab-ts -*-
+
+% t-utils-test-indent: no-line-by-line-indent - line-by-line typing results in
error nodes
+
+try
+ foo()
+catch err %comment
+end
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_catch_exception_issue148_expected_msgs.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_catch_exception_issue148_expected_msgs.m
new file mode 100644
index 0000000000..eb3b5ba5ed
--- /dev/null
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_catch_exception_issue148_expected_msgs.m
@@ -0,0 +1,8 @@
+% -*- matlab-ts -*- % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+
+% t-utils-test-indent: no-line-by-line-indent - line-by-line typing results in
error nodes % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+
+try % <{Matched rule: (matlab-ts-mode--i-top-level matlab-ts-mode--column-0
0)}>
+ foo() % <{Matched rule: ((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
+catch err %comment % <{Matched rule: ((node-is
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'")
parent 0)}>
+end % <{Matched rule: ((node-is
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'")
parent 0)}>
diff --git
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_catch_exception_issue148.m
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_catch_exception_issue148.m
new file mode 100644
index 0000000000..4ca2c3d590
--- /dev/null
+++
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_catch_exception_issue148.m
@@ -0,0 +1,8 @@
+% -*- matlab-ts -*-
+
+% t-utils-test-indent: no-line-by-line-indent - line-by-line typing results in
error nodes
+
+try
+foo()
+catch err%comment
+end
diff --git
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_catch_exception_issue148_expected.txt
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_catch_exception_issue148_expected.txt
new file mode 100644
index 0000000000..1be6fc6693
--- /dev/null
+++
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_catch_exception_issue148_expected.txt
@@ -0,0 +1,10 @@
+# -*- t-utils-ts-parse-tree -*-
+(source_file<1,146> (comment[1,20]@{% -*- matlab-ts -*-}@) (comment[22,112]@{%
t-utils-test-indent: no-line-by-line-indent - li...}@) \n[112,114]
+ (try_statement<114,145> try[114,117]
+ (block<118,124>
+ (function_call<118,123> name: (identifier[118,121]@{foo}@) ([121,122]
)[122,123])
+ \n[123,124])
+ (catch_clause<124,142> catch[124,129]
+ (block<130,142> (identifier[130,133]@{err}@) (comment[133,141]@{%comment}@)
\n[141,142]))
+ end[142,145])
+ \n[145,146])