ruby-ts-mode: Fine-tune s-p-f on symbols (bug#62086)

* lisp/progmodes/ruby-ts-mode.el (ruby-ts--s-p-query):
Don't match ':' in symbol node text.  Or '_', I suppose.
(ruby-ts--syntax-propertize): Make sure to only put the '_' syntax
on punctuation syntax characters, and not on the whole symbol (to
e.g. have symbols like :foo? include text recognized as word).

* test/lisp/progmodes/ruby-ts-mode-tests.el
(ruby-ts-syntax-propertize-symbol): New test.
This commit is contained in:
Dmitry Gutov 2023-03-09 23:49:39 +02:00
parent 29228e24f2
commit ecdfd584a5
2 changed files with 19 additions and 2 deletions

View file

@ -1026,7 +1026,7 @@ leading double colon is not added."
(:match "\\`?[#\"'`:?]" @char))
;; Symbols like :+, :<=> or :foo=.
((simple_symbol) @symbol
(:match "[[:punct:]]" @symbol))
(:match "\\s." @symbol))
;; Method calls with name ending with ? or !.
((call method: (identifier) @ident)
(:match "[?!]\\'" @ident))
@ -1058,7 +1058,9 @@ leading double colon is not added."
(put-text-property (1- (treesit-node-end node)) (treesit-node-end node)
'syntax-table (string-to-syntax "_")))
('symbol
(put-text-property (1+ (treesit-node-start node)) (treesit-node-end node)
(goto-char (treesit-node-end node))
(skip-syntax-backward "." (treesit-node-start node))
(put-text-property (point) (treesit-node-end node)
'syntax-table (string-to-syntax "_")))
('heredoc
(put-text-property (treesit-node-start node) (1+ (treesit-node-start node))

View file

@ -258,6 +258,21 @@ The whitespace before and including \"|\" on each line is removed."
(delete-char 1)
(should (string= (ruby-ts-add-log-current-function) "M::C#foo"))))
(ert-deftest ruby-ts-syntax-propertize-symbol ()
(pcase-dolist (`(,str . ,expected)
'((":abc" . ":abc")
(":foo?" . #(":foo?" 4 5 (syntax-table (3))))
(":<=>" . #(":<=>" 1 4 (syntax-table (3))))))
(ruby-ts-with-temp-buffer str
(syntax-propertize (point-max))
(let ((text (buffer-string)))
(remove-text-properties 0 (1- (point-max))
'(fontified)
text)
(should (equal-including-properties
text
expected))))))
(defmacro ruby-ts-resource-file (file)
`(when-let ((testfile ,(or (macroexp-file-name)
buffer-file-name)))