1
- ; ;; lsp-metals-treeview.el --- Scala Client settings -*- lexical-binding : t ; -*-
1
+ ; ;; lsp-metals-treeview.el --- LSP Scala Metals Treeview -*- lexical-binding : t ; -*-
2
2
3
3
; ; Copyright (C) 2019 Darren Syzling <[email protected] >
4
4
@@ -126,20 +126,28 @@ lsp-mode.")
126
126
" When the treeview is displayed and visible this variable
127
127
will hold the workspace associated with the instance." )
128
128
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
+
129
136
(defun lsp--metals-treeview-buffer-changed ()
130
137
" When the buffer is switched check to see if a treeview
131
138
is currently being displayed and whether we need to show
132
139
an alternative workspace's treeview."
133
140
(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))))))
143
151
144
152
(defun lsp--metals-treeview-buffer-list-update ()
145
153
(run-with-idle-timer lsp-metals-treeview-workspace-switch-delay
@@ -418,7 +426,7 @@ side window based based on an increasing SLOT number position."
418
426
(when-let ((view (car views)))
419
427
(lsp--metals-show-view workspace
420
428
(alist-get :view-id view)
421
- `((side . left) ( slot . , slot ) ))
429
+ (lsp--metals-treeview-position slot))
422
430
(lsp--metals-send-treeview-visibility-did-change workspace (alist-get :view-id view) t )
423
431
(lsp--metals-display-views workspace (cdr views) (+ 1 slot))))
424
432
@@ -454,7 +462,7 @@ relative to the others. "
454
462
(add-hook 'lsp-after-uninitialized-hook #'lsp--metals-treeview-on-workspace-shutdown ))
455
463
456
464
; ; 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))))
458
466
459
467
(defun lsp--metals-treeview-refresh (workspace params )
460
468
" 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. "
645
653
(-if-let (icon (ht-get metals-node " icon" ))
646
654
(treemacs-get-icon-value icon nil " Metals" )
647
655
(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
+
651
661
; ; leaf node without an icon
652
- (treemacs-as-icon " " 'face 'font-lock-string-face ))))
662
+ (treemacs-as-icon " " 'face 'font-lock-string-face ))))
653
663
654
664
; ; to support not showing icons at all - leave for debugging for now
655
665
; ; (defun lsp--metals-treeview-without-icons (metals-node)
@@ -722,11 +732,9 @@ collapsed or expanded."
722
732
; ; We can possibly remove the leaf node definition and
723
733
; ; replace lsp--metals-treeview-state to return treemacs-metals-node-closed-state
724
734
; ;
725
- (treemacs-define-leaf-node metals-leaf
726
- (treemacs-get-icon-value 'root nil " Metals" )
735
+ (treemacs-define-leaf-node metals-leaf 'dynamic-icon
727
736
728
737
:ret-action #'lsp--metals-treeview-exec-node-action
729
- :tab-action #'lsp--metals-treeview-exec-node-action
730
738
:mouse1-action (lambda (&rest args )
731
739
(interactive )
732
740
(lsp--metals-treeview-exec-node-action args)))
@@ -742,9 +750,6 @@ collapsed or expanded."
742
750
; ;
743
751
744
752
(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
-
748
753
:icon-open-form (lsp--metals-treeview-icon
749
754
(treemacs-button-get (treemacs-node-at-point) :node ) t )
750
755
:icon-closed-form (lsp--metals-treeview-icon
@@ -777,15 +782,10 @@ collapsed or expanded."
777
782
; ;
778
783
779
784
(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)
782
785
:icon-open (treemacs-get-icon-value 'root nil " Metals" )
783
786
:icon-closed (treemacs-get-icon-value 'root nil " Metals" )
784
787
:query-function (lsp--metals-treeview-get-children lsp--metals-view-id)
785
788
786
- ; ; Ignore return action on root.
787
- :ret-action '(lambda (&rest _))
788
-
789
789
:render-action
790
790
(treemacs-render-node
791
791
:icon (lsp--metals-treeview-icon item nil )
@@ -864,8 +864,6 @@ Metals Item: %s"
864
864
(-some-> node (treemacs-button-get :parent ) (treemacs--get-label-of))
865
865
(treemacs-button-get node :eldoc )
866
866
(-some-> node (treemacs-button-get :node )))))
867
- (global-set-key (kbd " C-x C-ö" ) #'treemacs-mu4e-debug-node )
868
-
869
867
870
868
871
869
(provide 'lsp-metals-treeview )
0 commit comments