From a89e0ce17a934ac867571611c40056b6e3a206a7 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 29 Oct 2018 19:13:35 -0700 Subject: [PATCH] eglot helper --- Emacs.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Emacs.md b/Emacs.md index 91b0899..198fef5 100644 --- a/Emacs.md +++ b/Emacs.md @@ -291,3 +291,36 @@ For out-of-band changes to the files in the workspace that are not made in the L `(ccls-reload)` to reload/rebuild indexes for every file. * Performance of lsp-ui-flycheck https://github.com/emacs-lsp/lsp-ui/issues/45 + +### eglot + +Use help window to display hierarchies: + +```elisp +(defun eglot-ccls-inheritance-hierarchy (&optional derived) + "Show inheritance hierarchy for the thing at point. +If DERIVED is non-nil (interactively, with prefix argument), show +the children of class at point." + (interactive "P") + (if-let* ((res (jsonrpc-request + (eglot--current-server-or-lose) + :$ccls/inheritance + (append (eglot--TextDocumentPositionParams) + `(:derived ,(if derived t :json-false)) + '(:levels 100) '(:hierarchy t)))) + (tree (list (cons 0 res)))) + (with-help-window "*ccls inheritance*" + (with-current-buffer standard-output + (while tree + (pcase-let ((`(,depth . ,node) (pop tree))) + (cl-destructuring-bind (&key uri range) (plist-get node :location) + (insert (make-string depth ?\ ) (plist-get node :name) "\n") + (make-text-button (+ (point-at-bol 0) depth) (point-at-eol 0) + 'action (lambda (_arg) + (interactive) + (find-file (eglot--uri-to-path uri)) + (goto-char (car (eglot--range-region range))))) + (cl-loop for child across (plist-get node :children) + do (push (cons (1+ depth) child) tree))))))) + (eglot--error "Hierarchy unavailable"))) +```