branch: externals/matlab-mode
commit 2bab6b4c55274aed71b2bbf842f925ca0d66117d
Author: John Ciolfi <[email protected]>
Commit: John Ciolfi <[email protected]>
matlab-ts-mode--ei: handle events, enumeration, methods commands
---
matlab-ts-mode--ei.el | 57 +++++++++------
.../electric_indent_inspect_keyword_commands.m | 7 ++
.../electric_indent_inspect_keyword_commands2.m | 21 ++++++
...ric_indent_inspect_keyword_commands2_expected.m | 21 ++++++
...ndent_inspect_keyword_commands2_expected_msgs.m | 21 ++++++
...tric_indent_inspect_keyword_commands_expected.m | 7 ++
...indent_inspect_keyword_commands_expected_msgs.m | 7 ++
.../electric_indent_inspect_keyword_commands.m | 7 ++
.../electric_indent_inspect_keyword_commands2.m | 21 ++++++
...c_indent_inspect_keyword_commands2_expected.txt | 83 ++++++++++++++++++++++
...ic_indent_inspect_keyword_commands_expected.txt | 38 ++++++++++
11 files changed, 267 insertions(+), 23 deletions(-)
diff --git a/matlab-ts-mode--ei.el b/matlab-ts-mode--ei.el
index f077550005..2dcd1859d3 100644
--- a/matlab-ts-mode--ei.el
+++ b/matlab-ts-mode--ei.el
@@ -74,7 +74,8 @@
"spmd"
"switch"
"try"
- "while")))
+ "while")
+ eos))
(defvar matlab-ts-mode--ei-pad-op-re
(rx bos (or "+" "-" "*" "/" ".*" "./" ".\\" "\\"
@@ -171,8 +172,11 @@
;; Case: c3 = {b [c '%']};
("." ,(rx bos "[" eos)
1)
+ ;; Case: foo(1) or foo.bar
(,(rx bos "identifier" eos) ,(rx bos (or "(" "{") eos)
0)
(,(rx bos "identifier" eos) "."
1)
+ ;; Case: {events(thing)}, {enumeration(thing)}, {methods(thing)}
+ (,(rx "-fcn" eos) ,(rx bos "(" eos)
0)
;; Case: number in matrix: [123 456]
(,(rx bos "number" eos) "."
1)
@@ -230,17 +234,18 @@ be unary-op even though the node type is \"+\"."
(parent-type (or (treesit-node-type parent) "")))
(cond
- ;; Use string and not the elements of the string
+ ;; Case: Use string and not the elements of the string
((string= parent-type "string")
(setq node parent
node-type parent-type))
+ ;; Case: name=value argument pair
((and (string= node-type "=")
(string= parent-type "arguments"))
;; arguments name=value
(setq node-type "n=v"))
- ;; prop-id, prop-class-id, enum-id, attribute-id
+ ;; Case: prop-id, prop-class-id, enum-id, attribute-id
((string= node-type "identifier")
(cond ((string= parent-type "property") ;; propertyWithOutDot?
(if (equal (treesit-node-child parent 0) node)
@@ -256,26 +261,32 @@ be unary-op even though the node type is \"+\"."
(setq node-type "attribute-id"))
))
- ;; Unary operator sign, + or -, e.g. [0 -e] or g = - e
+ ;; Case: unary operator sign, + or -, e.g. [0 -e] or g = - e
((and (string= parent-type "unary_operator")
(equal (treesit-node-child parent 0) node))
(setq node-type "unary-op"))
- ;; Super-class constructor call
+ ;; Case: super-class constructor call
;; [email protected];
((and (string= node-type "@")
(string= parent-type "function_call"))
(setq node-type "@-fcn-call"))
- ;; Property dimensions
+ ;; Case: property dimensions
;; foo1 (1, :) {mustBeNumeric, mustBeReal} = [0, 0, 0];
((and (or (string= node-type "number") (string= node-type ":"))
(or (string= parent-type "dimensions")
(and (string= parent-type "spread_operator")
(string= (treesit-node-type (treesit-node-parent parent))
"dimensions"))))
(setq node-type "prop-dim"))
- )
-
+
+ ;; Case: events, enumeration, methods
+ ((and (string-match-p (rx bos (or "events" "enumeration" "methods") eos)
node-type)
+ (string= parent-type "identifier"))
+ ;; TopTester: electric_indent_inspect_keyword_commands.m
+ ;; TopTester: electric_indent_inspect_keyword_commands2.m
+ (setq node-type (concat node-type "-fcn"))))
+
(cons node node-type)))
(cl-defun matlab-ts-mode--ei-move-to-and-get-node ()
@@ -1214,20 +1225,20 @@ See `matlab-ts-mode--ei-get-new-line' for EI-INFO
contents."
"Return property or argument node for first node in EI-INFO.
Returns nil if not a property, enum field, or argument node that ends on
same line and has items to align."
- (let* ((first-node-in-line (nth 3 ei-info))
- (modified-node-type (cdr (matlab-ts-mode--ei-get-node-to-use
first-node-in-line)))
- (prop-id-node (pcase modified-node-type
- ((or "prop-id" "enum-id")
- first-node-in-line)
- ("property_name"
- (treesit-node-parent first-node-in-line))))
- (prop-node (treesit-node-parent prop-id-node)))
- ;; skip multi-line nodes for alignment (properties / arguments can span
multiple lines)
- (when (and prop-node
- (= (line-number-at-pos (treesit-node-start prop-node))
- (line-number-at-pos (treesit-node-end prop-node)))
- (> (length (treesit-node-children prop-node)) 1))
- prop-id-node)))
+ (if-let ((first-node-in-line (nth 3 ei-info)))
+ (let* ((modified-node-type (cdr (matlab-ts-mode--ei-get-node-to-use
first-node-in-line)))
+ (prop-id-node (pcase modified-node-type
+ ((or "prop-id" "enum-id")
+ first-node-in-line)
+ ("property_name"
+ (treesit-node-parent first-node-in-line))))
+ (prop-node (treesit-node-parent prop-id-node)))
+ ;; skip multi-line nodes for alignment (properties / arguments can
span multiple lines)
+ (when (and prop-node
+ (= (line-number-at-pos (treesit-node-start prop-node))
+ (line-number-at-pos (treesit-node-end prop-node)))
+ (> (length (treesit-node-children prop-node)) 1))
+ prop-id-node))))
(defun matlab-ts-mode--ei-prop-length (ei-info)
"Get the property length from the electric indented line in EI-INFO."
@@ -1495,7 +1506,7 @@ TAB> x = 123 ./1 + 567
;; See https://github.com/acristoffers/tree-sitter-matlab/issues/149
(let ((orig-modified (replace-regexp-in-string (rx "identifier
line_continuation" eos)
- "enumeration
line_continuation"
+ "enumeration-fcn
line_continuation"
orig-line-node-types)))
(when (string= curr-line-node-types orig-modified)
(cl-return-from matlab-ts-mode--ei-assert-nodes-types-match)))
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_inspect_keyword_commands.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_inspect_keyword_commands.m
new file mode 100644
index 0000000000..3b7686a674
--- /dev/null
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_inspect_keyword_commands.m
@@ -0,0 +1,7 @@
+% -*- matlab-ts -*-
+
+foo1 = {events('handle')};
+
+foo2 = {enumeration('matlab.OnOffSwitchSTate')};
+
+foo3 = {methods('double')};
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_inspect_keyword_commands2.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_inspect_keyword_commands2.m
new file mode 100644
index 0000000000..ae9ab1ad48
--- /dev/null
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_inspect_keyword_commands2.m
@@ -0,0 +1,21 @@
+% -*- matlab-ts -*-
+
+classdef electric_indent_inspect_keyword_commands2
+ methods (Static)
+ function test
+
+ events('handle')
+ foo1 = {events('handle')};
+ disp(foo1);
+
+ enumeration('matlab.OnOffSwitchSTate')
+ foo2 = {enumeration('matlab.OnOffSwitchSTate')};
+ disp(foo2);
+
+ methods('double')
+ foo3 = {methods('double')};
+ disp(foo3);
+
+ end
+ end
+end
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_inspect_keyword_commands2_expected.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_inspect_keyword_commands2_expected.m
new file mode 100644
index 0000000000..ae9ab1ad48
--- /dev/null
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_inspect_keyword_commands2_expected.m
@@ -0,0 +1,21 @@
+% -*- matlab-ts -*-
+
+classdef electric_indent_inspect_keyword_commands2
+ methods (Static)
+ function test
+
+ events('handle')
+ foo1 = {events('handle')};
+ disp(foo1);
+
+ enumeration('matlab.OnOffSwitchSTate')
+ foo2 = {enumeration('matlab.OnOffSwitchSTate')};
+ disp(foo2);
+
+ methods('double')
+ foo3 = {methods('double')};
+ disp(foo3);
+
+ end
+ end
+end
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_inspect_keyword_commands2_expected_msgs.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_inspect_keyword_commands2_expected_msgs.m
new file mode 100644
index 0000000000..e3ab47cfe4
--- /dev/null
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_inspect_keyword_commands2_expected_msgs.m
@@ -0,0 +1,21 @@
+% -*- matlab-ts -*- % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+
+classdef electric_indent_inspect_keyword_commands2 % <{Matched rule:
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
+ methods (Static) % <{Matched rule: ((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
+ function test % <{Matched rule: ((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
+
+ events('handle') % <{Matched rule: ((parent-is
"\\`function_definition\\'") parent
matlab-ts-mode--set-function-indent-level-for-gp)}>
+ foo1 = {events('handle')}; % <{Matched rule: ((parent-is
"\\`block\\'") parent 0)}>
+ disp(foo1); % <{Matched rule: ((parent-is "\\`block\\'") parent
0)}>
+
+ enumeration('matlab.OnOffSwitchSTate') % <{Matched rule:
((parent-is "\\`block\\'") parent 0)}>
+ foo2 = {enumeration('matlab.OnOffSwitchSTate')}; % <{Matched
rule: ((parent-is "\\`block\\'") parent 0)}>
+ disp(foo2); % <{Matched rule: ((parent-is "\\`block\\'") parent
0)}>
+
+ methods('double') % <{Matched rule: ((parent-is "\\`block\\'")
parent 0)}>
+ foo3 = {methods('double')}; % <{Matched rule: ((parent-is
"\\`block\\'") parent 0)}>
+ disp(foo3); % <{Matched rule: ((parent-is "\\`block\\'") parent
0)}>
+
+ end % <{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)}>
+end % <{Matched rule: ((node-is
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'")
parent 0)}>
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_inspect_keyword_commands_expected.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_inspect_keyword_commands_expected.m
new file mode 100644
index 0000000000..3b7686a674
--- /dev/null
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_inspect_keyword_commands_expected.m
@@ -0,0 +1,7 @@
+% -*- matlab-ts -*-
+
+foo1 = {events('handle')};
+
+foo2 = {enumeration('matlab.OnOffSwitchSTate')};
+
+foo3 = {methods('double')};
diff --git
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_inspect_keyword_commands_expected_msgs.m
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_inspect_keyword_commands_expected_msgs.m
new file mode 100644
index 0000000000..a2048cad00
--- /dev/null
+++
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_inspect_keyword_commands_expected_msgs.m
@@ -0,0 +1,7 @@
+% -*- matlab-ts -*- % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+
+foo1 = {events('handle')}; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
+
+foo2 = {enumeration('matlab.OnOffSwitchSTate')}; % <{Matched rule:
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
+
+foo3 = {methods('double')}; % <{Matched rule: (matlab-ts-mode--i-top-level
matlab-ts-mode--column-0 0)}>
diff --git
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_inspect_keyword_commands.m
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_inspect_keyword_commands.m
new file mode 100644
index 0000000000..3b7686a674
--- /dev/null
+++
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_inspect_keyword_commands.m
@@ -0,0 +1,7 @@
+% -*- matlab-ts -*-
+
+foo1 = {events('handle')};
+
+foo2 = {enumeration('matlab.OnOffSwitchSTate')};
+
+foo3 = {methods('double')};
diff --git
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_inspect_keyword_commands2.m
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_inspect_keyword_commands2.m
new file mode 100644
index 0000000000..ae9ab1ad48
--- /dev/null
+++
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_inspect_keyword_commands2.m
@@ -0,0 +1,21 @@
+% -*- matlab-ts -*-
+
+classdef electric_indent_inspect_keyword_commands2
+ methods (Static)
+ function test
+
+ events('handle')
+ foo1 = {events('handle')};
+ disp(foo1);
+
+ enumeration('matlab.OnOffSwitchSTate')
+ foo2 = {enumeration('matlab.OnOffSwitchSTate')};
+ disp(foo2);
+
+ methods('double')
+ foo3 = {methods('double')};
+ disp(foo3);
+
+ end
+ end
+end
diff --git
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_inspect_keyword_commands2_expected.txt
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_inspect_keyword_commands2_expected.txt
new file mode 100644
index 0000000000..e14d1fd7a8
--- /dev/null
+++
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_inspect_keyword_commands2_expected.txt
@@ -0,0 +1,83 @@
+# -*- t-utils-ts-parse-tree -*-
+(source_file<1,466> (comment[1,20]@{% -*- matlab-ts -*-}@) \n[20,22]
+ (class_definition<22,465> classdef[22,30] name:
(identifier[31,72]@{electric_indent_inspect_keyword_commands2}@) \n[72,73]
+ (methods<77,461> methods[77,84]
+ (attributes<85,93> ([85,86]
+ (attribute<86,92> (identifier[86,92]@{Static}@))
+ )[92,93])
+ \n[93,94]
+ (function_definition<102,453> function[102,110] name:
(identifier[111,115]@{test}@) \n[115,117]
+ (block<129,442>
+ (function_call<129,145>
+ name: (identifier<129,135> events[129,135])
+ ([135,136]
+ (arguments<136,144>
+ argument: (string<136,144> '[136,137]
(string_content[137,143]@{handle}@) '[143,144]))
+ )[144,145])
+ \n[145,146]
+ (assignment<158,183> left: (identifier[158,162]@{foo1}@) =[163,164]
+ right:
+ (cell<165,183> {[165,166]
+ (row<166,182>
+ (function_call<166,182>
+ name: (identifier<166,172> events[166,172])
+ ([172,173]
+ (arguments<173,181>
+ argument: (string<173,181> '[173,174]
(string_content[174,180]@{handle}@) '[180,181]))
+ )[181,182]))
+ }[182,183]))
+ ;[183,184]
+ (function_call<197,207> name: (identifier[197,201]@{disp}@) ([201,202]
+ (arguments<202,206> argument: (identifier[202,206]@{foo1}@))
+ )[206,207])
+ ;[207,208] \n[208,210]
+ (function_call<222,260>
+ name: (identifier<222,233> enumeration[222,233])
+ ([233,234]
+ (arguments<234,259>
+ argument: (string<234,259> '[234,235]
(string_content[235,258]@{matlab.OnOffSwitchSTate}@) '[258,259]))
+ )[259,260])
+ \n[260,261]
+ (assignment<273,320> left: (identifier[273,277]@{foo2}@) =[278,279]
+ right:
+ (cell<280,320> {[280,281]
+ (row<281,319>
+ (function_call<281,319>
+ name: (identifier<281,292> enumeration[281,292])
+ ([292,293]
+ (arguments<293,318>
+ argument: (string<293,318> '[293,294]
(string_content[294,317]@{matlab.OnOffSwitchSTate}@) '[317,318]))
+ )[318,319]))
+ }[319,320]))
+ ;[320,321]
+ (function_call<334,344> name: (identifier[334,338]@{disp}@) ([338,339]
+ (arguments<339,343> argument: (identifier[339,343]@{foo2}@))
+ )[343,344])
+ ;[344,345] \n[345,347]
+ (function_call<359,376>
+ name: (identifier<359,366> methods[359,366])
+ ([366,367]
+ (arguments<367,375>
+ argument: (string<367,375> '[367,368]
(string_content[368,374]@{double}@) '[374,375]))
+ )[375,376])
+ \n[376,377]
+ (assignment<389,415> left: (identifier[389,393]@{foo3}@) =[394,395]
+ right:
+ (cell<396,415> {[396,397]
+ (row<397,414>
+ (function_call<397,414>
+ name: (identifier<397,404> methods[397,404])
+ ([404,405]
+ (arguments<405,413>
+ argument: (string<405,413> '[405,406]
(string_content[406,412]@{double}@) '[412,413]))
+ )[413,414]))
+ }[414,415]))
+ ;[415,416]
+ (function_call<429,439> name: (identifier[429,433]@{disp}@) ([433,434]
+ (arguments<434,438> argument: (identifier[434,438]@{foo3}@))
+ )[438,439])
+ ;[439,440] \n[440,442])
+ end[450,453])
+ \n[453,454] end[458,461])
+ \n[461,462] end[462,465])
+ \n[465,466])
diff --git
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_inspect_keyword_commands_expected.txt
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_inspect_keyword_commands_expected.txt
new file mode 100644
index 0000000000..abc79c0d08
--- /dev/null
+++
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_inspect_keyword_commands_expected.txt
@@ -0,0 +1,38 @@
+# -*- t-utils-ts-parse-tree -*-
+(source_file<1,128> (comment[1,20]@{% -*- matlab-ts -*-}@)
+ (assignment<22,47> left: (identifier[22,26]@{foo1}@) =[27,28]
+ right:
+ (cell<29,47> {[29,30]
+ (row<30,46>
+ (function_call<30,46>
+ name: (identifier<30,36> events[30,36])
+ ([36,37]
+ (arguments<37,45>
+ argument: (string<37,45> '[37,38] (string_content[38,44]@{handle}@)
'[44,45]))
+ )[45,46]))
+ }[46,47]))
+ ;[47,48]
+ (assignment<50,97> left: (identifier[50,54]@{foo2}@) =[55,56]
+ right:
+ (cell<57,97> {[57,58]
+ (row<58,96>
+ (function_call<58,96>
+ name: (identifier<58,69> enumeration[58,69])
+ ([69,70]
+ (arguments<70,95>
+ argument: (string<70,95> '[70,71]
(string_content[71,94]@{matlab.OnOffSwitchSTate}@) '[94,95]))
+ )[95,96]))
+ }[96,97]))
+ ;[97,98]
+ (assignment<100,126> left: (identifier[100,104]@{foo3}@) =[105,106]
+ right:
+ (cell<107,126> {[107,108]
+ (row<108,125>
+ (function_call<108,125>
+ name: (identifier<108,115> methods[108,115])
+ ([115,116]
+ (arguments<116,124>
+ argument: (string<116,124> '[116,117]
(string_content[117,123]@{double}@) '[123,124]))
+ )[124,125]))
+ }[125,126]))
+ ;[126,127] \n[127,128])