Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dedicated persistent documentation buffer #766

Merged
merged 1 commit into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions acm/acm.el
Original file line number Diff line number Diff line change
Expand Up @@ -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'.
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion core/handler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion core/handler/hover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
26 changes: 26 additions & 0 deletions lsp-bridge.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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)
Expand Down