-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
docs: create setup documentation #18304
Merged
Veykril
merged 3 commits into
rust-lang:master
from
davidkurilla:docs-create-setup-document
Oct 30, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Setup Guide | ||
|
||
This guide gives a simplified opinionated setup for developers contributing to rust-analyzer using Visual Studio Code to make changes and Visual Studio Code Insiders to test those changes. This guide will assume you have Visual Studio Code and Visual Studio Code Insiders installed. | ||
|
||
## Prerequisites | ||
|
||
Since rust-analyzer is a Rust project, you will need to install Rust. You can download and install the latest stable version of Rust [here](https://www.rust-lang.org/tools/install). | ||
|
||
## Step-by-Step Setup | ||
|
||
**Step 01**: Fork the rust-analyzer repository and clone the fork to your local machine. | ||
|
||
**Step 02**: Open the project in Visual Studio Code. | ||
|
||
**Step 03**: Open a terminal and run `cargo build` to build the project. | ||
|
||
**Step 04**: Install the language server locally by running the following command: | ||
|
||
```sh | ||
cargo xtask install --server --code-bin code-insiders --dev-rel | ||
``` | ||
|
||
In the output of this command, there should be a file path provided to the installed binary on your local machine. | ||
It should look something like the following output below: | ||
|
||
``` | ||
Installing <path-to-rust-analyzer-binary> | ||
Installed package `rust-analyzer v0.0.0 (<path-to-rust-analyzer-binary>)` (executable `rust-analyzer.exe`) | ||
``` | ||
|
||
In Visual Studio Code Insiders, you will want to open your User Settings (JSON) from the Command Palette. From there you should ensure that the `rust-analyzer.server.path` key is set to the `<path-to-rust-analyzer-binary>`. This will tell Visual Studio Code Insiders to use the locally installed version that you can debug. | ||
|
||
The User Settings (JSON) file should contain the following: | ||
|
||
```json | ||
{ | ||
"rust-analyzer.server.path": "<path-to-rust-analyzer-binary>" | ||
} | ||
``` | ||
|
||
Now you should be able to make changes to rust-analyzer in Visual Studio Code and then view the changes in Visual Studio Code Insiders. | ||
|
||
## Debugging rust-analyzer | ||
The simplest way to debug rust-analyzer is to use the `eprintln!` macro. The reason why we use `eprintln!` instead of `println!` is because the language server uses `stdout` to send messages. So instead we will debug using `stderr`. | ||
|
||
An example debugging statement could go into the `main_loop.rs` file which can be found at `crates/rust-analyzer/src/main_loop.rs`. Inside the `main_loop` we will add the following `eprintln!` to test debugging rust-analyzer: | ||
|
||
```rs | ||
eprintln!("Hello, world!"); | ||
``` | ||
|
||
Now we run `cargo build` and `sh | ||
cargo xtask install --server --code-bin code-insiders --dev-rel` to reinstall the server. | ||
|
||
Now on Visual Studio Code Insiders, we should be able to open the Output tab on our terminal and switch to Rust Analyzer Language Server to see the `eprintln!` statement we just wrote. | ||
|
||
If you are able to see your output, you now have a complete workflow for debugging rust-analyzer. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to build the extension unless you use it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This workflow requires building a local installation of the extension. This would allow the user to view
eprintln!
debug statements in the Rust Analyzer Language Server output.