lsp-mode
lsp-mode copied to clipboard
Ability to open hyperlinks with lsp-describe-thing-at-point
When looking at a documentation buffer after calling M-x lsp-describe-thing-at-point
, it would be nice to be able to open hyperlinks in those docs. It seems like M-x lsp-ui-doc--open-markdown-link
sort of works. However, I found that it doesn't respect my preferred browser settings. It would be great if that worked by just simply pressing RET
.
See the relevant lsp-ui
issue where this was fixed there: https://github.com/emacs-lsp/lsp-ui/issues/452
Here's the commit where @sebastiencs fixed this issue in lsp-ui
: https://github.com/emacs-lsp/lsp-ui/commit/79ba8b2a901d079f5f65f87735329af400dfe692
*bump*
Just chiming in about this annoying issue, reported almost a year ago.
Following code from lsp-mode
creates lsp-help buffer and renders its contents using markdown functions, including (mouse)binding to markdown-follow-thing-at-point
for hyperlinks, which it cant't handle and fails with user-error: Nothing to follow at point
.
https://github.com/emacs-lsp/lsp-mode/blob/5a62d4aa1b05fd14e338c47dad976b0b53c4bbc0/lsp-mode.el#L5022-L5024
For example external link rendered for regexp.MustCompile on pkg.go.dev is assembled this way:
regexp.MustCompile on pkg.go.dev
" 0 4 (markdown-gfm-code (7 58) face (font-lock-keyword-face markdown-code-face) font-lock-fontified t fontified t font-lock-multiline t) 4 5 (markdown-gfm-code (7 58) font-lock-fontified t fontified t font-lock-multiline t face (markdown-code-face)) 5 11 (markdown-gfm-code (7 58) face (font-lock-function-name-face markdown-code-face) font-lock-fontified t fontified t font-lock-multiline t) 11 12 (markdown-gfm-code (7 58) font-lock-fontified t fontified t font-lock-multiline t face (markdown-code-face)) 12 23 (markdown-gfm-code (7 58) face (font-lock-function-name-face markdown-code-face) font-lock-fontified t fontified t font-lock-multiline t) 23 28 (markdown-gfm-code (7 58) font-lock-fontified t fontified t font-lock-multiline t face (markdown-code-face)) 28 34 (markdown-gfm-code (7 58) face (font-lock-type-face markdown-code-face) font-lock-fontified t fontified t font-lock-multiline t) 34 37 (markdown-gfm-code (7 58) font-lock-fontified t fontified t font-lock-multiline t face (markdown-code-face)) 37 50 (markdown-gfm-code (7 58) face (font-lock-type-face markdown-code-face) font-lock-fontified t fontified t font-lock-multiline t) 50 51 (markdown-gfm-code (7 58) font-lock-fontified t fontified t font-lock-multiline t face (markdown-code-face)) 128 146 (face (markdown-link-face markdown-inline-code-face) keymap (keymap (mouse-2 . markdown-follow-thing-at-point) (follow-link . mouse-face)) mouse-face markdown-highlight-face font-lock-multiline t help-echo "https://pkg.go.dev/regexp?utm_source=gopls#MustCompile") 146 160 (keymap (keymap (mouse-2 . markdown-follow-thing-at-point) (follow-link . mouse-face)) mouse-face markdown-highlight-face font-lock-multiline t help-echo "https://pkg.go.dev/regexp?utm_source=gopls#MustCompile" face markdown-link-face))
As already mentioned about related issue from lsp-ui
module, lsp-ui-doc--open-markdown-link
processes such urls correctly.
For anybody interested, share here simple work around this problem.
Somewhere during emacs initialization, register hook which matches specific help buffer created by lsp-mode
and remap mouse button and set Return/Enter key binding:
(add-hook 'help-mode-hook
(lambda ()
(when (string= (buffer-name (current-buffer)) "*lsp-help*")
(local-set-key [?\r] 'lsp-ui-doc--open-markdown-link)
(define-key help-mode-map
[remap markdown-follow-thing-at-point] 'lsp-ui-doc--open-markdown-link))))
This is not a solution but a quick fix, albeit does the job in my case.
lsp-ui
package is expected to be present.