Skip to content

Commit bc8889c

Browse files
authored
Workaround new Eldoc on Emacs 27 (#3810)
* Revert "Revert "Move to new eldoc (#3275)"" This reverts commit 056865f. * Correctly declare lsp-eldoc-hook as an obsolete variable * Workaround new Eldoc on Emacs 27 Fixes #3295 * Just override eldoc strategy on older Emacs for simplicity Add remove reminder comment. * New eldoc: try to pass CI
1 parent 459b51f commit bc8889c

File tree

3 files changed

+41
-56
lines changed

3 files changed

+41
-56
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ jobs:
1414
matrix:
1515
os: [ubuntu-latest, macos-latest]
1616
emacs-version:
17-
- 26.1
18-
- 26.2
1917
- 26.3
2018
- 27.1
2119
- 27.2
@@ -72,8 +70,6 @@ jobs:
7270
fail-fast: false
7371
matrix:
7472
emacs-version:
75-
- 26.1
76-
- 26.2
7773
- 26.3
7874
- 27.1
7975
- 27.2

CHANGELOG.org

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
* Changelog
22
** Unreleased 8.0.1
3+
* Drop support for emacs 26.1 and 26.2
34
* Added support for ~textDocument/linkedEditingRange~ via
45
~lsp-iedit-linked-ranges~ and ~lsp-evil-multiedit-ranges~ (see [[https://github.com/emacs-lsp/lsp-mode/pull/3166][#3166]])
56
* Add [[https://github.com/graphql/graphiql/tree/main/packages/graphql-language-service-cli#readme][GraphQL Language Server]] for autocomplete graphql query

lsp-mode.el

Lines changed: 40 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
;; Author: Vibhav Pant, Fangrui Song, Ivan Yonchovski
66
;; Keywords: languages
7-
;; Package-Requires: ((emacs "26.1") (dash "2.18.0") (f "0.20.0") (ht "2.3") (spinner "1.7.3") (markdown-mode "2.3") (lv "0"))
7+
;; Package-Requires: ((emacs "26.3") (dash "2.18.0") (f "0.20.0") (ht "2.3") (spinner "1.7.3") (markdown-mode "2.3") (lv "0") (eldoc "1.11"))
88
;; Version: 8.0.1
99

1010
;; URL: https://github.com/emacs-lsp/lsp-mode
@@ -607,10 +607,7 @@ The hook will receive two parameters list of added and removed folders."
607607
:type 'hook
608608
:group 'lsp-mode)
609609

610-
(defcustom lsp-eldoc-hook '(lsp-hover)
611-
"Hooks to run for eldoc."
612-
:type 'hook
613-
:group 'lsp-mode)
610+
(define-obsolete-variable-alias 'lsp-eldoc-hook 'eldoc-documentation-functions "lsp-mode 8.0.1")
614611

615612
(defcustom lsp-before-apply-edits-hook nil
616613
"Hooks to run before applying edits."
@@ -1190,17 +1187,6 @@ See #2049"
11901187
"Display lsp error message with FORMAT with ARGS."
11911188
(lsp--message "%s :: %s" (propertize "LSP" 'face 'error) (apply #'format format args)))
11921189

1193-
(defun lsp--eldoc-message (&optional msg)
1194-
"Show MSG in eldoc."
1195-
(setq lsp--eldoc-saved-message msg)
1196-
(run-with-idle-timer 0 nil (lambda ()
1197-
;; XXX: new eldoc in Emacs 28
1198-
;; recommends running the hook variable
1199-
;; `eldoc-documentation-functions'
1200-
;; instead of using eldoc-message
1201-
(with-no-warnings
1202-
(eldoc-message msg)))))
1203-
12041190
(defun lsp-log (format &rest args)
12051191
"Log message to the ’*lsp-log*’ buffer.
12061192

@@ -3972,13 +3958,23 @@ yet."
39723958
(lsp-disconnect)
39733959
(lsp))
39743960

3961+
;; TODO remove those eldoc workarounds when dropping support for Emacs 27
3962+
;; https://github.com/emacs-lsp/lsp-mode/issues/3295#issuecomment-1308994099
3963+
(defvar eldoc-documentation-default) ; CI
3964+
(when (< emacs-major-version 28)
3965+
(unless (boundp 'eldoc-documentation-functions)
3966+
(load "eldoc"))
3967+
(when (memq (default-value 'eldoc-documentation-function) '(nil ignore))
3968+
;; actually `eldoc-documentation-strategy', but CI was failing
3969+
(setq-default eldoc-documentation-function 'eldoc-documentation-default)))
3970+
39753971
(define-minor-mode lsp-managed-mode
39763972
"Mode for source buffers managed by lsp-mode."
39773973
:lighter nil
39783974
(cond
39793975
(lsp-managed-mode
39803976
(when (lsp-feature? "textDocument/hover")
3981-
(add-function :before-until (local 'eldoc-documentation-function) #'lsp-eldoc-function)
3977+
(add-hook 'eldoc-documentation-functions #'lsp-eldoc-function nil t)
39823978
(eldoc-mode 1))
39833979

39843980
(add-hook 'after-change-functions #'lsp-on-change nil t)
@@ -4013,8 +4009,8 @@ yet."
40134009
(lsp--on-idle buffer)))))))
40144010
(t
40154011
(lsp-unconfig-buffer)
4016-
(remove-function (local 'eldoc-documentation-function) #'lsp-eldoc-function)
40174012

4013+
(remove-hook 'eldoc-documentation-functions #'lsp-eldoc-function t)
40184014
(remove-hook 'post-command-hook #'lsp--post-command t)
40194015
(remove-hook 'after-change-functions #'lsp-on-change t)
40204016
(remove-hook 'after-revert-hook #'lsp-on-revert t)
@@ -5078,10 +5074,32 @@ If EXCLUDE-DECLARATION is non-nil, request the server to include declarations."
50785074
(->> lsp--cur-workspace lsp--workspace-client lsp--client-response-handlers (remhash id))
50795075
(lsp-notify "$/cancelRequest" `(:id ,id))))
50805076

5081-
(defun lsp-eldoc-function ()
5082-
"`lsp-mode' eldoc function."
5083-
(run-hooks 'lsp-eldoc-hook)
5084-
eldoc-last-message)
5077+
(defvar-local lsp--hover-saved-bounds nil)
5078+
5079+
(defun lsp-eldoc-function (cb &rest _ignored)
5080+
"`lsp-mode' eldoc function to display hover info (based on `textDocument/hover')."
5081+
(if (and lsp--hover-saved-bounds
5082+
(lsp--point-in-bounds-p lsp--hover-saved-bounds))
5083+
lsp--eldoc-saved-message
5084+
(setq lsp--hover-saved-bounds nil
5085+
lsp--eldoc-saved-message nil)
5086+
(if (looking-at "[[:space:]\n]")
5087+
(setq lsp--eldoc-saved-message nil) ; And returns nil.
5088+
(when (and lsp-eldoc-enable-hover (lsp--capability :hoverProvider))
5089+
(lsp-request-async
5090+
"textDocument/hover"
5091+
(lsp--text-document-position-params)
5092+
(-lambda ((hover &as &Hover? :range? :contents))
5093+
(setq lsp--hover-saved-bounds (when range?
5094+
(lsp--range-to-region range?)))
5095+
(funcall cb (setq lsp--eldoc-saved-message
5096+
(when contents
5097+
(lsp--render-on-hover-content
5098+
contents
5099+
lsp-eldoc-render-all)))))
5100+
:error-handler #'ignore
5101+
:mode 'tick
5102+
:cancel-token :eldoc-hover)))))
50855103

50865104
(defun lsp--point-on-highlight? ()
50875105
(-some? (lambda (overlay)
@@ -5675,36 +5693,6 @@ It will show up only if current point has signature help."
56755693
:mode 'unchanged
56765694
:cancel-token :document-color-token)))
56775695

5678-
5679-
;; hover
5680-
5681-
(defvar-local lsp--hover-saved-bounds nil)
5682-
5683-
(defun lsp-hover ()
5684-
"Display hover info (based on `textDocument/signatureHelp')."
5685-
(if (and lsp--hover-saved-bounds
5686-
(lsp--point-in-bounds-p lsp--hover-saved-bounds))
5687-
(lsp--eldoc-message lsp--eldoc-saved-message)
5688-
(setq lsp--hover-saved-bounds nil
5689-
lsp--eldoc-saved-message nil)
5690-
(if (looking-at "[[:space:]\n]")
5691-
(lsp--eldoc-message nil)
5692-
(when (and lsp-eldoc-enable-hover (lsp-feature? "textDocument/hover"))
5693-
(lsp-request-async
5694-
"textDocument/hover"
5695-
(lsp--text-document-position-params)
5696-
(-lambda ((hover &as &Hover? :range? :contents))
5697-
(when hover
5698-
(when range?
5699-
(setq lsp--hover-saved-bounds (lsp--range-to-region range?)))
5700-
(lsp--eldoc-message (and contents
5701-
(lsp--render-on-hover-content
5702-
contents
5703-
lsp-eldoc-render-all)))))
5704-
:error-handler #'ignore
5705-
:mode 'tick
5706-
:cancel-token :eldoc-hover)))))
5707-
57085696

57095697

57105698
(defun lsp--action-trigger-parameter-hints (_command)

0 commit comments

Comments
 (0)