@@ -1566,6 +1566,68 @@ current symbol."
15661566
15671567
15681568
1569+ (defconst lsp-java--hierarchy-sub 0 )
1570+ (defconst lsp-java--hierarchy-super 1 )
1571+ (defconst lsp-java--hierarchy-both 2 )
1572+
1573+ (defun lsp-java--type-hierarchy-render-nodes (nodes direction load-direction )
1574+ (-map (-lambda ((it &as &TypeHierarchyItem :name :kind :uri :selection-range (&Range :start )))
1575+ (list :label (concat name
1576+ (cond
1577+ ((eq lsp-java--hierarchy-sub direction) (propertize " ↓" 'face 'shadow ))
1578+ ((eq lsp-java--hierarchy-super direction) (propertize " ↑" 'face 'shadow ))))
1579+ :key name
1580+ :icon (lsp-treemacs-symbol-kind->icon kind)
1581+ :children-async (-partial #'lsp-java--type-hierarchy-render it load-direction)
1582+ :ret-action #'lsp-treemacs-go-to
1583+ :position start
1584+ :uri uri
1585+ :actions `([" Go to" lsp-treemacs-go-to])))
1586+ nodes))
1587+
1588+ (lsp-defun lsp-java--type-hierarchy-render ((item &as &TypeHierarchyItem :uri :range (&Range :start )) direction _ callback)
1589+ (lsp-request-async
1590+ " workspace/executeCommand"
1591+ (list :command " java.navigate.resolveTypeHierarchy"
1592+ :arguments (vector (lsp--json-serialize item)
1593+ (number-to-string direction)
1594+ " 1" ))
1595+ (-lambda ((&TypeHierarchyItem :children? :parents? ))
1596+ (funcall callback (nconc (lsp-java--type-hierarchy-render-nodes
1597+ children? lsp-java--hierarchy-sub direction)
1598+ (lsp-java--type-hierarchy-render-nodes
1599+ parents? lsp-java--hierarchy-super direction))))))
1600+
1601+ (defun lsp-java-type-hierarchy (direction )
1602+ " Show the type hierarchy for the symbol at point.
1603+ With prefix 0 show sub-types.
1604+ With prefix 1 show super-types.
1605+ With prefix 2 show both."
1606+ (interactive " P" )
1607+ (setq direction (or direction lsp-java--hierarchy-both))
1608+ (let ((workspaces (lsp-workspaces))
1609+ (result
1610+ (lsp-workspace-command-execute
1611+ " java.navigate.openTypeHierarchy"
1612+ (vector (lsp--json-serialize (lsp--text-document-position-params))
1613+ (number-to-string direction)
1614+ " 0" ))))
1615+ (if result
1616+ (pop-to-buffer
1617+ (lsp-treemacs-render
1618+ (lsp-java--type-hierarchy-render-nodes (vector result) nil direction)
1619+ (concat (cond
1620+ ((eq lsp-java--hierarchy-sub direction) " Sub" )
1621+ ((eq lsp-java--hierarchy-super direction) " Super" )
1622+ ((eq lsp-java--hierarchy-both direction) " Sub/Super" ))
1623+ " Type Hierarchy" )
1624+ nil
1625+ " *lsp-java-type-hierarchy*"
1626+ nil
1627+ t ))
1628+ (user-error " No class under point." ))
1629+ (setq lsp--buffer-workspaces workspaces)))
1630+
15691631(provide 'lsp-java )
15701632; ;; lsp-java.el ends here
15711633
0 commit comments