Skip to content

Commit 3436153

Browse files
authored
Auto select-window on find references/implementations (#33)
* select-window on references/implementations * Select window only when has a prefix-arguments * Check prefix-arg for select/exapand * Improve function readability
1 parent 6dfc960 commit 3436153

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

lsp-treemacs.el

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,8 @@
11591159
(setq-local face-remapping-alist '((button . default)))
11601160
(lsp-treemacs--set-mode-line-format search-buffer title)
11611161
(lsp-treemacs-generic-refresh)
1162-
(when expand? (lsp-treemacs--expand 'LSP-Generic))
1162+
(when (equal expand? '(4))
1163+
(lsp-treemacs--expand 'LSP-Generic))
11631164
(current-buffer))))
11641165

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

1181-
(defun lsp-treemacs--do-search (method params title expand?)
1182-
(let ((search-buffer (get-buffer-create "*LSP Lookup*")))
1183-
(display-buffer-in-side-window search-buffer
1184-
'((side . bottom)))
1182+
(defun lsp-treemacs--do-search (method params title prefix-args)
1183+
(let ((search-buffer (get-buffer-create "*LSP Lookup*"))
1184+
(window (display-buffer-in-side-window (get-buffer-create "*LSP Lookup*")
1185+
'((side . bottom)))))
11851186
(lsp-request-async
11861187
method
11871188
params
@@ -1191,11 +1192,15 @@ depending on if a custom mode line is detected."
11911192
(let ((lsp-file-truename-cache (ht)))
11921193
(lsp-treemacs-render (lsp-treemacs--handle-references refs)
11931194
(format title (length refs))
1194-
expand?)))
1195+
prefix-args)))
11951196
(lsp--info "Refresh completed!"))
11961197
:mode 'detached
11971198
:cancel-token :treemacs-lookup)
11981199

1200+
(unless (zerop prefix-args)
1201+
(select-window window)
1202+
(set-window-dedicated-p window t))
1203+
11991204
(with-current-buffer search-buffer
12001205
(lsp-treemacs-initialize)
12011206
(lsp-treemacs--set-mode-line-format search-buffer " Loading... ")
@@ -1205,7 +1210,7 @@ depending on if a custom mode line is detected."
12051210
;;;###autoload
12061211
(defun lsp-treemacs-references (arg)
12071212
"Show the references for the symbol at point.
1208-
With a prefix argument, expand the tree of references automatically."
1213+
With a prefix argument, select the new window and expand the tree of references automatically."
12091214
(interactive "P")
12101215
(lsp-treemacs--do-search "textDocument/references"
12111216
`(:context (:includeDeclaration t) ,@(lsp--text-document-position-params))
@@ -1215,7 +1220,7 @@ With a prefix argument, expand the tree of references automatically."
12151220
;;;###autoload
12161221
(defun lsp-treemacs-implementations (arg)
12171222
"Show the implementations for the symbol at point.
1218-
With a prefix argument, expand the tree of implementations automatically."
1223+
With a prefix argument, select the new window expand the tree of implementations automatically."
12191224
(interactive "P")
12201225
(lsp-treemacs--do-search "textDocument/implementation"
12211226
(lsp--text-document-position-params)

0 commit comments

Comments
 (0)