Skip to content

Commit 9447738

Browse files
authored
lsp-rust: Add support for opening external docs (#3072)
* lsp-rust: Add support for opening external docs Add support for using the rust-analyzer 'experimental/externalDocs' request to get a URL for external documentation. * [docs] Add documentation for lsp-rust-analyzer-open-external-docs
1 parent 2e19005 commit 9447738

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

clients/lsp-rust.el

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,18 @@ open in a new window."
10941094
(lsp--warn "Couldn't find a Cargo.toml file or your version of rust-analyzer doesn't support this extension"))
10951095
(lsp--error "OpenCargoToml is an extension available only with rust-analyzer")))
10961096

1097+
(defun lsp-rust-analyzer-open-external-docs ()
1098+
"Open a URL for documentation related to the current TextDocumentPosition.
1099+
1100+
Rust-Analyzer LSP protocol documented here
1101+
https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/lsp-extensions.md#open-external-documentation"
1102+
(interactive)
1103+
(-if-let* ((params (lsp-make-rust-analyzer-open-external-docs-params
1104+
:text-document (lsp--text-document-identifier)
1105+
:position (lsp--cur-position)))
1106+
(url (lsp-request "experimental/externalDocs" params)))
1107+
(browse-url url)
1108+
(lsp--warn "Couldn't find documentation URL or your version of rust-analyzer doesn't support this extension")))
10971109

10981110
(defun lsp-rust-analyzer--related-tests ()
10991111
"Get runnable test items related to the current TextDocumentPosition.

docs/manual-language-docs/lsp-rust-analyzer.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,21 @@ Get a list of possible auto import candidates with `lsp-execute-code-action`
6262

6363
`lsp-rust-analyzer-open-cargo-toml` opens the Cargo.toml closest to the current file. Calling it with a universal argument will open the Cargo.toml in another window.
6464

65-
Corresponds to [the rust-analyzer LSP extension](https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/lsp-extensions.md#open-cargotoml)
65+
Corresponds to [the rust-analyzer LSP extension](https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/lsp-extensions.md#open-cargotoml)
6666

6767
![](../examples/lsp-rust-analyzer-open-cargo-toml.gif)
6868

69+
### Open external documentation
70+
71+
`lsp-rust-analyzer-open-external-docs` opens external documentation related to the current position in a browser.
72+
73+
Corresponds to [the rust-analyzer LSP extension](https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/lsp-extensions.md#open-external-documentation)
74+
6975
### Find and execute tests related to current position
7076

7177
`lsp-rust-analyzer-related-tests` find all tests related to the current position, asks for user completion and executes the selected test in a compilation buffer.
7278

73-
Corresponds to [the rust-analyzer LSP extension](https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/lsp-extensions.md#related-tests)
79+
Corresponds to [the rust-analyzer LSP extension](https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/lsp-extensions.md#related-tests)
7480

7581
In the example below, first you see that:
7682
+ On the left, the function `check_infer` is defined, on the right another

lsp-protocol.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ See `-let' for a description of the destructuring mechanism."
403403
(rust-analyzer:ExpandedMacro (:name :expansion) nil)
404404
(rust-analyzer:MatchingBraceParams (:textDocument :positions) nil)
405405
(rust-analyzer:OpenCargoTomlParams (:textDocument) nil)
406+
(rust-analyzer:OpenExternalDocsParams (:textDocument :position) nil)
406407
(rust-analyzer:ResovedCodeActionParams (:id :codeActionParams) nil)
407408
(rust-analyzer:JoinLinesParams (:textDocument :ranges) nil)
408409
(rust-analyzer:MoveItemParams (:textDocument :range :direction) nil)

0 commit comments

Comments
 (0)