Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto select-window on find references/implementations #33

Merged
merged 4 commits into from
Feb 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions lsp-treemacs.el
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,8 @@
(setq-local face-remapping-alist '((button . default)))
(lsp-treemacs--set-mode-line-format search-buffer title)
(lsp-treemacs-generic-refresh)
(when expand? (lsp-treemacs--expand 'LSP-Generic))
(when (equal expand? '(4))
(lsp-treemacs--expand 'LSP-Generic))
(current-buffer))))

(defalias 'lsp-treemacs--show-references 'lsp-treemacs-render)
Expand All @@ -1178,10 +1179,10 @@ depending on if a custom mode line is detected."
(t
(setq mode-line-format title)))))

(defun lsp-treemacs--do-search (method params title expand?)
(let ((search-buffer (get-buffer-create "*LSP Lookup*")))
(display-buffer-in-side-window search-buffer
'((side . bottom)))
(defun lsp-treemacs--do-search (method params title prefix-args)
(let ((search-buffer (get-buffer-create "*LSP Lookup*"))
(window (display-buffer-in-side-window (get-buffer-create "*LSP Lookup*")
'((side . bottom)))))
(lsp-request-async
method
params
Expand All @@ -1191,11 +1192,15 @@ depending on if a custom mode line is detected."
(let ((lsp-file-truename-cache (ht)))
(lsp-treemacs-render (lsp-treemacs--handle-references refs)
(format title (length refs))
expand?)))
prefix-args)))
(lsp--info "Refresh completed!"))
:mode 'detached
:cancel-token :treemacs-lookup)

(unless (zerop prefix-args)
(select-window window)
(set-window-dedicated-p window t))

(with-current-buffer search-buffer
(lsp-treemacs-initialize)
(lsp-treemacs--set-mode-line-format search-buffer " Loading... ")
Expand All @@ -1205,7 +1210,7 @@ depending on if a custom mode line is detected."
;;;###autoload
(defun lsp-treemacs-references (arg)
"Show the references for the symbol at point.
With a prefix argument, expand the tree of references automatically."
With a prefix argument, select the new window and expand the tree of references automatically."
(interactive "P")
(lsp-treemacs--do-search "textDocument/references"
`(:context (:includeDeclaration t) ,@(lsp--text-document-position-params))
Expand All @@ -1215,7 +1220,7 @@ With a prefix argument, expand the tree of references automatically."
;;;###autoload
(defun lsp-treemacs-implementations (arg)
"Show the implementations for the symbol at point.
With a prefix argument, expand the tree of implementations automatically."
With a prefix argument, select the new window expand the tree of implementations automatically."
(interactive "P")
(lsp-treemacs--do-search "textDocument/implementation"
(lsp--text-document-position-params)
Expand Down