Skip to content

Commit

Permalink
Additional indentation recovery for newline and case construction.
Browse files Browse the repository at this point in the history
The newline indentation uses the indentation of the next non-comment
sibling node.  When this node was an ERROR, the catch-all indentation
rule was matched which placed the newline at column 0.  Now, ERROR
nodes are handled by the indentation error recovery logic and newline
indentation prior to an ERROR node will be chosen according to this
logic.

The "end" corresponding to a case construction was not being properly
indented to the same level as the beginning of the case construction,
within the indentation error recovery logic.  This has been corrected.

Additional tests have been added to check indentation error recovery
logic for "end" nodes of a project, package and case construction
declaration.  A test was also added to check for newline indentation
just prior to an ERROR node.
  • Loading branch information
brownts committed Nov 20, 2024
1 parent 8ad1277 commit 598f2bc
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 3 deletions.
11 changes: 8 additions & 3 deletions gpr-ts-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

;; Author: Troy Brown <[email protected]>
;; Created: February 2023
;; Version: 0.6.4
;; Version: 0.6.5
;; Keywords: gpr gnat ada languages tree-sitter
;; URL: https://github.com/brownts/gpr-ts-mode
;; Package-Requires: ((emacs "29.1"))
Expand Down Expand Up @@ -326,7 +326,11 @@ If OP is nil or \\='anchor\\=', determine recovery anchor. If OP is
(let ((compound-alist
`(("when" . ( :compound-type "case_item"))
("case" . ( :compound-type "case_construction"
:offset gpr-ts-mode-indent-when-offset))
:offset
(lambda (_anchor)
(if (and ,node (string-equal (treesit-node-type ,node) "end"))
0
gpr-ts-mode-indent-when-offset))))
("package" . ( :compound-type "package_declaration"
:offset
(lambda (_anchor)
Expand Down Expand Up @@ -588,9 +592,10 @@ Return nil if no child of that type is found."
(gpr-ts-mode--anchor-first-sibling-matching "case_item")
gpr-ts-mode-indent-offset)

;; Parent ERROR recovery rules.
;; Error recovery rules.

((and (or (parent-is "ERROR")
(node-is "ERROR")
(gpr-ts-mode--prev-sibling-matches-p "ERROR"))
(gpr-ts-mode--indent-error-recovery-exists-p))
(gpr-ts-mode--anchor-of-indent-error-recovery)
Expand Down
62 changes: 62 additions & 0 deletions test/resources/indent-top_down-nl.erts
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,65 @@ project Hello_World is
for Exec_Dir use Project'Project_Dir;
|
=-=-=

Name: Handle next sibling being an ERROR node

=-=
project Hello_World is
package Binder is
for Default_Switches ("Ada") use|

package Compiler is
for Default_Switches ("Ada") use ("-g");
end Compiler;
end Hello_World;
=-=
project Hello_World is
package Binder is
for Default_Switches ("Ada") use
|

package Compiler is
for Default_Switches ("Ada") use ("-g");
end Compiler;
end Hello_World;
=-=-=

Name: Anchor "end" to project

=-=
project Hello_World is
end|
=-=
project Hello_World is
end
|
=-=-=

Name: Anchor "end" to package

=-=
project Hello_World is
package Compiler is
end|
=-=
project Hello_World is
package Compiler is
end
|
=-=-=

Name: Anchor "end" to case

=-=
project Hello_World is
package Compiler is
case Build is
end|
=-=
project Hello_World is
package Compiler is
case Build is
end
|
=-=-=

0 comments on commit 598f2bc

Please sign in to comment.