Skip to content

Commit

Permalink
tweak(eglot): move a custom function
Browse files Browse the repository at this point in the history
  • Loading branch information
abougouffa committed Aug 16, 2023
1 parent 048c1d6 commit d61510c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 30 deletions.
1 change: 1 addition & 0 deletions core/me-loaddefs.el
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Examples:
(fn MODES &rest SERVERS)")
(function-put '+eglot-register 'lisp-indent-function 0)
(register-definition-prefixes "../elisp/+eglot" '("+eglot-ccls-inheritance-hierarchy"))


;;; Generated autoloads from ../elisp/+emacs.el
Expand Down
30 changes: 30 additions & 0 deletions elisp/+eglot.el
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,34 @@ Examples:
(eglot-alternatives (ensure-list servers))
(ensure-list (car servers)))))))

;; From: github.com/MaskRay/ccls/wiki/eglot#misc
(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
(+ (pos-bol 0) depth) (pos-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")))


;;; +eglot.el ends here
31 changes: 1 addition & 30 deletions modules/me-prog.el
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,7 @@
:straight t
:hook ((python-ts-mode js-ts-mode css-ts-mode yaml-ts-mode typescript-ts-mode tsx-ts-mode) . combobulate-mode)
:custom
(combobulate-key-prefix "C-c o"))

;; From: github.com/MaskRay/ccls/wiki/eglot#misc
(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
(+ (pos-bol 0) depth) (pos-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"))))
(combobulate-key-prefix "C-c o")))

(use-package evil-textobj-tree-sitter
:straight t
Expand Down

0 comments on commit d61510c

Please sign in to comment.