You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I setup lsp-mode for c/c++ development using clangd-13.0.0. When I call lsp-treemacs-call-hierarcy, I see the following output:
I checked screenshots for java (https://github.com/emacs-lsp/lsp-treemacs) and saw that call-hierarchy output was a lot better. And ccls-call-hieararchy's output (better but not ideal because it only adds filename):
When using call hierarchy on a huge project, I think it is pretty handy to view file-paths next to functions (to know which packages/components uses the function). Especially when I don't know my way around the code.
After hacking the source, I managed to get the following output (Btw, I also tried to get function signatures but "CallHierarchyItem.detail?" from clangd returns empty string for some reason):
I am kind of an emacs noob, so I might be doing something wrong configuring lsp and end up getting plain output. Anyway, what do you guys think about this?
My changes are (unfortunately, I had to create a dependency to projectile):
(lsp-defun lsp-treemacs-render-symbol ((&CallHierarchyItem :name :uri :detail? :kind) ignored-path-prefix)
"Render INPUT0, an `&DocumentSymbol', to a string.
If SHOW-DETAIL? is set, make use of its `:detail?' field (often
the signature)."
(let ((name name)
(ignored-path-prefix (if ignored-path-prefix ignored-path-prefix ""))
(file-path (propertize (concat (string-remove-prefix ignored-path-prefix (lsp--uri-to-path uri)))
'face 'markdown-inline-code-face)))
(concat name " " file-path)))
(defun lsp-treemacs--call-hierarchy-children (buffer method outgoing ignored-path-prefix node callback)
(-let [item (plist-get node :item)]
(with-current-buffer buffer
(lsp-request-async
method
(list :item item)
(lambda (result)
(funcall
callback
(seq-map
(-lambda (node)
(-let* (((child-item &as &CallHierarchyItem :_name :kind :_detail? :name :uri :_uri :selection-range (&Range :_start) :name :uri :detail? :kind)
(if outgoing
(lsp:call-hierarchy-outgoing-call-to node)
(lsp:call-hierarchy-incoming-call-from node)))
(label (lsp-render-symbol child-item t))
(detailed-label (lsp-treemacs-render-symbol child-item ignored-path-prefix)))
(list :label detailed-label
:key label
:icon (lsp-treemacs-symbol-kind->icon kind)
:children-async (-partial #'lsp-treemacs--call-hierarchy-children
buffer method outgoing ignored-path-prefix)
:ret-action (lambda (&rest _)
(interactive)
(lsp-treemacs--call-hierarchy-ret-action child-item))
:item child-item)))
result)))
:mode 'detached))))
;;;###autoload
(defun lsp-treemacs-call-hierarchy (outgoing)
"Show the incoming call hierarchy for the symbol at point.
With a prefix argument, show the outgoing call hierarchy."
(interactive "P")
(unless (lsp-feature? "textDocument/prepareCallHierarchy")
(user-error "Call hierarchy not supported by the current servers: %s"
(-map #'lsp--workspace-print (lsp-workspaces))))
(let ((buffer (current-buffer))
(ignored-path-prefix (projectile-project-root)))
(select-window
(display-buffer-in-side-window
(lsp-treemacs-render
(seq-map
(-lambda ((item &as &CallHierarchyItem :kind :name :uri :detail?))
(list :label (lsp-treemacs-render-symbol item ignored-path-prefix)
:key name
:icon (lsp-treemacs-symbol-kind->icon kind)
:children-async (-partial
#'lsp-treemacs--call-hierarchy-children
buffer
(if outgoing
"callHierarchy/outgoingCalls"
"callHierarchy/incomingCalls")
outgoing
ignored-path-prefix)
:ret-action (lambda (&rest _)
(interactive)
(lsp-treemacs--call-hierarchy-ret-action item))
:item item))
(lsp-request "textDocument/prepareCallHierarchy"
(lsp--text-document-position-params)))
(concat (if outgoing "Outgoing" "Incoming") " Call Hierarchy")
nil "*Call Hierarchy*" nil t) nil))))
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi all,
I setup lsp-mode for c/c++ development using clangd-13.0.0. When I call lsp-treemacs-call-hierarcy, I see the following output:
I checked screenshots for java (https://github.com/emacs-lsp/lsp-treemacs) and saw that call-hierarchy output was a lot better. And ccls-call-hieararchy's output (better but not ideal because it only adds filename):
When using call hierarchy on a huge project, I think it is pretty handy to view file-paths next to functions (to know which packages/components uses the function). Especially when I don't know my way around the code.
After hacking the source, I managed to get the following output (Btw, I also tried to get function signatures but "CallHierarchyItem.detail?" from clangd returns empty string for some reason):
I am kind of an emacs noob, so I might be doing something wrong configuring lsp and end up getting plain output. Anyway, what do you guys think about this?
My changes are (unfortunately, I had to create a dependency to projectile):
Beta Was this translation helpful? Give feedback.
All reactions