From 828a9b589d1887f2186c38cf69067f74a7b08d57 Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Sun, 5 Nov 2023 00:15:01 -0700 Subject: [PATCH] Add dedicated persistent documentation buffer --- acm/acm.el | 12 ++++++------ core/handler/__init__.py | 2 +- core/handler/hover.py | 8 +++++++- lsp-bridge.el | 26 ++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/acm/acm.el b/acm/acm.el index fcec39e8aa..b6adbb47f2 100644 --- a/acm/acm.el +++ b/acm/acm.el @@ -1128,7 +1128,7 @@ The key of candidate will change between two LSP results." ("dark" acm-frame-background-dark-color) ("light" acm-frame-background-light-color))) -(defun acm-markdown-render-content () +(defun acm-markdown-render-content (&optional enable-decorations) (when (fboundp 'gfm-view-mode) (let ((inhibit-message t)) ;; Enable `gfm-view-mode' first, otherwise `gfm-view-mode' will change attribute of face `markdown-code-face'. @@ -1145,14 +1145,14 @@ The key of candidate will change between two LSP results." (setq prettify-symbols-compose-predicate (lambda (_start _end _match) t)) (prettify-symbols-mode 1) - ;; Disable line number. - (display-line-numbers-mode -1) - ;; Syntax Highlight. (font-lock-ensure) - ;; Disable mode line. - (setq-local mode-line-format nil)) + (unless enable-decorations + ;; Disable line number. + (display-line-numbers-mode -1) + ;; Disable mode line. + (setq-local mode-line-format nil))) (defun acm-doc-markdown-render-content (doc) (when (and (acm-frame-visible-p acm-doc-frame) diff --git a/core/handler/__init__.py b/core/handler/__init__.py index 34d2fa4b28..e47f0bb080 100644 --- a/core/handler/__init__.py +++ b/core/handler/__init__.py @@ -50,7 +50,7 @@ def handle_response(self, request_id, response): from core.handler.find_implementation import FindImplementation from core.handler.find_references import FindReferences from core.handler.peek import PeekFindDefine, PeekFindReferences -from core.handler.hover import Hover +from core.handler.hover import Hover, Documentation from core.handler.signature_help import SignatureHelp from core.handler.prepare_rename import PrepareRename from core.handler.rename import Rename diff --git a/core/handler/hover.py b/core/handler/hover.py index 27697f140b..1eca1849f9 100644 --- a/core/handler/hover.py +++ b/core/handler/hover.py @@ -9,6 +9,7 @@ def make_code_block(language, string): class Hover(Handler): name = "hover" method = "textDocument/hover" + callback = "lsp-bridge-popup-documentation--show" def process_request(self, position) -> dict: return dict(position=position) @@ -47,4 +48,9 @@ def process_response(self, response: dict) -> None: contents = response["contents"] render_string = self.parse_hover_contents(contents, []) - eval_in_emacs("lsp-bridge-popup-documentation--show", render_string) + eval_in_emacs(self.callback, render_string) + +class Documentation(Hover, Handler): + name = "documentation" + method = "textDocument/hover" + callback = "lsp-bridge-documentation-at-point--show" diff --git a/lsp-bridge.el b/lsp-bridge.el index 909f75b43d..0c2da33761 100644 --- a/lsp-bridge.el +++ b/lsp-bridge.el @@ -187,6 +187,12 @@ After set `lsp-bridge-completion-obey-trigger-characters-p' to nil, you need use :safe #'stringp :group 'lsp-bridge) +(defcustom lsp-bridge-buffer-documentation-buffer "*lsp-bridge-doc*" + "Buffer for display documentation information." + :type 'string + :safe #'stringp + :group 'lsp-bridge) + (defcustom lsp-bridge-disable-backup t "Default disable backup feature, include `make-backup-files' `auto-save-default' and `create-lockfiles'." :type 'boolean @@ -1696,6 +1702,10 @@ Off by default." (acm-backend-lsp-position-to-point bound-start) (acm-backend-lsp-position-to-point bound-end)))) +(defun lsp-bridge-documentation-at-point () + (interactive) + (lsp-bridge-call-file-api "documentation" (lsp-bridge--position))) + (defun lsp-bridge-popup-documentation () (interactive) (lsp-bridge-call-file-api "hover" (lsp-bridge--position))) @@ -1783,6 +1793,22 @@ Off by default." ;; Flash define line. (lsp-bridge-flash-line)) +(defun lsp-bridge-switch-to-documentation-buffer (norecord) + (interactive) + (switch-to-buffer-other-window + (get-buffer-create lsp-bridge-buffer-documentation-buffer) norecord)) + +(defun lsp-bridge-documentation-at-point--show (value) + (let ((buffer (get-buffer-create lsp-bridge-buffer-documentation-buffer))) + (with-current-buffer buffer + (read-only-mode -1) + (erase-buffer) + (insert value) + (setq-local truncate-lines nil) + (acm-markdown-render-content t) + (read-only-mode 1)) + (display-buffer buffer 'display-buffer-reuse-window))) + (defvar lsp-bridge-popup-documentation-frame nil) (defun lsp-bridge-popup-documentation-scroll-up (&optional arg)