|
4 | 4 |
|
5 | 5 | ;; Author: Troy Brown <[email protected]>
|
6 | 6 | ;; Created: February 2023
|
7 |
| -;; Version: 0.6.1 |
| 7 | +;; Version: 0.6.2 |
8 | 8 | ;; Keywords: gpr gnat ada languages tree-sitter
|
9 | 9 | ;; URL: https://github.com/brownts/gpr-ts-mode
|
10 | 10 | ;; Package-Requires: ((emacs "29.1"))
|
@@ -352,8 +352,15 @@ Return nil if no child of that type is found."
|
352 | 352 | 'include-node)))
|
353 | 353 | (when (and (gpr-ts-mode--declaration-p candidate)
|
354 | 354 | (not (treesit-search-subtree candidate "ERROR")))
|
355 |
| - (cons (treesit-node-start candidate) |
356 |
| - (treesit-node-end candidate)))))))) |
| 355 | + ;; Prevent interpreting a project declaration "end" |
| 356 | + ;; next to an incomplete package declaration as a |
| 357 | + ;; valid package declaration by checking if the names |
| 358 | + ;; match. |
| 359 | + (unless |
| 360 | + (and (gpr-ts-mode--package-declaration-p candidate) |
| 361 | + (not (gpr-ts-mode--package-declaration-names-match-p candidate))) |
| 362 | + (cons (treesit-node-start candidate) |
| 363 | + (treesit-node-end candidate))))))))) |
357 | 364 | (if region
|
358 | 365 | (progn
|
359 | 366 | (treesit-indent-region (car region) (cdr region))
|
@@ -541,8 +548,10 @@ Return nil if no child of that type is found."
|
541 | 548 | ;; Definition
|
542 | 549 | :language 'gpr
|
543 | 550 | :feature 'definition
|
544 |
| - '((package_declaration |
545 |
| - [name: (identifier) endname: (identifier)] @font-lock-function-name-face) |
| 551 | + '((package_declaration name: (identifier) @font-lock-function-name-face) |
| 552 | + ((package_declaration endname: (identifier) @font-lock-function-name-face) |
| 553 | + @package-declaration |
| 554 | + (:pred gpr-ts-mode--package-declaration-names-match-p @package-declaration)) |
546 | 555 | (typed_string_declaration name: (identifier) @font-lock-type-face)
|
547 | 556 | (variable_declaration name: (identifier) @font-lock-variable-name-face)
|
548 | 557 | (attribute_declaration name: (identifier) @font-lock-property-name-face))
|
@@ -614,6 +623,14 @@ Return nil if no child of that type is found."
|
614 | 623 | (packages (mapcar #'downcase gpr-ts-mode-package-names)))
|
615 | 624 | (seq-find (apply-partially #'string-equal identifier) packages)))
|
616 | 625 |
|
| 626 | +(defun gpr-ts-mode--package-declaration-names-match-p (node) |
| 627 | + "Check if names match in package declaration NODE." |
| 628 | + (when (gpr-ts-mode--package-declaration-p node) |
| 629 | + (let ((name (treesit-node-child-by-field-name node "name")) |
| 630 | + (endname (treesit-node-child-by-field-name node "endname"))) |
| 631 | + (string-equal-ignore-case (treesit-node-text name t) |
| 632 | + (treesit-node-text endname t))))) |
| 633 | + |
617 | 634 |
|
618 | 635 | ;;; Imenu
|
619 | 636 |
|
|
0 commit comments