[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/elpa 764347d 128/139: New command eglot-help-at-point a

From: João Távora
Subject: [elpa] externals/elpa 764347d 128/139: New command eglot-help-at-point and a README update
Date: Mon, 14 May 2018 09:53:49 -0400 (EDT)

branch: externals/elpa
commit 764347d24c9894b0de3a7aca2a7ea5b2d691c4e2
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>

    New command eglot-help-at-point and a README update
    * README.md (Commands and keybindings): New section.
    * eglot.el (eglot-eldoc-function): Use eglot--hover-info.
    Don't care about kind in highlightSymbol
    (eglot--hover-info): New helper.
    (eglot-help-at-point): New command.
 README.md | 25 +++++++++++++++++++++++++
 eglot.el  | 41 ++++++++++++++++++++++++++++-------------
 2 files changed, 53 insertions(+), 13 deletions(-)

diff --git a/README.md b/README.md
index 8a94466..a3789a4 100644
--- a/README.md
+++ b/README.md
@@ -33,6 +33,31 @@ Let me know how well it works and I'll add it to the list, 
or submit a
 PR.  You can also enter a `server:port` pattern to connect to an LSP
 server. To skip the guess and always be prompted use `C-u M-x eglot`.
+# Commands and keybindings
+Here's a summary of available commands:
+- `M-x eglot-reconnect` reconnects to the server
+- `M-x eglot-rename` asks the server to rename the symbol at point
+- `M-x eglot-help-at-point` asks the server for help for symbol at
+  point. Currently this is what `eldoc-mode` displays in the echo
+  area.
+- `M-x eglot-events-buffer` jumps to the events buffer for debugging
+  communication with the server.
+There are *no keybindings* specific to Eglot, but you can bind stuff
+in `eglot-mode-map`, which is active as long as Eglot is managing a
+file in your project. The commands don't need to be eglot-specific,
+(define-key eglot-mode-map (kbd "C-c h") 'eglot-help-at-point)
+(define-key eglot-mode-map (kbd "<f6>") 'xref-find-definitions)
 # Supported Protocol features
 ## General
diff --git a/eglot.el b/eglot.el
index c8612cf..13f6f61 100644
--- a/eglot.el
+++ b/eglot.el
@@ -1314,6 +1314,28 @@ DUMMY is ignored"
 (defvar eglot--highlights nil "Overlays for textDocument/documentHighlight.")
+(defun eglot--hover-info (contents &optional range)
+  (concat (and range
+               (eglot--with-lsp-range (beg end) range
+                 (concat (buffer-substring beg end)  ": ")))
+          (mapconcat #'eglot--format-markup
+                     (append
+                      (cond ((vectorp contents)
+                             contents)
+                            (contents
+                             (list contents)))) "\n")))
+(defun eglot-help-at-point ()
+  "Request \"hover\" information for the thing at point."
+  (interactive)
+  (cl-destructuring-bind (&key contents range)
+      (eglot--request (eglot--current-process-or-lose) :textDocument/hover
+                      (eglot--TextDocumentPositionParams))
+    (when (seq-empty-p contents) (eglot--error "No hover info here"))
+    (with-help-window "*eglot help*"
+      (with-current-buffer standard-output
+        (insert (eglot--hover-info contents range))))))
 (defun eglot-eldoc-function ()
   "EGLOT's `eldoc-documentation-function' function."
   (let ((buffer (current-buffer))
@@ -1325,17 +1347,7 @@ DUMMY is ignored"
        :success-fn (eglot--lambda (&key contents range)
                      (when (get-buffer-window buffer)
                        (with-current-buffer buffer
-                         (eldoc-message
-                          (concat
-                           (and range
-                                (eglot--with-lsp-range (beg end) range
-                                  (concat (buffer-substring beg end)  ": ")))
-                           (mapconcat #'eglot--format-markup
-                                      (append
-                                       (cond ((vectorp contents)
-                                              contents)
-                                             (contents
-                                              (list contents)))) "\n"))))))
+                         (eldoc-message (eglot--hover-info contents range)))))
        :deferred :textDocument/hover))
     (when (eglot--server-capable :documentHighlightProvider)
@@ -1346,12 +1358,11 @@ DUMMY is ignored"
                            (when (get-buffer-window buffer)
                              (with-current-buffer buffer
-                                (eglot--lambda (&key range kind)
+                                (eglot--lambda (&key range _kind)
                                   (eglot--with-lsp-range (beg end) range
                                     (let ((ov (make-overlay beg end)))
                                       (overlay-put ov 'face 'highlight)
                                       (overlay-put ov 'evaporate t)
-                                      (overlay-put ov :kind kind)
        :deferred :textDocument/documentHighlight)))
@@ -1482,3 +1493,7 @@ Proceed? "
 (provide 'eglot)
 ;;; eglot.el ends here
+;; Local Variables:
+;; checkdoc-force-docstrings-flag: nil
+;; End:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]