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

Ability to open hyperlinks with lsp-describe-thing-at-point #3041

Open
wraithm opened this issue Aug 9, 2021 · 2 comments
Open

Ability to open hyperlinks with lsp-describe-thing-at-point #3041

wraithm opened this issue Aug 9, 2021 · 2 comments
Labels

Comments

@wraithm
Copy link

wraithm commented Aug 9, 2021

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. It would be great if that worked by just simply pressing RET (or mouse-click).

See the relevant lsp-ui issue where this was fixed there: emacs-lsp/lsp-ui#452

Here's the commit where @sebastiencs fixed this issue in lsp-ui: emacs-lsp/lsp-ui@79ba8b2

EDIT: I removed the comment about respecting my preferred browser. That was my local xdg-mime settings being wrong for file uris.

@yyoncho yyoncho added the bug label Aug 9, 2021
@dunrix
Copy link

dunrix commented Jul 19, 2022

*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 .

lsp-mode/lsp-mode.el

Lines 5022 to 5024 in 5a62d4a

(with-current-buffer (get-buffer-create lsp-help-buf-name)
(with-help-window lsp-help-buf-name
(insert (string-trim-right (lsp--render-on-hover-content contents t))))))

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.

@dunrix
Copy link

dunrix commented Jul 21, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants