@@ -103,6 +103,11 @@ which hides the buffers within the buffer list in Emacs.")
103103
104104(defconst lsp--metals-treeview-metadata-key " metals-treeview"
105105 " Metadata key to store treeview data struct within workspace" )
106+
107+ (defconst lsp--metals-treeview-metals-server-id 'metals
108+ " Server id metals lsp client should be registered from within
109+ lsp-mode." )
110+
106111; ;
107112; ; Treemacs doesn't support a unique key - :-key-form isn't actually defined as
108113; ; being unique and you cannot search by this key - only by path. Since Metals
@@ -166,7 +171,7 @@ the WORKSPACE."
166171 " Add the BUFFER to the list of treeview buffers associated with
167172the WORKSPACE."
168173 (-when-let* ((state (lsp--metals-treeview-get-data workspace))
169- (buffers (append (lsp--metals-treeview-data-buffers state) ( list buffer ))))
174+ (buffers (push buffer (lsp--metals-treeview-data-buffers state))))
170175 (setf (lsp--metals-treeview-data-buffers state) buffers)))
171176
172177(defun lsp--metals-treeview-remove-buffers (workspace )
@@ -242,12 +247,11 @@ frame. Check to see if any of these buffers are metals
242247treeview buffers and if so return the buffers."
243248 ; ; retrieve any treeview buffers that are visible
244249 (->> (window-list (selected-frame ))
245- (-map (lambda (window )
250+ (-keep (lambda (window )
246251 (let ((buffer (window-buffer window)))
247252 (when (s-starts-with? lsp--metals-treeview-buffer-prefix
248253 (buffer-name buffer))
249- buffer))))
250- (remove nil )))
254+ buffer))))))
251255
252256(defun lsp--metals-treeview-visible? (workspace )
253257 " Is the metals treeview associated with the WORKSPACE currently visible?"
@@ -271,11 +275,10 @@ but not visible?"
271275 " Return visibility status of metals treeview associated
272276with WORKSPACE. Return 'visible, 'hidden, 'none depending on state of
273277treeview."
274- (if (lsp--metals-treeview-visible? workspace)
275- 'visible
276- (if (lsp--metals-treeview-exists? workspace)
277- 'hidden
278- 'none )))
278+ (cond
279+ ((lsp--metals-treeview-visible? workspace) 'visible )
280+ ((lsp--metals-treeview-exists? workspace) 'hidden )
281+ (t 'none )))
279282
280283(defun lsp--metals-treeview-show-window (workspace &optional select-window? )
281284 " Show metals treeview window associated with WORKSPACE and
@@ -807,20 +810,14 @@ that this will be sent during initial connection."
807810 :json-false )))))))
808811 (setf (lsp--client-custom-capabilities metals-client) custom-capabilities)))
809812
810-
811- (defun lsp-metals-treeview-reveal ()
812- (interactive )
813- (let (workspace (car (lsp-workspaces)))
814- (lsp-log " response from treeViewReveal %s"
815- (json-encode
816- (lsp-request " metals/treeViewReveal" (lsp--text-document-position-params))))))
817-
818813(defun lsp-metals-treeview (&optional workspace )
819814 " Display the Metals treeview window for the WORKSPACE (optional). If
820815WORKSPACE is not specified obtain the current workspace for the file in
821816the current buffer."
822817 (interactive )
823- (-if-let* ((workspace (or workspace (car (lsp-workspaces)))))
818+ (-if-let* ((workspace
819+ (or workspace
820+ (lsp-find-workspace lsp--metals-treeview-metals-server-id nil ))))
824821 (lsp--metals-treeview-show-window workspace t )
825822 (message " Current buffer is not within Metals workspace " )))
826823
@@ -832,7 +829,7 @@ to Metals to indicate we want treeview messages and wire up notification
832829handlers."
833830 (interactive )
834831 (with-eval-after-load 'lsp-metals
835- (let ((metals-client (ht-get lsp-clients ' metals )))
832+ (let ((metals-client (ht-get lsp-clients lsp-- metals-treeview-metals-server-id )))
836833 (lsp--metals-treeview-add-notification-handlers metals-client)
837834 (lsp--metals-treeview-add-custom-capabilities metals-client enable))))
838835
0 commit comments