-
Notifications
You must be signed in to change notification settings - Fork 56
/
eldoc-meghanada.el
117 lines (100 loc) · 3.67 KB
/
eldoc-meghanada.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
;;; el-doc-meghanada.el --- eldoc for meganada -*- coding: utf-8; lexical-binding: t; -*-
;; Copyright (C) 2017 Yutaka Matsubara
;; License: http://www.gnu.org/licenses/gpl.html
;; 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 <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; `eldoc-meghanada' provides eldoc for `meghanada-mode'.It shows type information
;; for variable, method, class and current argument position of function.
;;; Code:
(require 'cl-lib)
(require 'eldoc)
(require 'meghanada)
(require 'thingatpt)
(defgroup eldoc-meghanada nil
"Eldoc for meghanada."
:group 'meghanada)
(defun eldoc-meghanada--call-server (buf line col sym)
(let* ((decl (meghanada--send-request-sync
"sd"
buf
line
col
(format "\"%s\"" sym)))
(type (nth 0 decl))
(name (nth 1 decl))
(signature (nth 2 decl))
(arg-index (nth 3 decl)))
(cl-case type
(method
(format "%s: %s"
(propertize name 'face 'font-lock-function-name-face)
signature))
(class
(format "%s: %s"
(propertize name 'face 'font-lock-type-face)
signature))
(field
(format "%s: %s"
(propertize name 'face 'font-lock-variable-name-face)
signature))
(var
(format "%s: %s"
(propertize name 'face 'font-lock-variable-name-face)
signature))
(other ""))))
(defun eldoc-meghanada--documentation-function ()
(when (and meghanada--client-process (process-live-p meghanada--client-process))
(let* ((buf (buffer-file-name))
(line (meghanada--what-line))
(col (meghanada--what-column))
(raw-sym (meghanada--what-symbol))
(sym (if raw-sym
(string-trim raw-sym)
raw-sym))
(meta (get-text-property (point) 'meta))
(type (get-text-property (point) 'type)))
(when (and sym (> (length sym) 0))
(eldoc-meghanada--call-server buf line col sym)))))
;; (if meta
;; (cl-case type
;; (method
;; (format "%s: %s"
;; (propertize sym 'face 'font-lock-function-name-face)
;; meta))
;; (class
;; (format "%s: %s"
;; (propertize sym 'face 'font-lock-type-face)
;; meta))
;; (field
;; (format "%s: %s"
;; (propertize sym 'face 'font-lock-variable-name-face)
;; meta))
;; (var
;; (format "%s: %s"
;; (propertize sym 'face 'font-lock-variable-name-face)
;; meta))
;; (other ""))
;; (when sym
;; (eldoc-meghanada--call-server buf line col sym)))
;;;###autoload
(defun eldoc-meghanada-setup ()
"Set up eldoc function and enable 'eldoc-mode'."
(interactive)
(setq-local eldoc-documentation-function #'eldoc-meghanada--documentation-function)
(eldoc-mode +1))
;;;###autoload
(defun meghanada-eldoc-enable ()
"Enable eldoc for meghanada-mode."
(eldoc-meghanada-setup))
(provide 'eldoc-meghanada)
;;; go-eldoc.el ends here