From 9e9b95f49c5154dacd01b7d53896c349acc39cb0 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 20 Aug 2020 14:07:47 -0400 Subject: [PATCH] Fix #3789: fix eglot lookup-documentation handler Eglot replaced `eglot-help-at-point' in joaotavora/eglot@a044dec, breaking our documentation lookup handler. --- modules/tools/lsp/+eglot.el | 4 ++-- modules/tools/lsp/autoload/eglot.el | 34 +++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/modules/tools/lsp/+eglot.el b/modules/tools/lsp/+eglot.el index 8e9ccb329..469be56c0 100644 --- a/modules/tools/lsp/+eglot.el +++ b/modules/tools/lsp/+eglot.el @@ -16,11 +16,11 @@ eglot-auto-display-help-buffer nil) :config - (set-popup-rule! "^\\*eglot-help" :size 0.35 :quit t :select t) + (set-popup-rule! "^\\*eglot-help" :size 0.15 :quit t :select t) (set-lookup-handlers! 'eglot--managed-mode :implementations #'eglot-find-implementation :type-definition #'eglot-find-typeDefinition - :documentation #'+eglot/documentation-lookup-handler) + :documentation #'+eglot-lookup-documentation) (when (featurep! :checkers syntax) (after! flycheck (load! "autoload/flycheck-eglot")))) diff --git a/modules/tools/lsp/autoload/eglot.el b/modules/tools/lsp/autoload/eglot.el index f9b647d5e..6f7fd029e 100644 --- a/modules/tools/lsp/autoload/eglot.el +++ b/modules/tools/lsp/autoload/eglot.el @@ -9,11 +9,31 @@ Example : (set-eglot-client! 'python-mode `(,(concat doom-etc-dir \"lsp/mspyls/M (after! eglot (add-to-list 'eglot-server-programs `(,mode . ,server-call)))) +;; HACK Eglot removed `eglot-help-at-point' in joaotavora/eglot@a044dec for a +;; more problematic approach of deferred to eldoc. Here, I've restored it. +;; Doom's lookup handlers try to open documentation in a separate window +;; (so they can be copied or kept open), but doing so with an eldoc buffer +;; is difficult because a) its contents are generated asynchronously, +;; making them tough to scrape, and b) their contents change frequently +;; (every time you move your cursor). +(defvar +eglot--help-buffer nil) ;;;###autoload -(defun +eglot/documentation-lookup-handler () - "Documentation lookup handler using eglot :document/hover handler. - -Mostly a rewrite of `eglot-help-at-point', which should be used interactively." - (interactive) - (eglot-help-at-point) - (display-buffer eglot--help-buffer)) +(defun +eglot-lookup-documentation (_identifier) + "Request documentation for the thing at point." + (eglot--dbind ((Hover) contents range) + (jsonrpc-request (eglot--current-server-or-lose) :textDocument/hover + (eglot--TextDocumentPositionParams)) + (let ((blurb (and (not (seq-empty-p contents)) + (eglot--hover-info contents range))) + (hint (thing-at-point 'symbol))) + (if blurb + (with-current-buffer + (or (and (buffer-live-p +eglot--help-buffer) + +eglot--help-buffer) + (setq +eglot--help-buffer (generate-new-buffer "*eglot-help*"))) + (with-help-window (current-buffer) + (rename-buffer (format "*eglot-help for %s*" hint)) + (with-current-buffer standard-output (insert blurb)) + (setq-local nobreak-char-display nil))) + (display-local-help)))) + 'deferred)