發現documentSymbol結合avy很好用,可以快速跳轉到定義/引用。 剛剛給ccls增加了一個bool all
參數,可以顯示所有符號,而不僅是默認的outline。
(defun +my/avy-document-symbol ()
(interactive)
(let (ranges point0 point1 (line 0) (col 0) (w (selected-window)) candidates)
(save-excursion
(goto-char 1)
(dolist (loc
(lsp--send-request (lsp--make-request
"textDocument/documentSymbol"
;; :all t is specific to ccls . cquery does not have this parameter
`(:textDocument ,(lsp--text-document-identifier) :all t))))
(let ((range (->> loc (gethash "location") (gethash "range"))))
(-let* [((&hash "line" l0 "character" c0) (gethash "start" range))
((&hash "line" l1 "character" c1) (gethash "end" range))]
(when (or (< line l0) (and (= line l0) (<= col c0)))
(forward-line (- l0 line))
(forward-char c0)
(setq point0 (point))
(forward-line (- l1 l0))
(forward-char c1)
(setq point1 (point))
(setq line l1 col c1)
(push `((,point0 . ,point1) . ,w) candidates))))))
(avy-with avy-document-symbol
(avy--process candidates
(avy--style-fn avy-style)))))
這個改進下感覺可以扔到lsp-ui裏去。
我把;
绑定到
:n ";" (λ! (+my/avy-document-symbol) (+my/find-definitions))
效果: