Commit d4550125 authored by Jed Ye's avatar Jed Ye Committed by Fangrui Song

Improve performance of cquery--publish-semantic-highlighting (#8)

parent cc1fe7a0
......@@ -257,6 +257,16 @@ If nil, disable semantic highlighting."
(funcall fn cquery-sem-member-var-faces)
(funcall fn cquery-sem-free-var-faces))))))))
(defun cquery--read-semantic-ranges (symbol face)
(--map (let ((start (gethash "start" it))
(end (gethash "end" it)))
(list (cons (gethash "line" start)
(gethash "character" start))
(cons (gethash "line" end)
(gethash "character" end))
face))
(gethash "ranges" symbol)))
(defun cquery--publish-semantic-highlighting (_workspace params)
"Publish semantic highlighting information according to PARAMS."
(when cquery-sem-highlight-method
......@@ -266,13 +276,31 @@ If nil, disable semantic highlighting."
(when buffer
(with-current-buffer buffer
(save-excursion
(with-silent-modifications
(cquery--clear-sem-highlights)
(dolist (symbol symbols)
(-when-let (face (funcall cquery-sem-face-function symbol))
(dolist (range
(mapcar 'cquery--read-range (gethash "ranges" symbol)))
(cquery--make-sem-highlight range buffer face)))))))))))
(with-silent-modifications
(cquery--clear-sem-highlights)
(let ((last-line-number 0) ranges range-start range-end)
(dolist (symbol symbols)
(-when-let (face (funcall cquery-sem-face-function symbol))
(setq ranges
(nconc (cquery--read-semantic-ranges symbol face)
ranges))))
;; sort ranges by line number
(setq ranges
(sort ranges (lambda (x y) (< (caar x) (caar y)))))
(ignore-errors
(save-excursion
(goto-char (point-min))
(loop for (start end face) in ranges do
(forward-line (- (car start) last-line-number))
(forward-char (cdr start))
;; start of range
(setq range-start (point))
(forward-line (- (car end) (car start)))
(forward-char (cdr end))
;; end of range
(setq range-end (point))
(cquery--make-sem-highlight (cons range-start range-end) buffer face)
(setq last-line-number (car end)))))))))))))
(defmacro cquery-use-default-rainbow-sem-highlight ()
"Use default rainbow semantic highlighting theme."
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment