[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/eglot2emacs 2dad9298d9 061/120: Rework eglot's mode-line
From: |
João Távora |
Subject: |
feature/eglot2emacs 2dad9298d9 061/120: Rework eglot's mode-line |
Date: |
Thu, 20 Oct 2022 07:16:53 -0400 (EDT) |
branch: feature/eglot2emacs
commit 2dad9298d9ba96510fb5f744959284ca46b71968
Author: Felicián Németh <felician.nemeth@gmail.com>
Commit: João Távora <joaotavora@gmail.com>
Rework eglot's mode-line
Mimic flymake by replacing the old menus of the mode-line with
"context menus". List all usefull commands under the main menu
(eglot-menu-map), and commands related to LSP debugging under the
project menu (eglot-debug-map).
* eglot.el (eglot-read-documentation, eglot-customize): New
commands.
(eglot-mode-line-string): New defcustom.
(eglot-menu-map, eglot-debug-map,): New variables.
(eglot--mode-line-props): Rework to use eglot-menu-map and
eglot-debug-map.
(eglot--mode-line-format): Use eglot-mode-line-string.
GitHub-reference: close https://github.com/joaotavora/eglot/issues/792
---
lisp/progmodes/eglot.el | 129 +++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 118 insertions(+), 11 deletions(-)
diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index f739a0d34d..c8de62c154 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -322,6 +322,10 @@ let the buffer grow forever."
"If non-nil, activate Eglot in cross-referenced non-project files."
:type 'boolean)
+(defcustom eglot-mode-line-string "eglot"
+ "String displayed on the mode line when Eglot is active."
+ :type 'string)
+
(defvar eglot-withhold-process-id nil
"If non-nil, Eglot will not send the Emacs process id to the language server.
This can be useful when using docker to run a language server.")
@@ -1741,6 +1745,99 @@ If it is activated, also signal textDocument/didOpen."
(call-interactively what)
(force-mode-line-update t))))))
+(defun eglot-read-documentation ()
+ "Open the on-line documentation."
+ (interactive)
+ (browse-url "https://github.com/joaotavora/eglot#readme"))
+
+(defun eglot-customize ()
+ "Customize Eglot."
+ (interactive)
+ (customize-group "eglot"))
+
+(easy-menu-define eglot-menu-map nil "Eglot"
+ (let ((action-help
+ "Get possible code actions for the active region or the point"))
+ `("Eglot"
+ ;; Commands for getting information and customization.
+ ["Read the documentation" eglot-read-documentation
+ :help "Read the on-line documentation"]
+ ["Customize Eglot" eglot-customize
+ :help "Customize Eglot globally"]
+ "--"
+ ;; xref like commands.
+ ["Find definitions" xref-find-definitions
+ :help "Find definitions of the identifier at point"
+ :active (eglot--server-capable :definitionProvider)]
+ ["Find references" xref-find-references
+ :help "Find references to the identifier at point"
+ :active (eglot--server-capable :referencesProvider)]
+ ["Find symbols in workspace (apropos)" xref-find-apropos
+ :help "Find symbols matching a query"
+ :active (eglot--server-capable :workspaceSymbolProvider)]
+ ["Find declaration" eglot-find-declaration
+ :help "Find declaration for the identifier at point"
+ :active (eglot--server-capable :declarationProvider)]
+ ["Find implementation" eglot-find-implementation
+ :help "Find implementation for the identifier at point"
+ :active (eglot--server-capable :implementationProvider)]
+ ["Find type definition" eglot-find-typeDefinition
+ :help "Find type definition for the identifier at point"
+ :active (eglot--server-capable :typeDefinitionProvider)]
+ "--"
+ ;; LSP-related commands (mostly Eglot's own commands).
+ ["Rename symbol" eglot-rename
+ :help "Rename current symbol"
+ :active (eglot--server-capable :renameProvider)]
+ ["Format buffer" eglot-format-buffer
+ :help "Format contents of the buffer"
+ :active (eglot--server-capable :documentFormattingProvider)]
+ ["Format region" eglot-format
+ :help "Format the active region"
+ :active (and (region-active-p)
+ (eglot--server-capable :documentRangeFormattingProvider))]
+ ["Show all diagnostics" flymake-show-buffer-diagnostics
+ :help "Show diagnostics for current buffer (flymake)"]
+ ["Show documentation for point" eldoc-doc-buffer
+ :help "Show documentation for point in a buffer (eldoc)"]
+ "--"
+ ;; Code-action commands.
+ ["All possible code actions" eglot-code-actions
+ :help ,action-help
+ :active (eglot--server-capable :codeActionProvider)]
+ ["Organize imports" eglot-code-action-organize-imports
+ :help ,action-help
+ :visible (eglot--server-capable :codeActionProvider)]
+ ["Extract" eglot-code-action-extract
+ :help ,action-help
+ :visible (eglot--server-capable :codeActionProvider)]
+ ["Inline" eglot-code-action-inline
+ :help ,action-help
+ :visible (eglot--server-capable :codeActionProvider)]
+ ["Rewrite" eglot-code-action-rewrite
+ :help ,action-help
+ :visible (eglot--server-capable :codeActionProvider)]
+ ["Quickfix" eglot-code-action-quickfix
+ :help ,action-help
+ :visible (eglot--server-capable :codeActionProvider)])))
+
+(easy-menu-define eglot-debug-map nil "Debugging the server communication"
+ '("Debugging the server communication"
+ ["Go to events buffer" eglot-events-buffer
+ :help "Display the log buffer of the server communication"]
+ ["Go to the stderr buffer" eglot-stderr-buffer
+ :help "Display the error buffer for current LSP server"]
+ ["Reconnect to server" eglot-reconnect
+ :help "Reconnect to the current LSP server"]
+ ["Quit server" eglot-shutdown
+ :help "Politely ask the LSP server to quit"]
+ "--"
+ ["Customize events buffers"
+ (lambda ()
+ (interactive)
+ (customize-variable 'eglot-events-buffer-size))
+ :help "Customize variable eglot-events-buffer-size"]))
+
(defun eglot--mode-line-props (thing face defs &optional prepend)
"Helper for function `eglot--mode-line-format'.
Uses THING, FACE, DEFS and PREPEND."
@@ -1764,18 +1861,28 @@ Uses THING, FACE, DEFS and PREPEND."
(`(,_id ,doing ,done-p ,_detail) (and server (eglot--spinner
server)))
(last-error (and server (jsonrpc-last-error server))))
(append
- `(,(eglot--mode-line-props "eglot" 'eglot-mode-line nil))
+ `(,(propertize
+ eglot-mode-line-string
+ 'face 'eglot-mode-line
+ 'mouse-face 'mode-line-highlight
+ 'help-echo "Eglot: an LSP client\nmouse-1: Display minor mode menu"
+ 'keymap (let ((map (make-sparse-keymap)))
+ (define-key map [mode-line down-mouse-1] eglot-menu-map)
+ map)))
(when nick
- `(":" ,(eglot--mode-line-props
- nick 'eglot-mode-line
- '((C-mouse-1 eglot-stderr-buffer "go to stderr buffer")
- (mouse-1 eglot-events-buffer "go to events buffer")
- (mouse-2 eglot-shutdown "quit server")
- (mouse-3 eglot-reconnect "reconnect to server")))
- ,@(when last-error
+ `(":"
+ ,(propertize
+ nick
+ 'face 'eglot-mode-line
+ 'mouse-face 'mode-line-highlight
+ 'help-echo (format "Project '%s'\nmouse-1: LSP debugging menu" nick)
+ 'keymap (let ((map (make-sparse-keymap)))
+ (define-key map [mode-line down-mouse-1] eglot-debug-map)
+ map))
+ ,@(when last-error
`("/" ,(eglot--mode-line-props
"error" 'compilation-mode-line-fail
- '((mouse-3 eglot-clear-status "clear this status"))
+ '((mouse-3 eglot-clear-status "Clear this status"))
(format "An error occurred: %s\n" (plist-get last-error
:message)))))
,@(when (and doing (not done-p))
@@ -1785,9 +1892,9 @@ Uses THING, FACE, DEFS and PREPEND."
`("/" ,(eglot--mode-line-props
(format "%d" pending) 'warning
'((mouse-3 eglot-forget-pending-continuations
- "forget pending continuations"))
+ "Forget pending continuations"))
"Number of outgoing, \
-still unanswered LSP requests to the server"))))))))
+still unanswered LSP requests to the server\n"))))))))
(add-to-list 'mode-line-misc-info
`(eglot--managed-mode (" [" eglot--mode-line-format "] ")))
- feature/eglot2emacs dd017359e9 097/120: Add support for jedi-language-server (again), (continued)
- feature/eglot2emacs dd017359e9 097/120: Add support for jedi-language-server (again), João Távora, 2022/10/20
- feature/eglot2emacs add2926de8 114/120: Make eglot-code-actions usable non-interactively, João Távora, 2022/10/20
- feature/eglot2emacs eb9d6281b5 117/120: Do use eglot-connect-timeout if eglot-sync-connect is t, João Távora, 2022/10/20
- feature/eglot2emacs 0186faf2a1 120/120: ; Merge from https://github.com/joaotavora/eglot, João Távora, 2022/10/20
- feature/eglot2emacs f199060ee0 027/120: ; * eglot.el (eglot-server-initialized-hook): fix punctuation., João Távora, 2022/10/20
- feature/eglot2emacs 8b0ea132cb 035/120: * eglot.el (eglot--server-capable): don't use obsolete name., João Távora, 2022/10/20
- feature/eglot2emacs 469835a4f2 034/120: Obsolete eglot--plist-keys in favor of map-keys, João Távora, 2022/10/20
- feature/eglot2emacs 6dba74d8cb 051/120: Defend against broken move-to-column in recent emacs, João Távora, 2022/10/20
- feature/eglot2emacs 05418a1d83 054/120: Add omnisharp support for c#, João Távora, 2022/10/20
- feature/eglot2emacs c17c3cfcbf 064/120: Check textdocumentsync/willsave cap before sending it, João Távora, 2022/10/20
- feature/eglot2emacs 2dad9298d9 061/120: Rework eglot's mode-line,
João Távora <=
- feature/eglot2emacs f9cfefcf89 063/120: Guess language-id if manually entering server program, João Távora, 2022/10/20
- feature/eglot2emacs 339ebe7ce4 065/120: Update invocation for out-of-box dart ls support, João Távora, 2022/10/20
- feature/eglot2emacs 46a480aa88 072/120: Fix egregious thinko in eglot--uri-to-path, João Távora, 2022/10/20
- feature/eglot2emacs f8c8c70f8a 077/120: Reduce eldoc noise from hover messages, João Távora, 2022/10/20
- feature/eglot2emacs 9ffcd537f8 078/120: Apply any additionaltextedits unconditionally, João Távora, 2022/10/20
- feature/eglot2emacs b931d93b15 085/120: Guess the "lsp identifier at point", João Távora, 2022/10/20
- feature/eglot2emacs e5b021c01f 095/120: Fix jdtls support, João Távora, 2022/10/20
- feature/eglot2emacs a598352750 104/120: Allow eglot-workspace-configuration to be a plist, João Távora, 2022/10/20
- feature/eglot2emacs b633c29648 112/120: Rename "eglot -> eglot" in docstrings, João Távora, 2022/10/20
- feature/eglot2emacs 5b902b5cbb 110/120: Add support for "single server, multiple modes", João Távora, 2022/10/20