aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rw-r--r--docs/dev/lsp-extensions.md12
-rw-r--r--docs/dev/style.md35
-rw-r--r--docs/user/generated_config.adoc2
-rw-r--r--docs/user/manual.adoc111
4 files changed, 143 insertions, 17 deletions
diff --git a/docs/dev/lsp-extensions.md b/docs/dev/lsp-extensions.md
index f0f981802..8fcd72d5d 100644
--- a/docs/dev/lsp-extensions.md
+++ b/docs/dev/lsp-extensions.md
@@ -1,5 +1,5 @@
1<!--- 1<!---
2lsp_ext.rs hash: 28a9d5a24b7ca396 2lsp_ext.rs hash: 6e57fc1b345b00e9
3 3
4If you need to change the above hash to make the test pass, please check if you 4If you need to change the above hash to make the test pass, please check if you
5need to adjust this doc as well and ping this issue: 5need to adjust this doc as well and ping this issue:
@@ -486,6 +486,16 @@ Primarily for debugging, but very useful for all people working on rust-analyzer
486Returns a textual representation of the HIR of the function containing the cursor. 486Returns a textual representation of the HIR of the function containing the cursor.
487For debugging or when working on rust-analyzer itself. 487For debugging or when working on rust-analyzer itself.
488 488
489## View Crate Graph
490
491**Method:** `rust-analyzer/viewCrateGraph`
492
493**Request:** `null`
494
495**Response:** `string`
496
497Renders rust-analyzer's crate graph as an SVG image.
498
489## Expand Macro 499## Expand Macro
490 500
491**Method:** `rust-analyzer/expandMacro` 501**Method:** `rust-analyzer/expandMacro`
diff --git a/docs/dev/style.md b/docs/dev/style.md
index 6ab60b50e..d24a5952e 100644
--- a/docs/dev/style.md
+++ b/docs/dev/style.md
@@ -449,6 +449,39 @@ fn query_all(name: String, case_sensitive: bool) -> Vec<Item> { ... }
449fn query_first(name: String, case_sensitive: bool) -> Option<Item> { ... } 449fn query_first(name: String, case_sensitive: bool) -> Option<Item> { ... }
450``` 450```
451 451
452## Prefer Separate Functions Over Parameters
453
454If a function has a `bool` or an `Option` parameter, and it is always called with `true`, `false`, `Some` and `None` literals, split the function in two.
455
456```rust
457// GOOD
458fn caller_a() {
459 foo()
460}
461
462fn caller_b() {
463 foo_with_bar(Bar::new())
464}
465
466fn foo() { ... }
467fn foo_with_bar(bar: Bar) { ... }
468
469// BAD
470fn caller_a() {
471 foo(None)
472}
473
474fn caller_b() {
475 foo(Some(Bar::new()))
476}
477
478fn foo(bar: Option<Bar>) { ... }
479```
480
481**Rationale:** more often than not, such functions display "`false sharing`" -- they have additional `if` branching inside for two different cases.
482Splitting the two different control flows into two functions simplifies each path, and remove cross-dependencies between the two paths.
483If there's common code between `foo` and `foo_with_bar`, extract *that* into a common helper.
484
452## Avoid Monomorphization 485## Avoid Monomorphization
453 486
454Avoid making a lot of code type parametric, *especially* on the boundaries between crates. 487Avoid making a lot of code type parametric, *especially* on the boundaries between crates.
@@ -914,4 +947,4 @@ match p.current() {
914For `.md` and `.adoc` files, prefer a sentence-per-line format, don't wrap lines. 947For `.md` and `.adoc` files, prefer a sentence-per-line format, don't wrap lines.
915If the line is too long, you want to split the sentence in two :-) 948If the line is too long, you want to split the sentence in two :-)
916 949
917**Rationale:** much easier to edit the text and read the diff. 950**Rationale:** much easier to edit the text and read the diff, see [this link](https://asciidoctor.org/docs/asciidoc-recommended-practices/#one-sentence-per-line).
diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc
index e28423e99..f70558200 100644
--- a/docs/user/generated_config.adoc
+++ b/docs/user/generated_config.adoc
@@ -1,4 +1,4 @@
1[[rust-analyzer.assist.importMergeBehavior]]rust-analyzer.assist.importMergeBehavior (default: `"full"`):: 1[[rust-analyzer.assist.importMergeBehavior]]rust-analyzer.assist.importMergeBehavior (default: `"crate"`)::
2+ 2+
3-- 3--
4The strategy to use when inserting new imports or merging imports. 4The strategy to use when inserting new imports or merging imports.
diff --git a/docs/user/manual.adoc b/docs/user/manual.adoc
index 54195adb7..797af3f75 100644
--- a/docs/user/manual.adoc
+++ b/docs/user/manual.adoc
@@ -6,8 +6,6 @@
6:source-highlighter: rouge 6:source-highlighter: rouge
7:experimental: 7:experimental:
8 8
9// Master copy of this document lives in the https://github.com/rust-analyzer/rust-analyzer repository
10
11At its core, rust-analyzer is a *library* for semantic analysis of Rust code as it changes over time. 9At its core, rust-analyzer is a *library* for semantic analysis of Rust code as it changes over time.
12This manual focuses on a specific usage of the library -- running it as part of a server that implements the 10This manual focuses on a specific usage of the library -- running it as part of a server that implements the
13https://microsoft.github.io/language-server-protocol/[Language Server Protocol] (LSP). 11https://microsoft.github.io/language-server-protocol/[Language Server Protocol] (LSP).
@@ -20,7 +18,6 @@ To improve this document, send a pull request: +
20https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/manual.adoc[https://github.com/rust-analyzer/.../manual.adoc] 18https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/manual.adoc[https://github.com/rust-analyzer/.../manual.adoc]
21 19
22The manual is written in https://asciidoc.org[AsciiDoc] and includes some extra files which are generated from the source code. Run `cargo test` and `cargo test -p xtask` to create these and then `asciidoctor manual.adoc` to create an HTML copy. 20The manual is written in https://asciidoc.org[AsciiDoc] and includes some extra files which are generated from the source code. Run `cargo test` and `cargo test -p xtask` to create these and then `asciidoctor manual.adoc` to create an HTML copy.
23
24==== 21====
25 22
26If you have questions about using rust-analyzer, please ask them in the https://users.rust-lang.org/c/ide/14["`IDEs and Editors`"] topic of Rust users forum. 23If you have questions about using rust-analyzer, please ask them in the https://users.rust-lang.org/c/ide/14["`IDEs and Editors`"] topic of Rust users forum.
@@ -139,17 +136,6 @@ If you're not using Code, you can compile and install only the LSP server:
139$ cargo xtask install --server 136$ cargo xtask install --server
140---- 137----
141 138
142==== Troubleshooting
143
144Here are some useful self-diagnostic commands:
145
146* **Rust Analyzer: Show RA Version** shows the version of `rust-analyzer` binary.
147* **Rust Analyzer: Status** prints some statistics about the server, and dependency information for the current file.
148* To enable server-side logging, run with `env RA_LOG=info` and see `Output > Rust Analyzer Language Server` in VS Code's panel.
149* To log project loading (sysroot & `cargo metadata`), set `RA_LOG=project_model=debug`.
150* To log all LSP requests, add `"rust-analyzer.trace.server": "verbose"` to the settings and look for `Rust Analyzer Language Server Trace` in the panel.
151* To enable client-side logging, add `"rust-analyzer.trace.extension": true` to the settings and open `Output > Rust Analyzer Client` in the panel.
152
153=== rust-analyzer Language Server Binary 139=== rust-analyzer Language Server Binary
154 140
155Other editors generally require the `rust-analyzer` binary to be in `$PATH`. 141Other editors generally require the `rust-analyzer` binary to be in `$PATH`.
@@ -385,6 +371,68 @@ If available in PATH or in some standard location, `rust-analyzer` is detected a
385If `rust-analyzer` is not detected, Corrosion will prompt you for configuration of your Rust toolchain and language server with a link to the __Window > Preferences > Rust__ preference page; from here a button allows to download and configure `rust-analyzer`, but you can also reference another installation. 371If `rust-analyzer` is not detected, Corrosion will prompt you for configuration of your Rust toolchain and language server with a link to the __Window > Preferences > Rust__ preference page; from here a button allows to download and configure `rust-analyzer`, but you can also reference another installation.
386You'll need to close and reopen all .rs and Cargo files, or to restart the IDE, for this change to take effect. 372You'll need to close and reopen all .rs and Cargo files, or to restart the IDE, for this change to take effect.
387 373
374=== Kate Text Editor
375
376Support for the language server protocol is built into Kate through the LSP plugin, which is included by default.
377It is preconfigured to use Rls for rust sources, but allows you to use rust-analyzer through a simple settings change.
378In the LSP Client settings of Kate, copy the content of the third tab "default parameters" to the second tab "server configuration".
379Then in the configuration replace:
380[source,json]
381----
382 "rust": {
383 "command": ["rls"],
384 "rootIndicationFileNames": ["Cargo.lock", "Cargo.toml"],
385 "url": "https://github.com/rust-lang/rls",
386 "highlightingModeRegex": "^Rust$"
387 },
388----
389With
390[source,json]
391----
392 "rust": {
393 "command": ["rust-analyzer"],
394 "rootIndicationFileNames": ["Cargo.lock", "Cargo.toml"],
395 "url": "https://github.com/rust-analyzer/rust-analyzer",
396 "highlightingModeRegex": "^Rust$"
397 },
398----
399Then click on apply, and restart the LSP server for your rust project.
400
401== Troubleshooting
402
403Start with looking at the rust-analyzer version.
404Try **Rust Analyzer: Show RA Version** in VS Code and `rust-analyzer --version` in the command line.
405If the date is more than a week ago, it's better to update rust-analyzer version.
406
407The next thing to check would be panic messages in rust-analyzer's log.
408Log messages are printed to stderr, in VS Code you can see then in the `Output > Rust Analyzer Language Server` tab of the panel.
409To see more logs, set `RA_LOG=info` environmental variable.
410
411To fully capture LSP messages between the editor and the server, set `"rust-analyzer.trace.server": "verbose"` config and check
412`Output > Rust Analyzer Language Server Trace`.
413
414The root cause for many "`nothing works`" problems is that rust-analyzer fails to understand the project structure.
415To debug that, first note the `rust-analyzer` section in the status bar.
416If it has an error icon and red, that's the problem (hover will have somewhat helpful error message).
417**Rust Analyzer: Status** prints dependency information for the current file.
418Finally, `RA_LOG=project_model=debug` enables verbose logs during project loading.
419
420If rust-analyzer outright crashes, try running `rust-analyzer analysis-stats /path/to/project/directory/` on the command line.
421This command type checks the whole project in batch mode bypassing LSP machinery.
422
423When filing issues, it is useful (but not necessary) to try to minimize examples.
424An ideal bug reproduction looks like this:
425
426```bash
427$ git clone https://github.com/username/repo.git && cd repo && git switch --detach commit-hash
428$ rust-analyzer --version
429rust-analyzer dd12184e4 2021-05-08 dev
430$ rust-analyzer analysis-stats .
431💀 💀 💀
432```
433
434It is especially useful when the `repo` doesn't use external crates or the standard library.
435
388== Configuration 436== Configuration
389 437
390**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/rust-analyzer/src/config.rs[config.rs] 438**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/rust-analyzer/src/config.rs[config.rs]
@@ -611,6 +659,41 @@ For example, mutable bindings are underlined by default and you can override thi
611} 659}
612---- 660----
613 661
662Most themes doesn't support styling unsafe operations differently yet. You can fix this by adding overrides for the rules `operator.unsafe`, `function.unsafe`, and `method.unsafe`:
663
664[source,jsonc]
665----
666{
667 "editor.semanticTokenColorCustomizations": {
668 "rules": {
669 "operator.unsafe": "#ff6600",
670 "function.unsafe": "#ff6600"
671 "method.unsafe": "#ff6600"
672 }
673 },
674}
675----
676
677In addition to the top-level rules you can specify overrides for specific themes. For example, if you wanted to use a darker text color on a specific light theme, you might write:
678
679[source,jsonc]
680----
681{
682 "editor.semanticTokenColorCustomizations": {
683 "rules": {
684 "operator.unsafe": "#ff6600"
685 },
686 "[Ayu Light]": {
687 "rules": {
688 "operator.unsafe": "#572300"
689 }
690 }
691 },
692}
693----
694
695Make sure you include the brackets around the theme name. For example, use `"[Ayu Light]"` to customize the theme Ayu Light.
696
614==== Special `when` clause context for keybindings. 697==== Special `when` clause context for keybindings.
615You may use `inRustProject` context to configure keybindings for rust projects only. 698You may use `inRustProject` context to configure keybindings for rust projects only.
616For example: 699For example: