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

feat: vscode: Support opening local documentation if available #15728

Merged

Conversation

EliasHolzmann
Copy link
Contributor

This PR implements the VS code support for opening local documentation (server side support was already implemented in #14662).

local_docs.webm

Displaying local instead of web docs can have many benefits:

  • the web version may have different features enabled than locally selected
  • the standard library may be a different version than is available online
  • the user may not be online and therefore cannot access the web documentation
  • the documentation may not be available online at all, for example because it is for a new feature in a library the user is currently developing

If the documentation is not available locally, the extension still falls back to the web version.

Closes #12867.


If my implementation isn't really idiomatic TypeScript: Sorry, I'm not much of a TypeScript developer. I am open to feedback, however.

According to the VS Code documentation, the vscode.open command opens the URL
_in the editor_ (https://code.visualstudio.com/api/references/commands).
However, in reality, it seems to do so only for file:// URLs, falling back to
other applications for other URL schemes (at least for HTTP/HTTPS).

Until now, the URL to the documentation was always HTTP based, so using the
vscode.open command was perfectly fine. However, displaying local documentation
will be supported from now on (see next commit). Local documentation is not
HTTP-based, but instead addressed via a file:// URL. The file URL would
therefore be opened in VS Code instead of in the browser — this is definitely
not what the user wants.

Therefore, the vscode.env.openExternal function is used instead, this function
never opens the URL in VS Code.
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 8, 2023
@Veykril Veykril added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 9, 2023
@EliasHolzmann EliasHolzmann force-pushed the feature/local_documentation_vscode branch from 4a1c657 to 3ff80e0 Compare October 9, 2023 18:06
Displaying local instead of web docs can have many benefits:
- the web version may have different features enabled than locally selected
- the standard library may be a different version than is available online
- the user may not be online and therefore cannot access the web documentation
- the documentation may not be available online at all, for example because it
  is for a new feature in a library the user is currently developing

If the documentation is not available locally, the extension still falls back to
the web version.
@EliasHolzmann EliasHolzmann force-pushed the feature/local_documentation_vscode branch from 3ff80e0 to e8372e0 Compare October 9, 2023 18:12
@Veykril
Copy link
Member

Veykril commented Oct 10, 2023

Thanks!
@bors r+

@bors
Copy link
Collaborator

bors commented Oct 10, 2023

📌 Commit e8372e0 has been approved by Veykril

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Oct 10, 2023

⌛ Testing commit e8372e0 with merge 8a23314...

@bors
Copy link
Collaborator

bors commented Oct 10, 2023

☀️ Test successful - checks-actions
Approved by: Veykril
Pushing 8a23314 to master...

@bors bors merged commit 8a23314 into rust-lang:master Oct 10, 2023
10 checks passed
@Ciel-MC
Copy link

Ciel-MC commented Oct 19, 2023

Sorry if it shouldn't be asked here, a quick google didn't yield me much, but how do you get local docs? Is it for all crates or just stdlib? I could see doing away with doc viewers like Dash completely if this is broadly available.

@EliasHolzmann
Copy link
Contributor Author

@Ciel-MC:

  • For std (as well as core and all other libraries that are bundled with Rust), you need to install the documentation with rustup component add rust-docs-<your target triple> – so, for Linux, rustup component add rust-docs-x86_64-unknown-linux-gnu, for other systems, you may want to have a look at rustup component list (see the Rustup book for relevant documentation)
  • For "normal" dependencies of your crate (and the crate itself), just run cargo doc to generate the documentation. You can rerun the command later as needed to update the existing documentation. (see the Cargo book for relevant documentation – there are some interesting flags for cargo doc, for example --document-private-items that may be relevant to your use case)

@EliasHolzmann EliasHolzmann mentioned this pull request Nov 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Open docs for symbol should support locally built documentation
5 participants