mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-06 06:20:55 -08:00
rust-ts-mode: handle invalid rust syntax without signaling
Don't signal an error when encountering invalid rust syntax. Without this patch, invalid rust code would prevent a chunk of the buffer from being highlighted (bug#79272). * lisp/progmodes/rust-ts-mode.el (rust-ts-mode--fontify-scope): (rust-ts-mode--fontify-pattern): Avoid calling `string-match-p' on nil when a node is missing a parent. * test/lisp/progmodes/rust-ts-mode-resources/font-lock-no-parent.rs: Rust file that reproduces the issue. * test/lisp/progmodes/rust-ts-mode-tests.el: Test case to reproduce the issue.
This commit is contained in:
parent
1a549762ed
commit
f0b987c32c
3 changed files with 19 additions and 4 deletions
|
|
@ -366,7 +366,8 @@ See https://doc.rust-lang.org/reference/tokens.html#suffixes.")
|
||||||
tail-p
|
tail-p
|
||||||
(string-match-p
|
(string-match-p
|
||||||
"\\`\\(?:use_list\\|call_expression\\|use_as_clause\\|use_declaration\\)\\'"
|
"\\`\\(?:use_list\\|call_expression\\|use_as_clause\\|use_declaration\\)\\'"
|
||||||
(treesit-node-type (treesit-node-parent (treesit-node-parent node)))))
|
(or (treesit-node-type (treesit-node-parent (treesit-node-parent node)))
|
||||||
|
"no_parent")))
|
||||||
nil)
|
nil)
|
||||||
(t 'font-lock-constant-face))))
|
(t 'font-lock-constant-face))))
|
||||||
(when face
|
(when face
|
||||||
|
|
@ -387,9 +388,9 @@ See https://doc.rust-lang.org/reference/tokens.html#suffixes.")
|
||||||
,(treesit-query-compile 'rust '((identifier) @id
|
,(treesit-query-compile 'rust '((identifier) @id
|
||||||
(shorthand_field_identifier) @id)))))
|
(shorthand_field_identifier) @id)))))
|
||||||
(pcase-dolist (`(_name . ,id) captures)
|
(pcase-dolist (`(_name . ,id) captures)
|
||||||
(unless (string-match-p "\\`scoped_\\(?:type_\\)?identifier\\'"
|
(unless (string-match-p
|
||||||
(treesit-node-type
|
"\\`scoped_\\(?:type_\\)?identifier\\'"
|
||||||
(treesit-node-parent id)))
|
(or (treesit-node-type (treesit-node-parent id)) "no_parent"))
|
||||||
(treesit-fontify-with-override
|
(treesit-fontify-with-override
|
||||||
(treesit-node-start id) (treesit-node-end id)
|
(treesit-node-start id) (treesit-node-end id)
|
||||||
'font-lock-variable-name-face override start end)))))))
|
'font-lock-variable-name-face override start end)))))))
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
+// intentionally invalid syntax
|
||||||
|
+const THING: [u8; 48] = [];
|
||||||
|
|
||||||
|
// should recover here and highlight the text below
|
||||||
|
trait Foo() {
|
||||||
|
// ^ font-lock-keyword-face
|
||||||
|
}
|
||||||
|
|
@ -39,6 +39,13 @@
|
||||||
(ert-font-lock-test-file (ert-resource-file "font-lock-number.rs")
|
(ert-font-lock-test-file (ert-resource-file "font-lock-number.rs")
|
||||||
'rust-ts-mode)))
|
'rust-ts-mode)))
|
||||||
|
|
||||||
|
(ert-deftest rust-ts-test-no-parent ()
|
||||||
|
(skip-unless (treesit-ready-p 'rust))
|
||||||
|
(let ((treesit-font-lock-level 4)
|
||||||
|
(rust-ts-mode-fontify-number-suffix-as-type t))
|
||||||
|
(ert-font-lock-test-file (ert-resource-file "font-lock-no-parent.rs")
|
||||||
|
'rust-ts-mode)))
|
||||||
|
|
||||||
(provide 'rust-ts-mode-tests)
|
(provide 'rust-ts-mode-tests)
|
||||||
|
|
||||||
;;; rust-ts-mode-tests.el ends here
|
;;; rust-ts-mode-tests.el ends here
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue