Skip to content

Commit

Permalink
Merge pull request #766 from Zander671/master
Browse files Browse the repository at this point in the history
Add dedicated persistent documentation buffer
  • Loading branch information
manateelazycat committed Nov 5, 2023
2 parents f7b7f62 + 828a9b5 commit 5ad5eb9
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
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 @@ -188,6 +188,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 @@ -1697,6 +1703,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 @@ -1784,6 +1794,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

0 comments on commit 5ad5eb9

Please sign in to comment.