Personal emacs config
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
3.7 KiB

  1. ;;; el-doc-meghanada.el --- eldoc for meganada -*- coding: utf-8; lexical-binding: t; -*-
  2. ;; Copyright (C) 2017 Yutaka Matsubara
  3. ;; License: http://www.gnu.org/licenses/gpl.html
  4. ;; This program is free software; you can redistribute it and/or modify
  5. ;; it under the terms of the GNU General Public License as published by
  6. ;; the Free Software Foundation, either version 3 of the License, or
  7. ;; (at your option) any later version.
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;; You should have received a copy of the GNU General Public License
  13. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. ;;; Commentary:
  15. ;;
  16. ;; `eldoc-meghanada' provides eldoc for `meghanada-mode'.It shows type information
  17. ;; for variable, method, class and current argument position of function.
  18. ;;; Code:
  19. (require 'cl-lib)
  20. (require 'eldoc)
  21. (require 'meghanada)
  22. (require 'thingatpt)
  23. (defgroup eldoc-meghanada nil
  24. "Eldoc for meghanada."
  25. :group 'meghanada)
  26. (defun eldoc-meghanada--call-server (buf line col sym)
  27. (let* ((decl (meghanada--send-request-sync
  28. "sd"
  29. buf
  30. line
  31. col
  32. (format "\"%s\"" sym)))
  33. (type (nth 0 decl))
  34. (name (nth 1 decl))
  35. (signature (nth 2 decl))
  36. (arg-index (nth 3 decl)))
  37. (cl-case type
  38. (method
  39. (format "%s: %s"
  40. (propertize name 'face 'font-lock-function-name-face)
  41. signature))
  42. (class
  43. (format "%s: %s"
  44. (propertize name 'face 'font-lock-type-face)
  45. signature))
  46. (field
  47. (format "%s: %s"
  48. (propertize name 'face 'font-lock-variable-name-face)
  49. signature))
  50. (var
  51. (format "%s: %s"
  52. (propertize name 'face 'font-lock-variable-name-face)
  53. signature))
  54. (other ""))))
  55. (defun eldoc-meghanada--documentation-function ()
  56. (when (and meghanada--client-process (process-live-p meghanada--client-process))
  57. (let* ((buf (buffer-file-name))
  58. (line (meghanada--what-line))
  59. (col (meghanada--what-column))
  60. (raw-sym (meghanada--what-symbol))
  61. (sym (if raw-sym
  62. (string-trim raw-sym)
  63. raw-sym))
  64. (meta (get-text-property (point) 'meta))
  65. (type (get-text-property (point) 'type)))
  66. (when (and sym (> (length sym) 0))
  67. (eldoc-meghanada--call-server buf line col sym)))))
  68. ;; (if meta
  69. ;; (cl-case type
  70. ;; (method
  71. ;; (format "%s: %s"
  72. ;; (propertize sym 'face 'font-lock-function-name-face)
  73. ;; meta))
  74. ;; (class
  75. ;; (format "%s: %s"
  76. ;; (propertize sym 'face 'font-lock-type-face)
  77. ;; meta))
  78. ;; (field
  79. ;; (format "%s: %s"
  80. ;; (propertize sym 'face 'font-lock-variable-name-face)
  81. ;; meta))
  82. ;; (var
  83. ;; (format "%s: %s"
  84. ;; (propertize sym 'face 'font-lock-variable-name-face)
  85. ;; meta))
  86. ;; (other ""))
  87. ;; (when sym
  88. ;; (eldoc-meghanada--call-server buf line col sym)))
  89. ;;;###autoload
  90. (defun eldoc-meghanada-setup ()
  91. "Set up eldoc function and enable 'eldoc-mode'."
  92. (interactive)
  93. (setq-local eldoc-documentation-function #'eldoc-meghanada--documentation-function)
  94. (eldoc-mode +1))
  95. ;;;###autoload
  96. (defun meghanada-eldoc-enable ()
  97. "Enable eldoc for meghanada-mode."
  98. (eldoc-meghanada-setup))
  99. (provide 'eldoc-meghanada)
  100. ;;; go-eldoc.el ends here