-
Notifications
You must be signed in to change notification settings - Fork 2
/
ellsp-hover.el
75 lines (64 loc) · 2.64 KB
/
ellsp-hover.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
;;; ellsp-hover.el --- Hover Handler -*- lexical-binding: t; -*-
;; Copyright (C) 2023-2025 Shen, Jen-Chieh
;; This file is not part of GNU Emacs.
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; Hover Handler.
;;
;;; Code:
(defun ellsp--describe-string ()
"Return the describe symbol string."
(let ((thing (symbol-at-point)))
(with-current-buffer (help-buffer)
(let (buffer-read-only) (erase-buffer))
(msgu-silent (describe-symbol thing))
(buffer-string))))
(defun ellsp--describe-at-point ()
"Describe symbol at point."
(when-let (((derived-mode-p 'lisp-data-mode))
(desc (ellsp--describe-string)))
(if (or (string-empty-p desc)
(string= (string-trim desc) "[back]"))
nil
desc)))
(defun ellsp--handle-textDocument/hover (id params)
"Handle method `textDocument/hover'."
(-let* (((&HoverParams :text-document (&TextDocumentIdentifier :uri)
:position (&Position :line :character))
params)
(file (lsp--uri-to-path uri))
(buffer (ellsp-get-buffer ellsp-workspace file)))
(when buffer
(with-current-buffer buffer
(goto-char (point-min))
(forward-line line)
(forward-char character)
(when-let ((desc (ellsp--describe-at-point))
(line (line-number-at-pos nil t))
(column-beg (save-excursion (forward-symbol -1) (current-column)))
(column-end (save-excursion (forward-symbol 1) (current-column))))
(lsp--make-response
id
(lsp-make-hover
:contents (lsp-make-markup-content
:kind "plaintext"
:value desc)
:range (lsp-make-range
:start (lsp-make-position
:line line
:character column-beg)
:end (lsp-make-position
:line line
:character column-end)))))))))
(provide 'ellsp-hover)
;;; ellsp-hover.el ends here