diff options
author | Felicián Németh <felician.nemeth@gmail.com> | 2023-05-06 22:00:25 +0200 |
---|---|---|
committer | Felicián Németh <felician.nemeth@gmail.com> | 2023-05-06 22:06:14 +0200 |
commit | 1b3ba385ae3cb7da9e06cd76b3a800bc71ea3b69 (patch) | |
tree | caa95f932527fdc9df3ab9f925b7684f6d1abd71 | |
parent | a09ab28cf01d7cbb223ad83fbbb694c5158c96b8 (diff) |
Add client capability: localDocs
When the client has this capability, the server can send local
links in response to an open-external-documentation request.
* README.md (rust-analyzer): Mention the new feature.
* eglot-x.el (eglot-x-enable-local-docs-support): New defcustom.
(eglot-client-capabilities, eglot-x-open-external-documentation):
Use it.
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | eglot-x.el | 23 |
2 files changed, 24 insertions, 3 deletions
@@ -66,6 +66,7 @@ positions. However, emacs' own `backward-sexp`, and `forward-sexp` seem to be more useful. - [Open External Documentation]: see defun `eglot-x-open-external-documentation`. +- [Local Documentation]: see variable `eglot-x-enable-local-docs-support`. - [Structural Search Replace (SSR)][ssr]: see defun `eglot-x-structural-search-replace`. The server checks the correctness of the query while you type: @@ -169,14 +170,15 @@ See the documentation of `eglot-x-enable-ff-related-file-integration`. [Analyzer Status]: https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/lsp-extensions.md#analyzer-status [Colored diagnostics]: https://github.com/rust-lang/rust-analyzer/blob/master/docs/dev/lsp-extensions.md#colored-diagnostic-output [Expand Macro]: https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/lsp-extensions.md#expand-macro +[Flycheck commands]: https://github.com/rust-lang/rust-analyzer/blob/master/docs/dev/lsp-extensions.md#controlling-flycheck [Join Lines]: https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/lsp-extensions.md#join-lines +[Local Documentation]: https://github.com/rust-lang/rust-analyzer/blob/master/docs/dev/lsp-extensions.md#local-documentation [Matching Brace]: https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/lsp-extensions.md#matching-brace [Move Item]: https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/lsp-extensions.md#move-item [On Enter]: https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/lsp-extensions.md#on-enter [Open External Documentation]: https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/lsp-extensions.md#open-external-documentation [Related Tests]: https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/lsp-extensions.md#related-tests [Reload Workspace]: https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/lsp-extensions.md#reload-workspace -[Flycheck commands]: https://github.com/rust-lang/rust-analyzer/blob/master/docs/dev/lsp-extensions.md#controlling-flycheck [Runnables]: https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/lsp-extensions.md#runnables [Server Status]: https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/lsp-extensions.md#server-status [Snippet TextEdits]: https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/lsp-extensions.md#snippet-textedit @@ -190,6 +190,15 @@ manages .toml files, or (ii) the rust-analyzer LSP server manages :type 'boolean :link '(function-link ff-find-related-file) :link '(variable-link ff-related-file-alist)) + +(defcustom eglot-x-enable-local-docs-support t + "If non-nil, `eglot-x-open-external-documentation' can receive local links." + :type 'boolean + :link '(function-link eglot-x-open-external-documentation) + :link '(url-link + :tag "the definition of the extension (rust-analyzer)" + "https://github.com/rust-lang/rust-analyzer/blob/master/\ +docs/dev/lsp-extensions.md#local-documentation")) ;;; Enable the extensions ;; @@ -331,6 +340,11 @@ connections." (when eglot-x-enable-ff-related-file-integration (add-hook 'eglot-managed-mode-hook #'eglot-x--configure-ff-related-file-alist)) + (when eglot-x-enable-local-docs-support + (let* ((exp (plist-get capabilities :experimental)) + (old (if (eq exp eglot--{}) '() exp)) + (new (plist-put old :localDocs t))) + (setq capabilities (plist-put capabilities :experimental new)))) capabilities))) (defvar ff-other-file-alist) @@ -799,7 +813,12 @@ case.") :experimental/externalDocs (eglot--TextDocumentPositionParams)))) (when res - (browse-url res)))) + (let ((local (plist-get res :local)) + (web (or (plist-get res :web) + res))) + (if (and local (file-exists-p (eglot--uri-to-path local))) + (browse-url local) + (browse-url web)))))) ;;; Analyzer Status @@ -1594,7 +1613,7 @@ This is in contrast to merely setting it to 0." (defun eglot-x--put-in-server (server prop val) "Put PROP-VAL into SERVER object just like `plist-put'." ;; We can't inherit from eglot-lsp-server and add an additional - ;; slot, becasue this should work on any object inheriting from + ;; slot, because this should work on any object inheriting from ;; eglot-lsp-server. So let's hide PROP-VAL in the eglot-lsp-server ;; object. (let ((eglot-x--remove-hidden-info nil)) |