Skip to content

Commit 530945b

Browse files
committed
Tidy from code review comments.
Use 'dynamic-icon in leaf node to delegate icon rendering functionality to parent node. Remove tab action from leaf node. Use arrow icons from lsp-treemacs theme and three spaces for leaf nodes to align parent children correctly. Remove commented code from expandable node and metals root definition. Remove overriding return action for root, this does have the effect of providing a treemacs error message and flash the element red - but some people may prefer this. Remove key definition for invoking treemacs node debug helper - not required. Fix file header with correct summary for treeview. Use treemacs variables to define side window position and width. When switching buffers ensure that the new buffer is associated with a Metals server so that we don't attempt to switch treeviews on another language server. In order to achieve this reliably we ensure that the buffer being switched to has a major mode of scala-mode.
1 parent ba47aa8 commit 530945b

File tree

1 file changed

+27
-29
lines changed

1 file changed

+27
-29
lines changed

lsp-metals-treeview.el

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;;; lsp-metals-treeview.el --- Scala Client settings -*- lexical-binding: t; -*-
1+
;;; lsp-metals-treeview.el --- LSP Scala Metals Treeview -*- lexical-binding: t; -*-
22

33
;; Copyright (C) 2019 Darren Syzling <[email protected]>
44

@@ -126,20 +126,28 @@ lsp-mode.")
126126
"When the treeview is displayed and visible this variable
127127
will hold the workspace associated with the instance.")
128128

129+
(defun lsp--metals-treeview-position (slot)
130+
"Side window position of Metals treeview with the given SLOT.
131+
Uses defaults for treemacs position and width."
132+
`((side . ,treemacs-position)
133+
(slot . ,slot)
134+
(window-width . ,treemacs-width)))
135+
129136
(defun lsp--metals-treeview-buffer-changed ()
130137
"When the buffer is switched check to see if a treeview
131138
is currently being displayed and whether we need to show
132139
an alternative workspace's treeview."
133140
(with-current-buffer (current-buffer)
134-
(-if-let (workspaces (lsp-workspaces))
135-
(progn
136-
(when (and lsp--metals-treeview-active-view-workspace
137-
(not (member lsp--metals-treeview-active-view-workspace
138-
workspaces)))
139-
;; hide current treeview and show new window associated with
140-
;; the current workspace of file in buffer.
141-
(lsp--metals-treeview-hide-window lsp--metals-treeview-active-view-workspace)
142-
(lsp--metals-treeview-show-window (car workspaces)))))))
141+
(when (and (eq major-mode 'scala-mode)
142+
(lsp-find-workspace lsp--metals-treeview-metals-server-id nil)
143+
lsp--metals-treeview-active-view-workspace
144+
(not (member lsp--metals-treeview-active-view-workspace
145+
(lsp-workspaces))))
146+
147+
;; hide current treeview and show new window associated with
148+
;; the current workspace of file in buffer.
149+
(lsp--metals-treeview-hide-window lsp--metals-treeview-active-view-workspace)
150+
(lsp--metals-treeview-show-window (car (lsp-workspaces))))))
143151

144152
(defun lsp--metals-treeview-buffer-list-update ()
145153
(run-with-idle-timer lsp-metals-treeview-workspace-switch-delay
@@ -418,7 +426,7 @@ side window based based on an increasing SLOT number position."
418426
(when-let ((view (car views)))
419427
(lsp--metals-show-view workspace
420428
(alist-get :view-id view)
421-
`((side . left) (slot . ,slot)))
429+
(lsp--metals-treeview-position slot))
422430
(lsp--metals-send-treeview-visibility-did-change workspace (alist-get :view-id view) t)
423431
(lsp--metals-display-views workspace (cdr views) (+ 1 slot))))
424432

@@ -454,7 +462,7 @@ relative to the others. "
454462
(add-hook 'lsp-after-uninitialized-hook #'lsp--metals-treeview-on-workspace-shutdown))
455463

456464
;; No views are available - show temp message.
457-
(lsp--metals-show-waiting-message workspace `((side . left) (slot . ,slot)))))
465+
(lsp--metals-show-waiting-message workspace (lsp--metals-treeview-position slot))))
458466

459467
(defun lsp--metals-treeview-refresh (workspace params)
460468
"Top level treeview changed - Metals has potentially given
@@ -645,11 +653,13 @@ expandable node. If the node isn't expandable for now do not show an icon. "
645653
(-if-let (icon (ht-get metals-node "icon"))
646654
(treemacs-get-icon-value icon nil "Metals")
647655
(if (ht-get metals-node "collapseState")
648-
(if open-form?
649-
(treemacs-as-icon "- " 'face 'font-lock-string-face)
650-
(treemacs-as-icon "+ " 'face 'font-lock-string-face))
656+
(treemacs-get-icon-value
657+
(if open-form? 'expanded 'collapsed)
658+
nil
659+
lsp-treemacs-theme)
660+
651661
;; leaf node without an icon
652-
(treemacs-as-icon " " 'face 'font-lock-string-face))))
662+
(treemacs-as-icon " " 'face 'font-lock-string-face))))
653663

654664
;; to support not showing icons at all - leave for debugging for now
655665
;; (defun lsp--metals-treeview-without-icons (metals-node)
@@ -722,11 +732,9 @@ collapsed or expanded."
722732
;; We can possibly remove the leaf node definition and
723733
;; replace lsp--metals-treeview-state to return treemacs-metals-node-closed-state
724734
;;
725-
(treemacs-define-leaf-node metals-leaf
726-
(treemacs-get-icon-value 'root nil "Metals")
735+
(treemacs-define-leaf-node metals-leaf 'dynamic-icon
727736

728737
:ret-action #'lsp--metals-treeview-exec-node-action
729-
:tab-action #'lsp--metals-treeview-exec-node-action
730738
:mouse1-action (lambda (&rest args)
731739
(interactive)
732740
(lsp--metals-treeview-exec-node-action args)))
@@ -742,9 +750,6 @@ collapsed or expanded."
742750
;;
743751

744752
(treemacs-define-expandable-node metals-node
745-
;; :icon-open (treemacs-as-icon "- " 'face 'font-lock-string-face)
746-
;; :icon-closed (treemacs-as-icon "+ " 'face 'font-lock-string-face)
747-
748753
:icon-open-form (lsp--metals-treeview-icon
749754
(treemacs-button-get (treemacs-node-at-point) :node) t)
750755
:icon-closed-form (lsp--metals-treeview-icon
@@ -777,15 +782,10 @@ collapsed or expanded."
777782
;;
778783

779784
(treemacs-define-expandable-node metals-root
780-
;; :icon-open (treemacs-as-icon "- " 'face 'font-lock-string-face)
781-
;; :icon-closed (treemacs-as-icon "+ " 'face 'font-lock-string-face)
782785
:icon-open (treemacs-get-icon-value 'root nil "Metals")
783786
:icon-closed (treemacs-get-icon-value 'root nil "Metals")
784787
:query-function (lsp--metals-treeview-get-children lsp--metals-view-id)
785788

786-
;; Ignore return action on root.
787-
:ret-action '(lambda(&rest _))
788-
789789
:render-action
790790
(treemacs-render-node
791791
:icon (lsp--metals-treeview-icon item nil)
@@ -864,8 +864,6 @@ Metals Item: %s"
864864
(-some-> node (treemacs-button-get :parent) (treemacs--get-label-of))
865865
(treemacs-button-get node :eldoc)
866866
(-some-> node (treemacs-button-get :node)))))
867-
(global-set-key (kbd "C-x C-ö") #'treemacs-mu4e-debug-node)
868-
869867

870868

871869
(provide 'lsp-metals-treeview)

0 commit comments

Comments
 (0)