Skip to content

Commit 205260a

Browse files
danielmartinyyoncho
authored andcommitted
Mode line improvements (#29)
* Fix typo * Add function documentation for autoloaded lsp-treemacs commands * Improve the way the mode line in lsp-treemacs is handled In standard mode lines, the custom references title was not shown, only default " Treeemacs ". * lsp-treemacs.el (lsp-treemacs--set-mode-line-format): New function. Sets a Treemacs buffer mode-name or mode-line-format. (lsp-treemacs--show-references): Call `lsp-treemacs--set-mode-line-format`. (lsp-treemacs--do-search): Call `lsp-treemacs--set-mode-line-format`. (lsp-treemacs-references): Add a space to make the title more legible in the default mode line format. (lsp-treemacs-implementations): Add a space to make the title more legible in the default mode line format. * Remove unnecessary derived modes A couple of major modes were derived from `treemacs-mode` just to have a custom mode line, which seems unnecessary. * lsp-treemacs.el (lsp-treemacs-errors-mode): Remove major mode. (lsp-treemacs-java-deps-mode): Remove major mode. (lsp-treemacs-errors-list): Call `lsp-treemacs--set-mode-line-format`. (lsp-treemacs-java-deps-list): Call `lsp-treemacs--set-mode-line-format`. * Add spacing to make "LSP Symbols" look better in standard mode lines
1 parent 2066eaf commit 205260a

File tree

1 file changed

+57
-41
lines changed

1 file changed

+57
-41
lines changed

lsp-treemacs.el

Lines changed: 57 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150
(goto-char (point-min))
151151
(forward-line (lsp-diagnostic-line diag))
152152
(lsp-execute-code-action-by-kind "quickfix")))))
153-
(user-error "Not no a diagnostic"))))
153+
(user-error "Not on a diagnostic"))))
154154

155155
(defun lsp-treemacs-cycle-severity ()
156156
"Cycle through the severity levels shown in the errors list"
@@ -331,9 +331,6 @@
331331
:keymap lsp-treemacs-error-list-mode-map
332332
:group 'lsp-treeemacs)
333333

334-
(define-derived-mode lsp-treemacs-errors-mode treemacs-mode "LSP Errors View"
335-
"A major mode for displaying LSP Errors.")
336-
337334
;;;###autoload
338335
(defun lsp-treemacs-errors-list ()
339336
"Display error list."
@@ -348,7 +345,7 @@
348345
(select-window window)
349346
(set-window-dedicated-p window t)
350347
(treemacs-initialize)
351-
(lsp-treemacs-errors-mode)
348+
(lsp-treemacs--set-mode-line-format buffer " LSP Errors View ")
352349
(lsp-treemacs-error-list-mode 1)
353350

354351
(setq-local treemacs-default-visit-action 'treemacs-RET-action)
@@ -559,7 +556,7 @@
559556
(lsp-treemacs--symbols->tree
560557
lsp-treemacs--symbols
561558
nil)
562-
"LSP Symbols"
559+
" LSP Symbols "
563560
(and lsp-treemacs--symbols (> 30 (length lsp-treemacs--symbols)))
564561
"*LSP Symbols List*" ))
565562

@@ -780,9 +777,6 @@
780777
(lsp--info "Refresh completed")))
781778
(error)))
782779

783-
(define-derived-mode lsp-treemacs-java-deps-mode treemacs-mode "Java Dependencies"
784-
"A major mode for displaying Java Dependencies.")
785-
786780
;;;###autoload
787781
(defun lsp-treemacs-java-deps-list ()
788782
"Display error list."
@@ -796,7 +790,7 @@
796790
(select-window window)
797791
(set-window-dedicated-p window t)
798792
(treemacs-initialize)
799-
(lsp-treemacs-java-deps-mode)
793+
(lsp-treemacs--set-mode-line-format buffer " Java Dependencies ")
800794
(lsp-treemacs-deps-list-mode t)
801795

802796
(setq-local treemacs-space-between-root-nodes nil)
@@ -1139,52 +1133,72 @@
11391133
(lsp-treemacs--open-file-in-mru path)))))))
11401134

11411135
(defun lsp-treemacs--show-references (tree title expand? &optional buffer-name)
1142-
(with-current-buffer (get-buffer-create (or buffer-name "*LSP Lookup*"))
1143-
(lsp-treemacs-initialize)
1144-
(setq-local lsp-treemacs-tree tree)
1145-
(setq-local face-remapping-alist '((button . default)))
1146-
(lsp-treemacs-generic-refresh)
1147-
(when expand? (lsp-treemacs--expand 'LSP-Generic))
1148-
(setq-local mode-name title)
1149-
(current-buffer)))
1136+
(let ((search-buffer (get-buffer-create (or buffer-name "*LSP Lookup*"))))
1137+
(with-current-buffer search-buffer
1138+
(lsp-treemacs-initialize)
1139+
(lsp-treemacs--set-mode-line-format search-buffer title)
1140+
(setq-local lsp-treemacs-tree tree)
1141+
(setq-local face-remapping-alist '((button . default)))
1142+
(lsp-treemacs-generic-refresh)
1143+
(when expand? (lsp-treemacs--expand 'LSP-Generic))
1144+
(current-buffer))))
1145+
1146+
(defun lsp-treemacs--set-mode-line-format (buffer title)
1147+
"Set the mode line format of BUFFER to TITLE.
1148+
This function sets the `mode-name' or `mode-line-format'
1149+
depending on if a custom mode line is detected."
1150+
(with-current-buffer buffer
1151+
(cond ((or (fboundp 'spaceline-install)
1152+
(memq 'moody-mode-line-buffer-identification
1153+
(default-value 'mode-line-format))
1154+
(and (fboundp 'doom-modeline)
1155+
(fboundp 'doom-modeline-def-modeline)))
1156+
(setq mode-name title))
1157+
(t
1158+
(setq mode-line-format title)))))
11501159

11511160
(defun lsp-treemacs--do-search (method params title expand?)
1152-
(display-buffer-in-side-window (get-buffer-create "*LSP Lookup*")
1153-
'((side . bottom)))
1154-
(lsp-request-async
1155-
method
1156-
params
1157-
(lambda (refs)
1158-
(setq-local mode-name "Rendering results...")
1159-
(lsp-with-cached-filetrue-name
1160-
(let ((lsp-file-truename-cache (ht)))
1161-
(lsp-treemacs--show-references (lsp-treemacs--handle-references refs)
1162-
(format title (length refs))
1163-
expand?)))
1164-
(lsp--info "Refresh completed!"))
1165-
:mode 'detached
1166-
:cancel-token :treemacs-lookup)
1167-
1168-
(with-current-buffer "*LSP Lookup*"
1169-
(lsp-treemacs-initialize)
1170-
(setq-local mode-name "Loading...")
1171-
(setq-local lsp-treemacs-tree nil)
1172-
(lsp-treemacs-generic-refresh)))
1161+
(let ((search-buffer (get-buffer-create "*LSP Lookup*")))
1162+
(display-buffer-in-side-window search-buffer
1163+
'((side . bottom)))
1164+
(lsp-request-async
1165+
method
1166+
params
1167+
(lambda (refs)
1168+
(lsp-treemacs--set-mode-line-format search-buffer " Rendering results... ")
1169+
(lsp-with-cached-filetrue-name
1170+
(let ((lsp-file-truename-cache (ht)))
1171+
(lsp-treemacs--show-references (lsp-treemacs--handle-references refs)
1172+
(format title (length refs))
1173+
expand?)))
1174+
(lsp--info "Refresh completed!"))
1175+
:mode 'detached
1176+
:cancel-token :treemacs-lookup)
1177+
1178+
(with-current-buffer search-buffer
1179+
(lsp-treemacs-initialize)
1180+
(lsp-treemacs--set-mode-line-format search-buffer " Loading... ")
1181+
(setq-local lsp-treemacs-tree nil)
1182+
(lsp-treemacs-generic-refresh))))
11731183

11741184
;;;###autoload
11751185
(defun lsp-treemacs-references (arg)
1186+
"Show the references for the symbol at point.
1187+
With a prefix argument, expand the tree of references automatically."
11761188
(interactive "P")
11771189
(lsp-treemacs--do-search "textDocument/references"
11781190
`(:context (:includeDeclaration t) ,@(lsp--text-document-position-params))
1179-
"Found %s references"
1191+
" Found %s references "
11801192
arg))
11811193

11821194
;;;###autoload
11831195
(defun lsp-treemacs-implementations (arg)
1196+
"Show the implementations for the symbol at point.
1197+
With a prefix argument, expand the tree of implementations automatically."
11841198
(interactive "P")
11851199
(lsp-treemacs--do-search "textDocument/implementation"
11861200
(lsp--text-document-position-params)
1187-
"Found %s implementations"
1201+
" Found %s implementations "
11881202
arg))
11891203

11901204

@@ -1219,6 +1233,8 @@
12191233

12201234
;;;###autoload
12211235
(defun lsp-treemacs-call-hierarchy (outgoing)
1236+
"Show the incoming call hierarchy for the symbol at point.
1237+
With a prefix argument, show the outgoing call hierarchy."
12221238
(interactive "P")
12231239
(unless (lsp--find-workspaces-for "textDocument/prepareCallHierarchy")
12241240
(user-error "Call hierarchy not supported by the current servers: %s"

0 commit comments

Comments
 (0)