File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 123
123
(defun ts-fold-parsers-go ()
124
124
" Rule set for Go."
125
125
'((block . ts-fold-range-seq)
126
- (comment . ts-fold-range-seq)))
126
+ (comment . ts-fold-range-seq)
127
+ (const_declaration . (lambda (node offset )
128
+ (ts-fold-range-markers node offset " (" " )" )))
129
+ (field_declaration_list . ts-fold-range-seq)
130
+ (import_spec_list . ts-fold-range-seq)
131
+ (interface_type . (lambda (node offset )
132
+ (ts-fold-range-markers node offset " {" " }" )))))
127
133
128
134
(defun ts-fold-parsers-html ()
129
135
" Rule set for HTML."
Original file line number Diff line number Diff line change @@ -392,6 +392,28 @@ Argument OFFSET can be used to tweak the final beginning and end position."
392
392
(end (1- (tsc-node-end-position node))))
393
393
(ts-fold--cons-add (cons beg end) offset)))
394
394
395
+ (defun ts-fold-range-markers (node offset start-seq &optional end-seq )
396
+ " Returns the fold range for NODE with an OFFSET where the range
397
+ starts at the end of the first occurence of the regular expression
398
+ START-SEQ and ends at the end of the node or the last occurence of
399
+ the optional regular expression LAST-SEQ.
400
+
401
+
402
+ If no occurence is found for START-SEQ or END-SEQ or the
403
+ occurences overlap, then the range returned is nil."
404
+ (when start-seq
405
+ (let ((beg (tsc-node-start-position node))
406
+ (end (tsc-node-end-position node)))
407
+ (save-excursion
408
+ (when-let* ((start-position (progn (goto-char beg)
409
+ (search-forward-regexp start-seq end t )))
410
+ (end-position (if end-seq
411
+ (progn (goto-char end)
412
+ (search-backward-regexp end-seq beg t ))
413
+ (1- end))))
414
+ (unless (> start-position end-position)
415
+ (ts-fold--cons-add (cons start-position end-position) offset)))))))
416
+
395
417
(defun ts-fold-range-line-comment (node offset prefix )
396
418
" Define fold range for line comment.
397
419
You can’t perform that action at this time.
0 commit comments