mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 13:13:03 +00:00
Fix #979: grok curly braces with LSP-style escaping
* yasnippet-tests.el (escaping-for-lsp-style-snippet-syntax): New test. * yasnippet.el (yas--field-parse-create): rework real-match-end-0 calculation.
This commit is contained in:
parent
a66f15e6c9
commit
1bee3a33c7
@ -781,6 +781,20 @@ mapconcat #'(lambda (arg)
|
||||
(yas-expand-snippet "Look ma! ${1:`(yas-selected-text)`} OK?")
|
||||
(should (string= (yas--buffer-contents) "Look ma! He)}o world! OK?")))))
|
||||
|
||||
(ert-deftest escaping-for-lsp-style-snippet-syntax ()
|
||||
"See Github #979."
|
||||
(should
|
||||
(string= (with-temp-buffer
|
||||
(yas-minor-mode 1)
|
||||
(yas-expand-snippet
|
||||
"Printf(${1:format string}, ${2:args ...interface{\\}})${0}")
|
||||
(yas--buffer-contents))
|
||||
(with-temp-buffer
|
||||
(yas-minor-mode 1)
|
||||
(yas-expand-snippet
|
||||
"Printf(${1:format string}, ${2:args ...interface\\{\\}})${0}")
|
||||
(yas--buffer-contents)))))
|
||||
|
||||
(ert-deftest insert-snippet-with-backslashes-in-active-field ()
|
||||
;; This test case fails if `yas--inhibit-overlay-hooks' is not bound
|
||||
;; in `yas-expand-snippet' (see Github #844).
|
||||
|
@ -4730,7 +4730,14 @@ When multiple expressions are found, only the last one counts."
|
||||
;;
|
||||
(save-excursion
|
||||
(while (re-search-forward yas--field-regexp nil t)
|
||||
(let* ((real-match-end-0 (yas--scan-sexps (1+ (match-beginning 0)) 1))
|
||||
(let* ((brace-scan (yas--scan-sexps (1+ (match-beginning 0)) 1))
|
||||
;; if the `brace-scan' didn't reach a brace, we have a
|
||||
;; snippet with invalid escaping, probably a closing
|
||||
;; brace escaped with two backslashes (github#979). But
|
||||
;; be lenient, because we can.
|
||||
(real-match-end-0 (if (eq ?} (char-before brace-scan))
|
||||
brace-scan
|
||||
(point)))
|
||||
(number (and (match-string-no-properties 1)
|
||||
(string-to-number (match-string-no-properties 1))))
|
||||
(brand-new-field (and real-match-end-0
|
||||
|
Loading…
x
Reference in New Issue
Block a user