Add documentation command for LSP
The default way lsp (at least for Java) is displayed is annoying. I’m used to calling documentation with a keybinding like in Emacs Lisp. This command makes it more like that.
This commit is contained in:
parent
220ad644dd
commit
d4e4a25cde
2 changed files with 26 additions and 8 deletions
13
oni-java.el
13
oni-java.el
|
@ -4,8 +4,8 @@
|
||||||
|
|
||||||
;; Author: Tom Willemse <tom@ryuslash.org>
|
;; Author: Tom Willemse <tom@ryuslash.org>
|
||||||
;; Keywords: local
|
;; Keywords: local
|
||||||
;; Version: 2019.1016.231834
|
;; Version: 2019.1021.002901
|
||||||
;; Package-Requires: (oni-fci oni-data-dir lsp-java company-lsp lsp-ui hydra)
|
;; Package-Requires: (oni-fci oni-data-dir oni-lsp lsp-java company-lsp hydra)
|
||||||
|
|
||||||
;; This program is free software; you can redistribute it and/or modify
|
;; 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
|
;; it under the terms of the GNU General Public License as published by
|
||||||
|
@ -30,6 +30,7 @@
|
||||||
(require 'hydra)
|
(require 'hydra)
|
||||||
(require 'lsp-java)
|
(require 'lsp-java)
|
||||||
(require 'oni-data-dir)
|
(require 'oni-data-dir)
|
||||||
|
(require 'oni-lsp)
|
||||||
|
|
||||||
(defun oni-java-enable-buffer-formatting ()
|
(defun oni-java-enable-buffer-formatting ()
|
||||||
"Format the buffer before save."
|
"Format the buffer before save."
|
||||||
|
@ -50,6 +51,9 @@
|
||||||
("p" lsp-java-create-parameter "Create parameter")
|
("p" lsp-java-create-parameter "Create parameter")
|
||||||
("l" lsp-java-create-local "Create local"))
|
("l" lsp-java-create-local "Create local"))
|
||||||
|
|
||||||
|
(defhydra java-documentation-hydra (:color blue)
|
||||||
|
("d" oni-lsp-show-doc "Show documentation"))
|
||||||
|
|
||||||
(setq lsp-java-server-install-dir
|
(setq lsp-java-server-install-dir
|
||||||
(oni-data-dir-locate "lsp-java/server/"))
|
(oni-data-dir-locate "lsp-java/server/"))
|
||||||
|
|
||||||
|
@ -74,14 +78,15 @@
|
||||||
(add-to-list 'company-backends 'company-lsp)
|
(add-to-list 'company-backends 'company-lsp)
|
||||||
|
|
||||||
(define-key java-mode-map (kbd "C-c r") 'java-refactor-hydra/body)
|
(define-key java-mode-map (kbd "C-c r") 'java-refactor-hydra/body)
|
||||||
|
(define-key java-mode-map (kbd "C-c d") 'java-documentation-hydra/body)
|
||||||
|
|
||||||
(add-to-list 'auto-insert-alist
|
(add-to-list 'auto-insert-alist
|
||||||
'("\\.java\\'"
|
'("\\.java\\'"
|
||||||
() "public class "
|
() "public class "
|
||||||
(file-name-sans-extension
|
(file-name-sans-extension
|
||||||
(file-name-nondirectory (buffer-file-name))) " {\n"
|
(file-name-nondirectory (buffer-file-name))) " {\n"
|
||||||
(indent-for-tab-command) _ "\n"
|
(indent-for-tab-command) _ "\n"
|
||||||
"}"))
|
"}"))
|
||||||
|
|
||||||
;;;###autoload(with-eval-after-load 'cc-mode (require 'oni-java))
|
;;;###autoload(with-eval-after-load 'cc-mode (require 'oni-java))
|
||||||
|
|
||||||
|
|
21
oni-lsp.el
21
oni-lsp.el
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
;; Author: Tom Willemse <tom@ryuslash.org>
|
;; Author: Tom Willemse <tom@ryuslash.org>
|
||||||
;; Keywords: local
|
;; Keywords: local
|
||||||
;; Version: 2019.1016.231222
|
;; Version: 2019.1021.004102
|
||||||
;; Package-Requires: (lsp-mode lsp-ui)
|
;; Package-Requires: (lsp-mode lsp-ui)
|
||||||
|
|
||||||
;; This program is free software; you can redistribute it and/or modify
|
;; This program is free software; you can redistribute it and/or modify
|
||||||
|
@ -29,12 +29,25 @@
|
||||||
(require 'lsp)
|
(require 'lsp)
|
||||||
(require 'lsp-ui)
|
(require 'lsp-ui)
|
||||||
|
|
||||||
|
(defun oni-lsp-show-doc ()
|
||||||
|
"Show documentation string in a help buffer."
|
||||||
|
(interactive)
|
||||||
|
(let* ((position-params (lsp--text-document-position-params))
|
||||||
|
(response (lsp-request "textDocument/hover" position-params))
|
||||||
|
(contents (gethash "contents" response))
|
||||||
|
(help-string (lsp-ui-doc--extract contents))
|
||||||
|
(symbol (gethash "value" (pcase contents
|
||||||
|
((pred arrayp) (aref contents 0))
|
||||||
|
(_ contents)))))
|
||||||
|
(with-help-window (help-buffer)
|
||||||
|
(princ symbol)
|
||||||
|
(princ "\n\n")
|
||||||
|
(princ help-string))))
|
||||||
|
|
||||||
(setq lsp-prefer-flymake nil)
|
(setq lsp-prefer-flymake nil)
|
||||||
|
|
||||||
(setq lsp-ui-doc-enable t)
|
(setq lsp-ui-doc-enable nil)
|
||||||
(setq lsp-ui-sideline-enable nil)
|
(setq lsp-ui-sideline-enable nil)
|
||||||
(setq lsp-ui-doc-position 'at-point)
|
|
||||||
(setq lsp-ui-doc-delay 1)
|
|
||||||
|
|
||||||
(add-hook 'lsp-mode-hook 'lsp-lens-mode)
|
(add-hook 'lsp-mode-hook 'lsp-lens-mode)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue